我正在尝试使用cron作业将所有具有“特殊价格”的产品添加到特殊类别中。我已经成功运行了cron.php但是我似乎无法让cron工作,任何人都可以看到我哪里出错了?
到目前为止我所拥有的: 应用程序/代码/本地/命名空间/ MODULENAME / ECT / config.xml中:
<crontab>
<jobs>
<namespace_productassign>
<schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
<run><model>modulename/productassign::assignproduct</model></run>
</namespace_productassign>
</jobs>
</crontab>
应用程序/代码/本地/命名空间/ MODULENAME /型号/ Productassign.php:
<?php
class Namespace_Modulename_Model_Productassign {
public function assignproduct () {
try {
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$productIds = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('visibility', array('neq'=>1))
->addAttributeToFilter('status', array('neq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED))
->addAttributeToFilter('price', array('neq' => ""))
->addAttributeToFilter('special_price', array('neq' => ""))
->addAttributeToFilter('special_price', array('lt' =>new Zend_Db_Expr('at_price.value')))
->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(0 => array('date' => true, 'from' =>$tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')
->getAllIds();
$newCategories = 68; // Add here your SALE category id
$category = Mage::getModel('catalog/category')->load($newCategories);
$saleIds = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($category)
->getAllIds();
$product = (array_values(array_diff($productIds,$saleIds)));
foreach ($product as $id) {
$sql = "INSERT INTO catalog_category_product (category_id ,product_id) VALUES ('".$newCategories."', '".$id."')";
$statement = $write->query($sql);
}
// Working copy of unassign product from Sale Category whose special to date is ended.
$current_date = date('Y-m-d H:i:s');
$category = Mage::getModel('catalog/category')->load($newCategories);
$saleIds = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($category)
->addAttributeToFilter('special_to_date', array('date'=>true, 'lt'=> $current_date))
->getAllIds();
foreach ($saleIds as $id) {
$sql = "Delete from catalog_category_product where category_id='".$newCategories."' and product_id='".$id."'";
$statement = $write->query($sql);
}
/* reindexing
3. Catalog URL Rewrites
6. Category Products
*/
$process = Mage::getModel('index/process')->load(3);
$process->reindexAll();
$process = Mage::getModel('index/process')->load(6);
$process->reindexAll();
}
catch (Exception $e) {
Mage::log($e);
}
}
}
?>
任何帮助都会很棒,谢谢。我需要做任何其他事情来使这个cron工作吗?
答案 0 :(得分:0)
很抱歉不确定是什么,但我总是使用这个ext来帮助调试和运行cron作业
http://www.magentocommerce.com/magento-connect/aoe-scheduler.html