Skip to content

Instantly share code, notes, and snippets.

@stnc
Created June 8, 2017 11:16
Show Gist options
  • Save stnc/9abdf8c2c252e47f60f876cf7f947124 to your computer and use it in GitHub Desktop.
Save stnc/9abdf8c2c252e47f60f876cf7f947124 to your computer and use it in GitHub Desktop.
<?php
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
if ($product) {
$productId = $product->getId();
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
$stockItemId = $stockItem->getId();
$stock = array();
if (!$stockItemId) {
$stockItem->setData('product_id', $product->getId());
$stockItem->setData('stock_id', 1);
}
else {
$stock = $stockItem->getData();
}
$stock['qty'] = $qty;
$stock['is_in_stock'] = $is_in_stock;
$stock['manage_stock'] = 1;
foreach($stock as $field => $value) {
$stockItem->setData($field, $value ? $value : 0);
}
$stockItem->save();
unset($stockItem);
unset($product);
}
print $sku." Güncellendi!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment