user3737881
user3737881

Reputation: 37

Setting the stock qty of products in magento

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

Answers (1)

Manashvi Birla
Manashvi Birla

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

Related Questions