Magento – How to set enable qty increments and set the qty increment in php

magento-1.7magento-1.8

I have a large list of products that for each I have to enable qty_increments and set the qty_ increment to a specific value for that product.

I am not sure how to do that in php.

I know how to get and save the product just not how do enable and set the increments

my input is:

sku qty_increment
sku qty_increment ….

Thanks

Best Answer

   $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
   $productId = $product->getId();
   $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
   $stockItemId = $stockItem->getId(); // in case you need it

   $stockItem->setData('use_config_qty_increments', false);
   $stockItem->setData('use_config_enable_qty_inc', false);
   $stockItem->setData('use_config_enable_qty_increments', false);

   $stockItem->setData('enable_qty_increments', true);
   $stockItem->setData('qty_increments', $newIncrement);

I am not sure if I need all that, or if it can be shortened, but it works for me as is. I am not showing the error checking and handling.

Related Topic