【问题标题】:Setup CRON to automatically flag a recently added product into the "New Product" category设置 CRON 以自动将最近添加的产品标记为“新产品”类别
【发布时间】:2013-10-25 07:32:06
【问题描述】:

我在 Magento 中创建了一个“新产品”类别,我正在尝试让 CRON 作业运行并自动标记过去 14 天内创建的产品,并将它们从“新产品”中删除类别一旦创建超过 14 天。

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

【问题讨论】:

    标签: php magento cron magento-1.7


    【解决方案1】:

    您好,请尝试如下:

    首先创建一个自定义模块,并在 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>
    

    使用 sendBirthayEmail 方法创建一个名为 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% 完成,您必须调整代码以使其成为您想要的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 2019-07-15
      • 2022-11-05
      • 2018-03-26
      • 1970-01-01
      相关资源
      最近更新 更多