我有以下观察者方法:
public function ModifyOrderECC(Varien_Event_Observer $observer)
{
//sales_order_place_before
Mage::log('ECC!! = ModifyOrderECC has been called successfully - event/array-5', null, 'mylog.log');
$cart = $observer->getEvent()->getCart();
try{
if($cart != NULL)
{
Mage::log('$cart contains data!', null, 'mylog.log');
foreach ($cart->getItems() as $item) {
$getID = $item->getProduct()->getId();
$productName = $item->getProduct()->getName();
$productPrice = $item->getProduct()->getPrice();
$quantity = (string)$item->getProduct()->getQtyOrdered();
Mage::log('ID: '.$getID, null, 'mylog.log');
Mage::log('Name: '.$productName, null, 'mylog.log');
Mage::log('Price: '.$productPrice, null, 'mylog.log');
Mage::log('Qty: '.$quantity, null, 'mylog.log');
}
}else
{
Mage::log('sorry Cart is null :(', null, 'mylog.log');
}
}catch(Exception $e)
{
Mage::log($e->getMessage());
Mage::log('error = '.$e->getMessage(), null, 'mylog.log');
}
}
但是 getCart 事件为 null,我也尝试过 getquote,它也是 null。我需要从事件中获取购物车的内容,以查看其创建的内容。有什么想法吗?
最佳答案
根据sales_order_place_before事件,它仅提供订单对象并能够直接提供报价对象。
您想要从此事件中获取报价对象
,然后您需要从订单对象
获取报价ID
,然后使用报价ID您可以获取报价对象
。
public function ModifyOrderECC(Varien_Event_Observer $observer)
{
//sales_order_place_before
$QuoteID=$observer->getEvent()->getOrder()->getQuoteId();
$quoteObject=Mage::getModel('sales/quote')->load($QuoteID);
...
}
关于php - Magento sales_order_place_before $observer getevent null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32819944/