2013-03-08 81 views
-1

如何在magento中逐步设置cron作业。如果我有一个具有设置日期的属性,我希望cron作业禁用产品,如果一天已经过去...Cron作业禁用产品Magento 1.7 CE

+0

你有没有找到解决办法? – 2016-05-09 12:25:39

回答

4

1)创建一个自定义模块,有很多指南 - 或使用模块创建器让你开始。

2)添加了cron作业设置你的模块配置

config.xml中

... 
    <crontab> 
     <jobs> 
      <mymodule_disable> 
       <schedule> 
        <!-- every 10 min --> 
        <cron_expr>*/10 * * * *</cron_expr> 
       </schedule> 
       <run> 
        <model>mymodule/Scheduler::disable</model> 
       </run> 
      </mymodule_disable> 
     </jobs> 
    </crontab> 

</config> 

现在,创建一个类来处理任务,为您(MODULENAME /型号/ Scheduler.php)

Scheduler.php

<?php 
class Mymodule_Model_Scheduler 
{ 
    /** 
    * Disable prodcuts for us 
    */ 
    public static function disable() 
    { 
     // This will be run every 10 minutes, we want to get applicable products 
     // you will need to customize the filter for what you need, subtracting 
     // or adding date values etc.. you get the idea :) 
     $date = Mage::getModel('core/date')->gmtDate(); // add/subtract etc 
     $collection = Mage::getModel('catalog/product')->getCollection(); 
     $collection->addfieldtofilter('custom_date_attr', array(
      array('to' => $date), 
      //array('gteq' => $date) 
     )); 
     foreach($collection as $product) { 
      $product->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED); 
      $product->save(); 
     } 
    } 
} 

现在,你需要设置一个cron作业运行Magentos调度,例如:

*/10 * * * * php -f /path/to/magento/cron.php