我想添加新商品时从购物车中删除商品。我正在观察:checkout_cart_add_product_complete
事件。我的代码如下:从magento中添加新商品时删除商品
<checkout_cart_add_product_complete>
<observers>
<secodaryproduct>
<type>singleton</type>
<class>secodaryproduct/observer</class>
<method>checkoutCartAddProductAddComplete</method>
</secodaryproduct>
</observers>
</checkout_cart_add_product_complete>
以及用于删除产品:
$quote = Mage::getSingleton('checkout/cart');
$quote->removeItem($product['item_id']);
$quote->save();
当我把这个代码,而观察者则能正常工作,并删除所需物品。但是,如果我使用这个使用观察员,然后项目不从购物车删除。我也将输出放在日志文件中,并且项目ID正确打印,但我的项目不会从购物车中删除。 请帮忙。
$ product ['item_id']'从哪里来?请注意,您必须使用引号项目的id通过'Mage_Sales_Model_Quote :: removeItem($ itemId)'将其删除,而不是某种产品ID。 –
是$ product ['item_id']是“sales_flat_quote_item”记录的标识。并且我已经在日志文件中打印了项目标识,并且显示正确。在checkout_cart_add_product_complete事件的情况下,只有删除查询不起作用,但在checkout_cart_update_items_after和sales_quote_remove_item事件的情况下,此功能正常工作。 –