Magento - update all products inventory with sql

后端 未结 4 1518
轮回少年
轮回少年 2021-01-03 16:58

I want to update the inventory of all My Magento products.

Can I do that with an only sql request?

What\'s the request if that\'s possible ?

Thanks

4条回答
  •  不知归路
    2021-01-03 17:20

    function updateProductStock($productId, $qty) { 
        $resource = Mage::getSingleton('core/resource');
        $write = $resource->getConnection('core_write');
        $write->update(
          "cataloginventory_stock_item"
        , array("qty" => $qty, 'is_in_stock' => ($qty > 0 ? 1 : 0))
        , "product_id = " . $productId
        );
    } 
    

提交回复
热议问题