1

你能明白为什么我的观察者中的 Mage::log 没有触发吗?非常沮丧。我希望他们在我将商品添加到购物车后记录,但事实并非如此。你能看到问题吗?我启用了日志记录。该模块显示在 config>advanced 下的列表中。我已禁用缓存,但正在清除以进行良好的测量。

配置.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>    
    <modules>
        <Caitlinhavener_Dynamicprice>
            <version>0.1.0</version>
        </Caitlinhavener_Dynamicprice>
    </modules>
    <global>
        <models>
            <chdispatcher>
                <class>Caitlinhavener_Dynamicprice_Model</class>
            </chdispatcher>
        </models>

        <frontend>
            <events>
                <checkout_cart_product_add_after>
                    <observers>
                        <modify_to_custom_price>
                            <class>Caitlinhavener_Dynamicprice_Model_Observer</class>
                            <method>modifyPrice</method>
                        </modify_to_custom_price>
                    </observers>
                </checkout_cart_product_add_after>
            </events>
        </frontend>
    </global>
</config>

观察者.php:

<?php
Mage::log('Im here')
or exit("unable to log");
class Caitlinhavener_Dynamicprice_Model_Observer
{
    public function modifyPrice(Varien_Event_Observer $obs)
    {
        // Get the quote item
        $item = $obs->getQuoteItem();
        Mage::log('Get Quote Item '. var_dump($_item->debug());

        // Ensure we have the parent item, if it has one
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        Mage::log('Get parent item ' . var_dump($_item->debug());

        // Load the custom price
        //$price = "your custom price logic";
        $price = Mage::registry('dynamic_tier_price');
        Mage::log('Price is ' . $price);

        // Set the custom price
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        // Enable super mode on the product.
        $item->getProduct()->setIsSuperMode(true);
        Mage::log('Item after super mode ' . var_dump($_item->debug());
    }



}
?>
4

1 回答 1

1

您的 config.xml 不正确(删除<frontend>标签)

<config>
   ..
   <global>
      <models>
         <chdispatcher>
             <class>Caitlinhavener_Dynamicprice_Model</class>
         </chdispatcher>
     </models>
     <events>
       ...
    </events>

在 magento 中,您有 3 个不同的事件范围(请参阅Magento:Event Observer Scope

在你的 config.xml

<config>
    <frontend>
        <events>
            ...
        </events>
    <frontend>
    <adminhtml>
        <events>
            ...
        </events>
    <adminhtml>
    <global>
        <events>
            ...
        </events>
    <global>
</config>
于 2013-06-05T16:50:14.673 回答