Magento Cron 作业销售类别

问题描述 投票:0回答:1

我正在尝试使用 cron 作业将所有具有“特价”的产品添加到特殊类别中。我已经成功运行了 cron.php,但是我似乎无法让 cron 工作,任何人都可以看到我哪里出了问题吗?

到目前为止我所拥有的: 应用程序/代码/本地/命名空间/模块名称/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>

应用程序/代码/本地/命名空间/模块名称/模型/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 工作吗?

php magento cron magento-1.7
1个回答
0
投票

抱歉,不确定发生了什么,但我总是使用这个 ext 来帮助调试和运行 cron 作业
http://www.magentocommerce.com/magento-connect/aoe-scheduler.html

© www.soinside.com 2019 - 2024. All rights reserved.