Skip to content

Instantly share code, notes, and snippets.

@trabulium
Created May 30, 2016 00:43
Show Gist options
  • Save trabulium/a2a5129f13ae0736f9a4fb54385fe9f7 to your computer and use it in GitHub Desktop.
Save trabulium/a2a5129f13ae0736f9a4fb54385fe9f7 to your computer and use it in GitHub Desktop.
Bulk Set Magento Stock Status as True
define('MAGENTO_ROOT', "/path/to/magento");
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
Mage::app()->getStore()->setId(0);
class Mage_Shell_setStock {
$stockCollection = Mage::getModel('catalog/product')->getCollection();
foreach ($stockCollection as $stockItem) {
$product = mage::getModel('catalog/product')->setStoreId(0)->load($stockObject->getId());
if ($stockItem->getIsInStock() == False) {
try {
$stockItem->setIsInStock(True)->save();
$this->_doReindexFlag = true;
}
catch (Exception $e) {
Mage::Log($e);
echo "Problem setting SKU ".$product->getSku()." into stock \n";
}
}
}
if ($this->_doReindexFlag) {
$this->reindex(array('cataloginventory_stock',
'catalogsearch_fulltext',
));
}
}
$shell = new Mage_Shell_setStock();
$shell->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment