开发者

Detect inventory change

开发者 https://www.devze.com 2023-04-04 14:23 出处:网络
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 nec开发者_高级运维essarily by the user)? I looked for an event, but I don\'t

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 nec开发者_高级运维essarily by the user)? I looked for an event, but I don't see one. Is my only choice to override the Stock_Item model?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消