class Mage_Cron_Model_Schedule 的对象无法转换为字符串
Object of class Mage_Cron_Model_Schedule could not be converted to string
当我尝试手动执行 /cron.php 文件时,出于某种原因出现上述错误。
这是我的 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!");
}
}
我不确定错误是什么意思,有人可以帮忙吗?
\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 内容。
希望这对您有所帮助!
如果还是不行,请 post Magento 输出完整的错误,我会更新答案。
还有这个How to setup a cron job in Magento module?
<?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>
对我有用。 Select 来自 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
当我尝试手动执行 /cron.php 文件时,出于某种原因出现上述错误。
这是我的 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!");
}
}
我不确定错误是什么意思,有人可以帮忙吗?
\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 内容。 希望这对您有所帮助!
如果还是不行,请 post Magento 输出完整的错误,我会更新答案。
还有这个How to setup a cron job in Magento module?
<?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>
对我有用。 Select 来自 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