I want to change via web service a remote inventory, I know that via Event Observer Method can triger my code, but I don't know which event is useful to complete my task, like on_order_complete, is there an updated list of events or more documentation?
4条回答 默认 最新
- duanjuan3931 2011-03-03 15:49关注
If you want to dispatch an event when the state of an order changes to any status or state, then you'll need to insert your own event listener. This isn't as difficult as it sounds.
Simply override the
_setStatus
function inMage_Sales_Model_Order
like so.../** * Order model * * @category WMG * @package WMG_Sales * @author Lee Bolding <lee.bolding@wmg.com> * * Supported events: * sales_order_status_before * sales_order_status_after * * NOTE: Unfortunately, we can't override setState() as the protected _setState() * function is used by the registerCancellation() and _checkState() functions * */ class WMG_Sales_Model_Order extends Mage_Sales_Model_Order { /** * Order state protected setter. * By default allows to set any state. Can also update status to default or specified value * Сomplete and closed states are encapsulated intentionally, see the _checkState() * * @param string $state * @param string|bool $status * @param string $comment * @param bool $isCustomerNotified * @param $shouldProtectState * @return Mage_Sales_Model_Order */ protected function _setState($state, $status = false, $comment = '', $isCustomerNotified = null, $shouldProtectState = false) { // dispatch an event before we attempt to do anything Mage::dispatchEvent('sales_order_status_before', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified, 'shouldProtectState' => $shouldProtectState)); // attempt to set the specified state if ($shouldProtectState) { if ($this->isStateProtected($state)) { Mage::throwException(Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state)); } } $this->setData('state', $state); // add status history if ($status) { if ($status === true) { $status = $this->getConfig()->getStateDefaultStatus($state); } $this->setStatus($status); $history = $this->addStatusHistoryComment($comment, false); // no sense to set $status again $history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility } // dispatch an event after status has changed Mage::dispatchEvent('sales_order_status_after', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified, 'shouldProtectState' => $shouldProtectState)); return $this; } }
You can now subscribe observers to the newly created
sales_order_status_before
andsales_order_status_after
events本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 minnio内存占用过大,内存没被回收(Windows环境)
- ¥65 抖音咸鱼付款链接转码支付宝
- ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
- ¥15 求螺旋焊缝的图像处理
- ¥15 blast算法(相关搜索:数据库)
- ¥15 请问有人会紧聚焦相关的matlab知识嘛?
- ¥15 网络通信安全解决方案
- ¥50 yalmip+Gurobi
- ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
- ¥15 itunes恢复数据最后一步发生错误