doulanli6146 2015-09-25 09:14
浏览 31
已采纳

Magento购物车事件项目记录

I have the following magento code in a custom module sitting in my local folder.

public function ProofOfConecept(Varien_Event_Observer $observer)
{
    //checkout_cart_save_before
    Mage::log('ProofOfConecept called - 2', null, 'proofLog.log');

    $cart = $observer->getEvent()->getCart();
    if($cart != NULL)
    {
        Mage::log('$cart contains data!', null, 'proofLog.log');
        $items = $cart->getItems();
        if($items != NULL)
        {
            Mage::log('$items has the following -- '.$items, null, 'proofLog.log');
        }else{
            Mage::log('$items is null??', null, 'proofLog.log');
        }
    }else
    {
        Mage::log('sorry Cart is null :(', null, 'proofLog.log');
    }


}

The code above is my method to call when an event is fired, Below is the config.xml code

<events>
        <checkout_cart_save_before>
            <observers>
                <dotnetit_eccbundle_model_observer>
                    <type>singleton</type>
                    <class>DotNetIT_ECCbundle_Model_Observer</class>
                    <method>ProofOfConecept</method>
                </dotnetit_eccbundle_model_observer>
            </observers>
        </checkout_cart_save_before>
    </events>

when i update something in my cart the following is logged in my ProofLog.log file

2015-09-25T09:05:40+00:00 DEBUG (7): ProofOfConecept called - 2
2015-09-25T09:05:40+00:00 DEBUG (7): $cart contains data!
2015-09-25T09:05:40+00:00 DEBUG (7): $items has the following -- 

As you can see, the if statement is true that there does appear to be data in $items, however i cant seem to log the items, is this the correct syntax?

I cannot debug the project either, this code lives on production hence why I'm using Mage::log() for my debugging :(

Also I'm a .net web dev, and php magento is all new to me, last couple weeks I've been trying to learn as much as i can, so forgive me if the issue is a simple syntax mistake.

Thanks guys.

  • 写回答

2条回答 默认 最新

  • dtkmejg127475 2015-09-25 10:16
    关注

    replace the following line

    Mage::log('$items has the following -- '.$items, null, 'proofLog.log');
    

    with

    Mage::log('$items has the following -- '.print_r($items), null, 'proofLog.log');
    

    you will get all details in array and do whatever after that

    Let me know if you have any query

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法