Php 设置CRON以自动将最近添加的产品标记到;“新产品”;类别
我在Magento中创建了一个“新产品”类别,我正在尝试获取一个CRON作业来运行并自动标记在过去14天内创建的产品,并在创建超过14天后将其从“新产品”类别中删除Php 设置CRON以自动将最近添加的产品标记到;“新产品”;类别,php,magento,cron,magento-1.7,Php,Magento,Cron,Magento 1.7,我在Magento中创建了一个“新产品”类别,我正在尝试获取一个CRON作业来运行并自动标记在过去14天内创建的产品,并在创建超过14天后将其从“新产品”类别中删除 我看了几篇文章,他们提到了这里提到的一篇文章:唯一的问题是这篇文章不再有效。谷歌缓存也没有存储它。您好,请尝试以下操作: 首先创建一个自定义模块,并在config.xml文件中复制以下代码: <crontab> <jobs> <inchoo_birthday_send>
我看了几篇文章,他们提到了这里提到的一篇文章:唯一的问题是这篇文章不再有效。谷歌缓存也没有存储它。您好,请尝试以下操作: 首先创建一个自定义模块,并在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>
请不要说我从我的一个安装中复制了上面的代码,并且没有100%完成,你必须调整到代码中,使其成为你想要的输出
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;
}
}