Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento订单状态更改事件_Php_Magento - Fatal编程技术网

Php Magento订单状态更改事件

Php Magento订单状态更改事件,php,magento,Php,Magento,我想通过web服务更改远程资源清册,我知道通过事件观察者方法可以触发我的代码,但我不知道哪个事件对完成我的任务有用,比如在订单上,是否有更新的事件列表或更多文档?使用grep查找事件列表,它必须类似于 grep -rn -A2 --include="*.php" dispatchEvent /var/www/magento/ 或者类似的…几周前,我做了一个关于这一点的讨论(其中包含Magento CE 1.4的完整事件列表) 您可能对下单感兴趣的事件是sales\u order\u place

我想通过web服务更改远程资源清册,我知道通过事件观察者方法可以触发我的代码,但我不知道哪个事件对完成我的任务有用,比如在订单上,是否有更新的事件列表或更多文档?

使用grep查找事件列表,它必须类似于

grep -rn -A2 --include="*.php" dispatchEvent /var/www/magento/
或者类似的…

几周前,我做了一个关于这一点的讨论(其中包含Magento CE 1.4的完整事件列表)

您可能对下单感兴趣的事件是
sales\u order\u place\u after
,下单后会调用该事件(严重!)

希望有帮助

谢谢,
Joe

如果要在订单状态更改为任何状态或状态时发送事件,则需要插入自己的事件侦听器。这并不像听起来那么难

只需覆盖
Mage\u Sales\u Model\u Order
中的
\u setStatus
函数,如下所示

/**
 * 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;
    }
}
/**
*订单模型
*
*@类别WMG
*@package WMG_销售
*@作者李伯丁
*
*支持的事件:
*销售\订单\状态\之前
*销售\订单\状态\之后
*
*注意:很遗憾,我们无法将setState()重写为受保护的_setState()
*函数由registerCancellation()和_checkState()函数使用
*  
*/
WMG_销售模式订单类扩展了Mage_销售模式订单
{
/**
*命令状态保护的setter。
*默认情况下允许设置任何状态。也可以将状态更新为默认值或指定值
*С完全和关闭状态是有意封装的,参见_checkState()
*
*@param string$state
*@param string | bool$状态
*@param string$comment
*@param bool$isCustomerNotified
*@param$shouldProtectState
*@return Mage\u Sales\u Model\u订单
*/
受保护函数_setState($state,$status=false,$comment='',$isCustomerNotified=null,$shouldProtectState=false)
{
//在我们尝试做任何事情之前发送事件
Mage::dispatchEvent('sales_order_status_before',array('order'=>$this,'state'=>$state,'status'=>$status,'comment'=>$comment,'isCustomerNotified'=>$isCustomerNotified,'shouldProtectState'=>$shouldProtectState));
//尝试设置指定的状态
如果($shouldProtectState){
如果($this->isStateProtected($state)){
Mage::throwException(Mage::helper('sales')->(不能手动设置订单状态“%s”。,$State));
}
}
$this->setData('state',$state);
//添加状态历史记录
如果($状态){
如果($status==true){
$status=$this->getConfig()->getStateDefaultStatus($state);
}
$this->setStatus($status);
$history=$this->addStatusHistoryComment($comment,false);//再次设置$status没有意义
$history->setIsCustomerNotified($isCustomerNotified);//用于向后兼容
}
//在状态更改后调度事件
Mage::dispatchEvent('sales\u order\u status\u after',array('order'=>$this,'state'=>$state,'status'=>$status,'comment'=>$comment,'isCustomerNotified'=>$isCustomerNotified,'shouldProtectState'=>$shouldProtectState));
退还$this;
}
}

您现在可以订阅新创建的
sales\u order\u status\u before
sales\u order\u status\u after
事件

我想更好的解决方案是注意更改,而不使用重写:


通过阅读代码,你可能会得到线索,甚至它是用德语写的…

谢谢Joe,这篇文章写得很好,但我有一些问题:当管理员完成订单时,这个销售订单会在发出后发出吗?或者只是当用户完成cekout过程时?我需要更改管理员在向用户发送通知后完成订单的时间将订单添加到系统时触发sales\u order\u place\u after事件。如果您在订单移动到“已完成”状态时查找单个事件,则没有针对该事件的特定事件。您应该可以改为使用sales\u order\u save\u after并检查订单的状态。死链接:(…尝试此操作将显示默认的核心事件..他需要实现自己的事件,因为它不是由magento的核心提供的。