I need a script that will check all magento products and set them to instock if the qty is greater than 0.
The plan is to run this as a scheduled cronjob so that it will be checking for any products that have their stock value incorrectly set.
My code is rather crude so far but here is what i have come up with:
<?php PHP_SAPI == 'cli' or die;
ini_set('memory_limit','1024M');
set_time_limit(0);
error_reporting(E_ALL | E_STRICT);
require_once '../app/Mage.php';
umask(0);
Mage::app();
$product = Mage::getModel('catalog/product')->load($product_id);
$stock_item = $product->getStockItem();
if ($stock_item->getQty() < 0){
$stockItem->setIsInStock(true);
$stockItem->save();
$product->save();
}
?>
Unfortunately when i run this nothing changes in the backend and no products are set to instock as they should.
Perhaps somebody could point to where i'm going wrong or a better solution?