Skip to content

Instantly share code, notes, and snippets.

@aliomattux
Created April 26, 2016 22:30
Show Gist options
  • Save aliomattux/dfda94ef8275b7d2336fd4e161d2c403 to your computer and use it in GitHub Desktop.
Save aliomattux/dfda94ef8275b7d2336fd4e161d2c403 to your computer and use it in GitHub Desktop.
public function updateproductstock(array $productData) {
foreach ($productData as $productId => $data) {
$productId = (int) $productId;
$isInStock = $data['is_in_stock'];
$manageStock = $data['manage_stock'];
$qty = $data['qty'];
$configManageStock = $data['config_manage_stock'];
$this->updateOneProductStock($productId, $isInStock, $manageStock, $qty, $configManageStock);
}
// $process = Mage::getModel('index/indexer')->getProcessByCode('cataloginventory_stock');
// $process->reindexAll();
}
public function updateOneProductStock($productId, $isInStock, $manageStock, $qty, $configManageStock) {
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
if ($stockItem && !$stockItem->getProductId()) {
$stockItem->setData('product_id', $productId);
$stockItem->setData('stock_id', 1);
}
if (!stockItem) {
return;
}
// $stockItem->setData('product_id', $productId);
$stockItem->setData('qty', $qty);
// $stockItem->setData('store_id', 1);
// $stockItem->setData('stock_id', 1);
$stockItem->setData('is_in_stock', $isInStock);
$stockItem->setData('manage_stock', $manageStock);
$stockItem->setData('use_config_manage_stock', $configManageStock);
$stockItem->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment