【问题标题】:Magento Clear Cart ObserverMagento 清除购物车观察者
【发布时间】:2015-03-08 13:10:45
【问题描述】:

Namespace_Modulename_Model_Observer我需要在添加产品之前创建一个事件/观察者来清除购物车。结帐过程将仅包括一种产品。谁能帮帮我?

到目前为止,我有以下代码,但我做错了什么:

在 config.xml 我有:

<frontend>
    <events>
        <checkout_cart_product_add_after>
          <observers>
            <clear_cart_observer>
              <type>singleton</type>
              <class>Namespace_Modulename_Model_Observer</class>
              <method>clearCart</method>
            </clear_cart_observer>
          </observers>
        </checkout_cart_product_add_after>
    </events>
</frontend>

另外,我创建了一个观察者文件,其中包含:

public function clearCart($observer) 
{   
    foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ) {
        Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
    }
}

我的 system.log 中没有任何错误,但它不会触发。有什么想法吗?

【问题讨论】:

    标签: magento events cart checkout


    【解决方案1】:

    您可能需要解决此问题:

    <class>Namespace_Modulename_Model_Observer</class>
    

    并确保您已加载模块:

    app/etc/modules/Namespace_Modulename.xml
    

    别忘了刷新缓存。

    【讨论】:

    • 在我的代码中没问题。只是我没有把它贴在这里。不能解决我的问题。
    • 掷骰子('这里');在你的观察者的顶部。它会渲染吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 2011-04-09
    • 1970-01-01
    相关资源
    最近更新 更多