Reputation: 37
I have to set the qty of all products in my magento store, but the code that i have here is not working, does anyone know what is wrong with my code?
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$variable = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($variable as $product) {
$product->setManageStock(1)
->setUseConfigManageStock(1)
->setQty(1)
->setIsInStock(1)
->save();
}
Upvotes: 1
Views: 714
Reputation: 2843
May be this might help :
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$variable = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($variable as $product) {
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getEntityId());
$stockItem->setManageStock(1)
->setUseConfigManageStock(1)
->setQty(1)
->setIsInStock(1)
->save();
}
Upvotes: 1