设置 CRON 以自动将最近添加的产品标记为“新产品”类别


Setup CRON to automatically flag a recently added product into the "New Product" category

我在Magento中创建了一个"新产品"类别,我正在尝试让CRON Job运行并自动标记过去14天内创建的产品,并在创建超过14天后将其从"新产品"类别中删除。

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

您好请尝试以下操作:

首先创建一个自定义模块,并在 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(在模型文件夹中)的模型文件,方法发送出生电子邮件,如下所示:

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% 完成,您必须调整代码才能使其出现在您想要的输出中。