Magento – Change Simple Products to Manage Stock = No

MySQLstock

I want to change all my simple products to not manage stock and thus I need to change two fields

manage_stock... to be manage_stock = no
use_config_manage_stock... to be use_config_manage_stock = no (this way it won't use the default.)

my MySQL query would be something along the lines of…

UPDATE `my_database`.`cataloginventory_stock_item` SET `manage_stock` ='0' AND `use_config_manage_stock` ='0'
WHERE...

WHERE? this is where I struggle… I need to do where the type = simple, however I don't know where this data is held?


thinking about this its a little more complicated. Actually what I need to do is to do all simple products which are not associated to a configurable product…

Is this possible?

Henry

Best Answer

I know that this doesn't dirrectly answer your question, as it doesn't do this via an SQL statement, however, you could achieve this programatically.

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'simple'));

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

I don't think there is a way to grab only simple products that aren't associated with configurable products, unless you can filter by another attribute; for example, visibility (if associated products are not visible - only through their parent). The alternative would be to load all the configurable products, grab all the associated product IDs - getUsedProductIds() and then check if each simple product is in the array or not.

Related Topic