I have a cron job set up where I need to get all simple products. This is working perfectly well when I'm running the script manually but when Cron runs it it fails to retrieve the products.
I've been trying to figure out exactly what is going wrong, but it doesn't seem like any errors regarding this is getting logged.
My guess is that it might have to do with when running the cron job manually from the adminpanel the store is set or something like that. I've tried setting this manually in the cron job itself as well.
I also tested to see if I could retrieve a single product by using the regular Mage::getModel('catalog/product')->load($productId)
which worked fine.
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
try{
$i = 0;
$productCollection = Mage::getResourceModel('catalog/product_collection')
->addStoreFilter(0)
->addAttributeToSelect('entity_id')
->addAttributeToSelect('parent_sku')
->addAttributeToSelect('qty')
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
->addAttributeToFilter('type_id', array('eq' => 'simple'));
Mage::log($productCollection->getSelect()->__toString(), null, 'cronlog.log');
foreach ($productCollection as $product) {
$this->updateStock($product);
Mage::log("Product: " . $i++, null, 'cronlog.log');
}
} catch (Exception $e){
Mage::logException("Exception whit aggregating stock");
throw new Exception($e->getMessage());
}
Mage::app()->cleanCache('catalog_product_view');