购物车中已移除商品的观察者 [英] Observer for removed items in the cart
问题描述
当产品从购物车中移除时,是否有可用于观察事件的观察器?我没有找到.
Is there an observer which can be used to observe events when a product is removed from the cart? I haven't found any.
我发现的是 checkout_cart_update_items_after
可以在通过更改产品数量删除产品时使用它,但在用户使用删除按钮时则不能使用.我目前看到的唯一替代方法是 checkout_cart_save_after
,它在购物车发生变化时使用.当然,这需要自定义逻辑来检查删除了哪个产品.不完美.
What I have found is checkout_cart_update_items_after
which can be used if a product is removed by altering the product count, but not when the user uses the remove button. The only alternative I see in the moment is checkout_cart_save_after
which is used whenever the cart changes. Of course this needs custom logic which check which product was removed. Not perfect.
那么有没有更好的方法来注意移除事件?
So is there a better way to watch out for remove events?
推荐答案
您可以使用 sales_quote_remove_item
事件,在 Mage_Sales_Model_Quote::removeItem()
中调度.
删除的项目作为参数传递给观察者.
You can use the sales_quote_remove_item
event, dispatched in Mage_Sales_Model_Quote::removeItem()
.
The removed item is passed to the observer as an argument.
Mage::dispatchEvent('sales_quote_remove_item', array('quote_item' => $item));
要在事件观察器中获取关联的产品模型,请使用 $observer->getQuoteItem()->getProduct()
.
To get the associated product model in an event observer, use $observer->getQuoteItem()->getProduct()
.
这篇关于购物车中已移除商品的观察者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!