我有以下观察员方法:
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事件是空的,我也尝试了getCart引用,这也是空的。我需要从事件中获取购物车的内容,以查看它创建了哪些内容。有什么想法吗?
发布于 2015-09-28 10:11:15
根据as,sales_order_place_before事件它只提供Order对象,并允许直接提供引用对象。
您想要从这个事件中获得quote object,那么您需要从Order object获得quote id,然后使用quote id you can get quote object。
public function ModifyOrderECC(Varien_Event_Observer $observer)
{
//sales_order_place_before
$QuoteID=$observer->getEvent()->getOrder()->getQuoteId();
$quoteObject=Mage::getModel('sales/quote')->load($QuoteID);
...
}发布于 2015-09-28 10:00:49
通过查看order类(第1113行),该事件为您提供了一个完整的cart实例,而不是cart实例。
如果要检索cart,请执行以下操作:
$cart = Mage::getSingleton('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
// do something
}https://stackoverflow.com/questions/32819944
复制相似问题