检测库存变化 [英] Detect inventory change
问题描述
我如何检测商品的库存水平何时达到0或Magento(不一定由用户)将其状态更改为缺货"?我寻找了一个活动,但没有看到.我是覆盖Stock_Item模型的唯一选择吗?
How can I detect when a product's inventory level reaches 0 or it's status is changed to "Out of Stock" by Magento (not necessarily by the user)? I looked for an event, but I don't see one. Is my only choice to override the Stock_Item model?
推荐答案
查找app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
,注意$ _eventPrefix设置为cataloginventory_stock_item
.这意味着您可以使用
Look in app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
and notice that the $_eventPrefix is set to cataloginventory_stock_item
. That means that you can use the generic Object Saving events detailed in this blog post to register an Observer, e.g. cataloginventory_stock_item_save_after
and inspect the values of the object.
使用泛型事件时,几乎几乎不需要覆盖模型.
You will almost never need to override the model when you use the generic events.
这篇关于检测库存变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!