通过Cron获取产品系列

问题描述 投票:0回答:1

我有一个cron工作,我需要获得所有简单的产品。当我手动运行脚本时,这非常有效,但是当Cron运行它时,它无法检索产品。

我一直在试图弄清楚到底出了什么问题,但似乎没有任何关于这个错误的记录。

我的猜测是,它可能与从商店设置的adminpanel手动运行cron作业或类似的事情有关。我也试过在cron作业中手动设置它。

我还测试了是否可以通过使用正常的Mage::getModel('catalog/product')->load($productId)来检索单个产品。

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);
  }

} catch (Exception $e){
  Mage::logException("Exception with aggregating stock");
  throw new Exception($e->getMessage());
}

Mage::app()->cleanCache('catalog_product_view');
magento cron magento-1.7
1个回答
0
投票

我找到了问题的原因。看来,当cron自动运行时,脚本内存不足。

我在我的脚本顶部添加了ini_set('memory_limit','800M');,这解决了我的问题

© www.soinside.com 2019 - 2024. All rights reserved.