1

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');
0

I managed to find the cause of my issue. It appears that when the cron was running automatically the script ran out of memory.

I added ini_set('memory_limit','800M'); at the top of my script and this solved my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.