php - Magento sales_order_place_before $observer getevent null

标签 php magento

我有以下观察者方法:

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/

相关文章:

Magento 层导航从根类别开始

css - Magento 从特定 View 中删除 css 或 js

Magento - 无法解决 - jQuery/jCarousel 冲突问题

php - 下拉选择菜单有效,但无法预选

php - div 在 php 中 while 循环

Magento 仪表板总销售价格仍未更新为 0.-

php - Magento:使用 getModel 获取产品和类别

php - 如何从数组中求和等于X数的数组中找到最佳子集

php - 在 IDE 中显示 docker 容器输出

php - 如何将 Wordpress 注销重定向到自定义 URL