我的觀察陷在和無限循環。爲什麼會發生,我該如何解決?爲什麼我的Magento觀察員陷入無盡循環?
config.xml文件:
<?xml version="1.0"?>
<config>
<global>
<models>
<shipmentsave>
<class>Company_Shipmentsave_Model</class>
</shipmentsave>
</models>
</global>
<adminhtml>
<events>
<sales_order_shipment_track_save_after>
<observers>
<shipmentsave>
<type>model</type>
<class>shipmentsave/observer</class>
<method>salesOrderShipmentTrackSaveAfter</method>
</shipmentsave>
</observers>
</sales_order_shipment_track_save_after>
<sales_order_shipment_save_after>
<observers>
<shipmentsave>
<type>model</type>
<class>shipmentsave/observer</class>
<method>salesOrderShipmentSaveAfter</method>
</shipmentsave>
</observers>
</sales_order_shipment_save_after>
</events>
</adminhtml>
<frontend>
<events>
<sales_order_shipment_save_after>
<observers>
<shipmentsave>
<type>singleton</type>
<class>shipmentsave/observer</class>
<method>salesOrderShipmentSaveAfter</method>
</shipmentsave>
</observers>
</sales_order_shipment_save_after>
</events>
</frontend>
</config>
Observer.php:
class Company_Shipmentsave_Model_Observer
{
public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
{
error_log("My observer called ....",0);
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$track = Mage::getModel('sales/order_shipment_track')
->setNumber('1231354564')
->setCarrierCode('localdelivery')
->setTitle('Aramex');
$shipment->addTrack($track);
$shipment->save();
return;
}
}
喜喬, 感謝回答。 我想你的意思
sales_order_shipment_before
而不是sales_order_shipment_after
因爲我使用sales_order_shipment_after
是改變事件sales_order_shipment_before
工作對我來說已經面臨的問題。 但還是好奇,想知道如何使用sales_order_shipment_save_after
如果有的話我需要。 問候, SAURABH – Saurabh 2010-07-03 04:05:22它已經因爲你回答了這個很長一段時間,但可以提供一些見解如何設置,你在你的答案談單變量? – spdaly 2012-12-05 17:02:07