Если вы хотите отправить событие, когда состояние заказа меняется на какое-либо состояние или состояние, вам нужно будет вставить свой собственный прослушиватель событий.Это не так сложно, как кажется.
Просто переопределите функцию _setStatus
в Mage_Sales_Model_Order
вот так ...
/**
* 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;
}
}
Теперь вы можете подписать наблюдателей на недавно созданные sales_order_status_before
и sales_order_status_after
события