观察者查看购物车中已移除的物品 [英] Observer for removed items in the cart

查看:91
本文介绍了观察者查看购物车中已移除的物品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从购物车中取出产品时,是否有观察员可用来观察事件?我还没找到.

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_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?

推荐答案

您可以使用在Mage_Sales_Model_Quote::removeItem()中调度的sales_quote_remove_item事件.
删除的项目作为参数传递给观察者.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆