Magento 1 Data Upgrade Script: Set All Simple Products to Manage Stock

<?php
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('type_id', 'simple');

foreach ($collection as $product) {
    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
    $stockItem->setData('manage_stock', 1);
    $stockItem->setData('use_config_manage_stock', 1);
    $stockItem->save();
}

$installer->endSetup();

?>

Leave a Reply

Your email address will not be published. Required fields are marked *