Magento order status change events

前端 未结 4 1952
孤独总比滥情好
孤独总比滥情好 2020-12-10 08:29

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, l

相关标签:
4条回答
  • 2020-12-10 09:13

    I did a blog post about this (which contains the full event list for Magento CE 1.4) a few weeks ago.

    The events that may interest you for an order placement is sales_order_place_after, which gets called after the order is placed (seriously!).

    Hope that helps!

    Thanks, Joe

    0 讨论(0)
  • 2020-12-10 09:17

    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 in Mage_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 and sales_order_status_after events

    0 讨论(0)
  • 2020-12-10 09:20

    i guess a bit better solution is to watch out for changes, without using a rewrite:

    http://www.cartware.de/blog/detail/article/kein-magento-event-fuer-statusaenderung/

    By reading the code you may get the clue even its writte in german language...

    0 讨论(0)
  • 2020-12-10 09:21

    Use grep to find the list of events, it must be something like

    grep -rn -A2 --include="*.php" dispatchEvent /var/www/magento/
    

    or something like that...

    0 讨论(0)
提交回复
热议问题