2013-10-25 20 views
-1

我在Magento中创建了“新产品”类别,并且我试图让CRON作业运行并自动标记已经在过去14天内创建,并在创建超过14天后将其从“新产品”类别中移除。设置CRON自动将最近添加的产品标记到“新产品”类别中

我看了几个帖子,他们提到了这里提到的一篇文章:http://www.ecomdev.org/2010/06/07/how-to-schedule-the-future-product-activation.html唯一的问题是帖子不再有效。 Google缓存也没有存储它。

回答

0

您好,请尝试如下:

首先创建一个自定义模块,并在config.xml文件拷贝下面的代码:

<crontab> 
    <jobs> 
     <inchoo_birthday_send> 
      <schedule><cron_expr>0 1 * * *</cron_expr></schedule> 
      <run><model>birthday/observer::sendBirthayEmail</model></run> 
     </inchoo_birthday_send> 
    </jobs> 
</crontab> 

创建一个名为observer.php模型文件(模型文件夹中)与方法sendBirthayEmail如下:

class Inchoo_Birthday_Model_Observer 
{ 
    public function sendBirthayEmail() 
    { 
     $day = new DateTime(); 
     $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
     $collection = Mage::getResourceModel('catalog/product_collection'); 
     $collection->addAttributeToFilter('status',1); //only enabled product 

     $day->modify("-14 days"); 
     $fromDate = $day->format("Y-m-d 00:00:00"); 
     $collection->addAttributeToFilter('created_at', array('or'=> array(0 => array('date' => true, 'from' => $fromDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left'); 
     $collection->setOrder('created_at', 'desc'); 
     $collection->addAttributeToSelect('*'); //add product attribute to be fetched 
     $collection->addStoreFilter(); 
     if(!empty($collection)) 
     { 
      //do your work here. 
     } 
     return $this; 
    } 
} 

请不,我已经复制上面的代码从我安装的一个,而不是100%完成,你必须调整到代码使其成为您想要的输出。

相关问题