Magento Asked by sulman on December 2, 2020
I am updating products stock like this:
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if ($_product) {
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
if (!$stockItem->getId()) {
echo "No stock item for $sku".PHP_EOL;
} else { // if there is, update it
$stockItem->setQty($qty);
$stockItem->setManageStock(true);
}
echo "$sku UPDATED to $qty".PHP_EOL;
$stockItem->save();
} else {
echo "$sku does not exist".PHP_EOL;
}
This works fine, but I need the alert emails to be sent (back in stock notifications), but with this code they do not run. I have also tried adding the below:
$_product->setData("_hasDataChanges", true);
$_product->save();
To try to force the catalog_product_save_after event to fire. But it doesn’t
Any ideas?
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP