Magento 1.9:观察员不工作。有没有办法测试观察者是否正在工作?

时间:2018-05-28 10:05:47

标签: magento magento-1.9

我在config.xml文件中添加了以下代码

<?xml version="1.0"?>
<config>
<global>
      <events>
            <checkout_cart_add_product_complete>
                <observers>
                    <oroola_oroolachildren_observer>
                        <type>singleton</type>
                        <class>oroola_oroolachildren/observer</class>
                        <method>updateProductPrice</method>
                    </oroola_oroolachildren_observer>
                </observers>
            </checkout_cart_add_product_complete>
        </events>
    </global>
</config>

所以按照上面的配置文件,我在app / code / local / Oroola / Oroolachildren / Model /

中创建了一个Observer.php文件

Observer.php

<?php
Class Oroola_Oroolachildren_Model_Observer extends Varien_Event_Observer
{
    public function updateProductPrice(Varien_Event_Observer $obs)
    {
        header('Location: http://www.google.com/');
        die();
        $quote = $obs->getEvent()->getQuote();
        $item = $obs->getQuoteItem();
        $product_id=$item->getProductId();
        $_product=Mage::getModel('catalog/product')->load($product_id);
        $newprice=$_product->getPrice()+rand(10,100);

        Mage::log('My log entry', null, 'mylogfile.log');

        // Set the custom price
        $item->setCustomPrice($newprice);
        $item->setOriginalCustomPrice($newprice);
        // Enable super mode on the product.
        $item->getProduct()->setIsSuperMode(true);
        die();
    }
}

?>

我添加了php标头并将其重定向到google.com以测试其是否正常工作。

但这不起作用。

我想在添加到购物车之前/之后更改产品价格。

1 个答案:

答案 0 :(得分:1)

我已经更改了config.xml文件中的代码,并且在清除缓存后它可以工作。

<class>Oroola_Oroolachildren_Model_Observer</class>
<method>updateProductPrice</method>
相关问题