当客户将magento中的订单放入另一个数据库平台时,我想保存所有数据(客户,产品,帐单地址等)。请帮忙。
由于
答案 0 :(得分:2)
为此,您需要创建一个模块。这是:
app/etc/modules/Tech_Order.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Tech_Order>
<active>true</active>
<codePool>community</codePool>
</Tech_Order>
</modules>
</config>
创建模块配置文件app/code/community/Tech/Order/etc/config.xml
。如下:
<?xml version="1.0"?>
<config>
<modules>
<Tech_Order>
<version>1.0.0</version>
</Tech_Order>
</modules>
<global>
<events>
<sales_order_place_after>
<observers>
<order_capture>
<type>singleton</type>
<class>Tech_Order_Model_Observer</class>
<method>captureOrder</method>
</order_capture>
</observers>
</sales_order_place_after>
</events>
</global>
</config>
创建捕获订单app/code/community/Tech/Order/Model/Observer.php
class Tech_Order_Model_Observer {
public function captureOrder(Varien_Event_Observer $observer) {
$_order = $observer->getEvent()->getOrder();
$orderObj = Mage::getModel("sales/order")->load($_order->getId());
$orderId = $_order->getRealOrderId();
$items = $orderObj->getAllItems();
$billingAddress = $_order->getBillingAddress();
$shipingAddress = $_order->getShippingAddress();
foreach($items as $item) {
$sku = $item->getData('sku');
$qty = (int) $item->getQtyOrdered();
$price = $item->getprice();
}
Mage::log('Order Data -- ' . $orderObj->getData());
Mage::log('Billing Address -- '. $billingAddress->getData());
Mage::log('Shipping Address -- '. $shipingAddress->getData());
}
}
captureOrder
是您可以捕获订单的所有信息并保存在数据库中的功能。