2015-03-24 103 views
1

由於某種原因,當我嘗試手動執行/cron.php文件時,出現上述錯誤。Mage_Cron_Model_Schedule類的對象無法轉換爲字符串

這裏是我的一個模塊,我認爲config.xml中造成問題

<?xml version="1.0" encoding="UTF-8"?> 

<!-- The root node for Magento module configuration --> 
<config> 

    <!-- 
     The module's node contains basic 
     information about each Magento module 
    --> 
    <modules> 

     <!-- 
      This must exactly match the namespace and module's folder 
      names, with directory separators replaced by underscores 
     --> 
     <Company_ScheduledPriceDrop> 

      <!-- The version of our module, starting at 0.0.1 --> 
      <version>0.0.1</version> 

     </Company_ScheduledPriceDrop> 

    </modules> 

    <crontab> 
     <jobs> 
      <Company_ScheduledPriceDrop> 
       <schedule> 
        <cron_expr>*/5 * * * *</cron_expr> 
       </schedule> 
       <run> 
        <model>Company_ScheduledPriceDrop/observer::setPrice</model> 
       </run> 
      </Company_ScheduledPriceDrop> 
     </jobs> 
    </crontab> 

</config> 

這裏是被稱爲觀察者文件

<?php 

class Company_ScheduledPriceDrop_Model_Observer extends Mage_Core_Model_Abstract 
{ 
    public function setPrice() 
    { 
     Mage::log("WORKS!"); 
    } 
} 

我不知道是什麼錯誤的意思是,任何人都可以幫忙嗎?

回答

2

\app\etc\modules\Company_ScheduledPriceDrop.xml\app\code\local\Company\ScheduledPriceDrop\etc\config.xml\app\code\local\Company\ScheduledPriceDrop\Model\Observer.php應該是您的文件。

Company_ScheduledPriceDrop.xml

<config> 
    <modules> 
     <Company_ScheduledPriceDrop> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Company_ScheduledPriceDrop> 
    </modules> 
</config> 

該文件會告訴你有一個模塊加載Magento的。

config.xml中

<config> 
    <modules> 
     <Company_ScheduledPriceDrop> 
      <version>1.0.0</version> 
     </Company_ScheduledPriceDrop> 
    </modules> 
    <global> 
     <models> 
      <scheduledpricedrop> 
       <class>Company_ScheduledPriceDrop_Model</class> 
      </scheduledpricedrop>       
     </models> 
    </global> 
    <crontab> 
     <jobs> 
      <scheduledpricedrop> 
       <schedule> 
        <cron_expr>*/5 * * * *</cron_expr> 
       </schedule> 
       <run> 
        <model>scheduledpricedrop/observer::setPrice</model> 
       </run> 
      </scheduledpricedrop> 
     </jobs> 
    </crontab> 
</config> 

該文件會告訴Magento的地方到Magento的系統模塊插頭。

另外..你需要有你的模型在全局命名空間的cron東西。 希望這有助於!

如果仍然無法正常工作,請發佈Magento輸出的完整錯誤,我會更新答案。

這裏,也有這個How to setup a cron job in Magento module?

1
<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <Company_Schedule> 
      <version>0.0.1</version> 
     </Company_Schedule> 
    </modules> 

    <global> 
     <models> 
      <schedule> 
       <class>Company_Schedule_Model</class> 
      </schedule> 
     </models> 
    </global> 

    <crontab> 
     <jobs> 
      <schedulepricedrop_cronjob> 
       <schedule> 
        <cron_expr>*/5 * * * *</cron_expr> 
       </schedule> 
       <run> 
        <model>schedule/observer::setPrice</model> 
       </run> 
      </schedulepricedrop_cronjob> 
     </jobs> 
    </crontab> 

</config> 

這對我的作品。從cron_schedule中選擇:

100  schedulepricedrop_cronjob pending  NULL 2015-04-10 05:22:11  2015-04-10 05:25:00  NULL NULL 
101  schedulepricedrop_cronjob pending  NULL 2015-04-10 05:22:11  2015-04-10 05:30:00  NULL NULL 
102  schedulepricedrop_cronjob pending  NULL 2015-04-10 05:22:11  2015-04-10 05:35:00  NULL NULL 
103  schedulepricedrop_cronjob pending  NULL 2015-04-10 05:22:11  2015-04-10 05:40:00  NULL NULL