我开发了一个自定义 Magento 模块,带有一个观察者:
<?xml version="1.0"?>
<config>
<modules>
<ADF_Evoucher>
<version>1.0.0</version>
</ADF_Evoucher>
</modules>
<frontend>
[...]
<events>
[...]
<sales_order_save_before>
<observers>
<ADF_Evoucher_Model_Observer>
<class>evoucher/observer</class>
<method>salesOrderSaveBeforeObserve</method>
</ADF_Evoucher_Model_Observer>
</observers>
</sales_order_save_before>
</events>
</frontend>
[...]
</config>
我的观察者:
<?php
class ADF_Evoucher_Model_Observer extends Varien_Event_Observer
{
public function __construct()
{
}
public function salesOrderSaveBeforeObserve($observer)
{
$order = $observer->getEvent()->getOrder();
$quote = $order->getQuote();
$cart = Mage::getModel('checkout/cart');
Zend_Debug::dump($quote);
Zend_Debug::dump($cart);
die();
}
}
?>
问题是我的购物车是空的,而我确实在其中添加了一些物品:
object(Mage_Checkout_Model_Cart)[458]
protected '_summaryQty' => null
protected '_productIds' => null
protected '_data' =>
array (size=0)
empty
protected '_hasDataChanges' => boolean false
protected '_origData' => null
protected '_idFieldName' => null
protected '_isDeleted' => boolean false
protected '_oldFieldsMap' =>
array (size=0)
empty
protected '_syncFieldsMap' =>
array (size=0)
empty
我不明白为什么。也许我在某个地方做错了什么,我对 Magento 有点陌生。知道为什么这个购物车对象在我的观察者中是空的吗?