繁体   English   中英

Magento购物车事件项目记录

[英]Magento Cart Event Items Logging

我在本地文件夹中的自定义模块中有以下magento代码。

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');
    }


}

上面的代码是触发事件时要调用的方法,下面是config.xml代码

<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>

当我更新购物车中的某些内容时,ProofLog.log文件中将记录以下内容

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 -- 

如您所见,if语句为true,确实在$ items中存在数据,但是我似乎无法记录这些项目,这是正确的语法吗?

我也不能调试项目,该代码可以在生产环境中使用,因此为什么要在调试中使用Mage :: log():

我也是.net Web开发人员,而php magento对我来说是新手,最近几周我一直在努力学习,因此,如果问题是一个简单的语法错误,请原谅我。

多谢你们。

替换以下行

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

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

您将获得阵列中的所有详细信息,然后执行任何操作

让我知道您是否有任何疑问

替换以下行

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

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

这应该将$ items打印为字符串而不是日志文件中的数组。 它应该为您工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM