I'm trying to send a notification when the product becomes out of stock. This is the code I have on my Observer:
public function detectProductChanges($observer)
{
$product = $observer->getEvent()->getProduct();
if ($product->hasDataChanges()) {
try {
$oldStock = $product->getStockItem()->getOrigData('qty');
$newStock = $product->getStockItem()->getData('qty');
if ($newStock != '0' || $oldStock == $newStock) {
return $this;
}
// send email...
} catch (Exception $e) {
Mage::log($e->getTraceAsString(), null, 'my_cute.log');
}
}
return $this;
}
On the config.xml file I got the following:
<!-- ... -->
<global>
<events>
<catalog_product_save_after>
<observers>
<reports_detect_product_changes>
<type>singleton</type>
<class>reports/observer</class>
<method>detectProductChanges</method>
</reports_detect_product_changes>
</observers>
</catalog_product_save_after>
</events>
</global>
<!-- ... -->
The thing is, if I edit a product on the admin side, everything's fine, but if I proceed to checkout a product, this event is not called, can you help please?