【问题标题】:cron job in magentoMagento中的cron作业
【发布时间】:2011-10-22 04:28:00
【问题描述】:

我不会在 magento 中做一分钟的 cron 工作,所以我有以下信息 http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job

所以在上面的帮助下,我为这个 cron 设置创建了新的模数,这个模数是活跃的并显示在 magento 管理面板中,但 cron 没有触发

我的配置文件代码是

<?xml version="1.0"?>
<config>
    <modules>
        <Apprika_Cron>
            <active>true</active>
            <codePool>local</codePool>
        </Apprika_Cron>
    </modules>
    <crontab>
          <jobs>
              <Apprika_Cron>
                  <schedule>
                      <cron_expr>*/1 * * * *</cron_expr>
                  </schedule>
                  <run>
                      <model>Cron/Observer::setLifeCycleStatus</model>
                  </run>
              </Apprika_Cron>
          </jobs>
      </crontab>
</config> 

以及我在 C:\xampp\htdocs\ce\app\code\local\Apprika\Cron\Model\Observer.php 中创建的模型

代码是

class Apprika_Cron_Model_Observer extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
         parent::_construct();
        $this->setLifeCycleStatus();
    }
    public function setLifeCycleStatus()
    {

       $products = Mage::getModel('catalog/product');
       $live_concluded=$this->getProductInfoforLifecycle();

       $product = Mage::getModel('catalog/product');
      if(count($live_concluded)>0){
       foreach($live_concluded as $status=>$value)
       {
           if($status=='live')
           {
               for($i=0;$i<count($value);$i++)
               {
                   $productId=$value[$i];
                   if($productId) 
                   {
                        try 
                        {  
                            $product->load($productId);
                            $product->setData('offer_stage','3');
                            $product->save();         
                        }catch(Exception $e)
                        {
                            Mage::printException($e);
                        }

                   }
               }
           }
           if($status=='concluded')
           {
               for($j=0;$j<count($value);$j++)
               {
                   $productId=$value[$j];

                   if($productId) 
                   {
                        try 
                        {  
                            $product->load($productId);
                            $product->setData('offer_stage','4');
                            $product->save();         
                        }catch(Exception $e)
                        {
                            Mage::printException($e);
                        }
                   }

               }
           }
       }
       }


    }
     public function getProductInfoforLifecycle() 
     {  
        $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*');
         $current_date=Date('Y-m-d H:i');  
        $current_date_ts=strtotime($current_date);
        $productarr=array();
        foreach($products as $product)
        { 
            $offer_stage=$product->getOffer_stage();
            $offer_start_date= $product->getOffer_start_date();
            $offer_start_date_ts=strtotime($offer_start_date);
            $offer_end_date= $product->getOffer_end_date();
            $offer_end_date_ts=strtotime($offer_end_date);
            $entity_id=$product->getEntity_id();
            if($offer_stage==2 && $offer_start_date!="" && $offer_end_date!="" && $offer_start_date_ts <=$current_date_ts)
            {
              $productarr['live'][]=$entity_id;
            }if($offer_stage==2 && $offer_start_date!="" && $offer_end_date!="" && $offer_end_date_ts <=$current_date_ts)
            {
              $productarr['concluded'][]=$entity_id;
            }

        }

         return $productarr;
      }  
}

但是这个 cron 没有被调用所以这个记录没有更新

如果我打电话给http://xyz.com/cron.php

然后记录更新,但在 cron 记录的帮助下没有更新

提前致谢

【问题讨论】:

  • 你找到解决办法了吗...问题是什么??

标签: magento


【解决方案1】:

您需要将此行(或类似的行)添加到您的 crontab:

*/5 * * * *  /bin/sh /absolute/path/to/magento/cron.sh

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-06-07
  • 1970-01-01
  • 1970-01-01
  • 2011-08-18
  • 1970-01-01
  • 1970-01-01
  • 2013-04-05
  • 2016-04-05
相关资源
最近更新 更多