Magento Cron职务销售类别

Magento Cron职务销售类别,magento,cron,magento-1.7,Magento,Cron,Magento 1.7,我正在尝试使用cronjobs将所有具有“特殊价格”的产品添加到一个特殊类别中。我已经成功运行了cron.php,但是我似乎无法让cron正常工作。有人能看到我哪里出了问题吗 到目前为止,我所拥有的: app/code/local/Namespace/Modulename/ect/config.xml: <crontab> <jobs> <namespace_productassign> <schedule

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

到目前为止,我所拥有的: app/code/local/Namespace/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>

*/5 * * * * 
modulename/productassign::assignproduct
app/code/local/Namespace/Modulename/Model/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);
    }
}
}
?>

很抱歉,我不确定发生了什么,但我总是使用这个ext来帮助调试和运行cron作业

谢谢您的回复。前几天我安装了这个,我的cron似乎没有出现在列表上?这是否意味着config.xml有问题?您是否解决了u问题?尚未找到cron未运行的原因@monojiti之前使用过magento cron。确保您的模块工作正常。您可以使用Mage::log(“works”);在assignproduct函数内,用于检查函数是否正在调用。我在模块内使用了observer.php,但我认为这不是问题所在,我还使用了link,以确保cron.php工作正常。您可以从页面中删除所有函数,只需使用Mage::log(“works”);用于检查和清除缓存。如果您看到您的模块工作正常,但cron不工作,则在模型(类名称空间\u Modulename\u model\u observer)内创建observer.php,并检查它是否正常工作;1.他到底有没有工作。。