2
votes

I need to turn on the Manage Stock option for thousands of products. I am using PHP to update the Magento tables. I just need help identifying the tables and fields to update. The fields are:

Manage Stock
Qty for Item's Status to Become Out of Stock
Minimum Qty Allowed in Shopping Cart
Notify for Quantity Below

I believe they might be in catalog_product_entity_int but I have no idea what value relates to which.

3

3 Answers

2
votes

You're searching for the Mage_CatalogInventory_Model_Stock_Item model:

$sProductId = 911;
$oStockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($sProductId);
var_dump($oStockItem->getData());

Sample output:
["item_id"]=> string(4) "911"
["product_id"]=> string(4) "911"
["stock_id"]=> string(1) "1"
["qty"]=> string(6) "0.0000"
["min_qty"]=> string(7) "-3.0000"
["use_config_min_qty"]=> string(1) "1"
["is_qty_decimal"]=> string(1) "0"
["backorders"]=> string(1) "0"
["use_config_backorders"]=> string(1) "1"
["min_sale_qty"]=> string(7) "10.0000"
["use_config_min_sale_qty"]=> string(1) "1"
["max_sale_qty"]=> string(6) "0.0000"
["use_config_max_sale_qty"]=> string(1) "1"
["is_in_stock"]=> string(1) "0"
["low_stock_date"]=> string(19) "2013-06-28 01:02:34"
["notify_stock_qty"]=> string(6) "0.0000"
["use_config_notify_stock_qty"]=> string(1) "1"
["manage_stock"]=> string(1) "1"
["use_config_manage_stock"]=> string(1) "1"
["stock_status_changed_auto"]=> string(1) "1"
["use_config_qty_increments"]=> string(1) "1"
["qty_increments"]=> string(6) "0.0000"
["use_config_enable_qty_inc"]=> string(1) "1"
["enable_qty_increments"]=> string(1) "0"
["type_id"]=> string(6) "simple"
["stock_status_changed_automatically"]=> string(1) "1"
["use_config_enable_qty_increments"]=> string(1) "1"

Sample code to enable manage stock (or any other attributes):

$sProductId = 911;
$oStockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($sProductId);
$sStockId = $oStockItem->getId();
$aStock = array();
if (!$sStockId) {
    $oStockItem
        ->setProductId($sProductId)
        ->setStockId(1);
}
else {
    $aStock = $oStockItem->getData();
}

$aStock['manage_stock'] = 1;
// $aStock['use_config_manage_stock'] = 1;

foreach ($aStock as $k => $v) {
    $oStockItem->setData($k, $v);
}

$oStockItem->save();
3
votes

The manage stock option has its own col in cataloginventory_stock_item If you want to do this via mysql you can do this.

There are 2 options, not sure which is the right one for you.

If system configuration System->Inventory->Product Stock Options->Manage Stock is set to yes, you many want to only update use_config_manage_stock

UPDATE 
    cataloginventory_stock_item 
SET 
    use_config_manage_stock = 1

The other way is to set this for every product individually

UPDATE
    cataloginventory_stock_item 
SET 
    use_config_manage_stock = 0, 
    manage_stock = 1

After running these queries you should reindex the "Stock Status"

0
votes

Table : cataloginventory_stock_item

columns manage_stock update value to 1 and use_config_manage_stock update Value to 0