Created
June 8, 2017 11:16
-
-
Save stnc/9abdf8c2c252e47f60f876cf7f947124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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