在前台下订单发生之后,做订单相关的操作,比如记录订单相关的字段信息,这个时候,需要使用到jmagento的事件机制。
如何做 比如订单完成之后的事件代码:
使用事件的方法如下:
- 创建下面文件
D:\www\lollicupStore2\app\code\local\Lollicupstore\Order\etc\config.xml D:\www\lollicupStore2\app\etc\modules\Lollicupstore_Order.xml
D:\www\lollicupStore2\app\code\local\Lollicupstore\Order\Model\Observer.php
在上面三个文件里面输入下面的代码
\app\code\local\Lollicupstore\Order\etc\config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<modules>
<Lollicupstore_Order>
<version>0.1.0</version>
</Lollicupstore_Order>
</modules>
<models>
<Lollicupstore_Order>Lollicupstore_Order_Model_Observer</Lollicupstore_Order>
</models>
<frontend>
<events>
<checkout_submit_all_after>
<observers>
<Lollicupstore_Order>
<type>singleton</type>
<class>Lollicupstore_Order_Model_Observer</class>
<method>saveCustomData</method>
</Lollicupstore_Order>
</observers>
</checkout_submit_all_after>
</events>
</frontend>
</config>
\app\etc\modules\Lollicupstore_Order.xml
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<modules>
<Lollicupstore_Order>
<active>true</active>
<codePool>local</codePool>
</Lollicupstore_Order>
</modules>
</config>
\app\code\local\Lollicupstore\Order\Model\Observer.php
<?php
/**
* Created by PhpStorm.
* User: lollicup
* Date: 2019/7/26
* Time: 15:04
*/
class Lollicupstore_Order_Model_Observer
{
//在这里做shipping address 插入到order
public function saveCustomData($observer)
{
set_time_limit(0);
$order = $observer->getEvent()->getOrder();
$incrementId = $order->getIncrementId();
echo "我的订单".$incrementId;
die();
}
}
然后:测试 一个事件即操作完成。