类Mage_Cron_Model_Schedule的对象无法转换为字符串

时间:2015-03-24 22:21:00

标签: magento

当我尝试手动执行/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!");
   }
}

我不确定错误的含义,有人可以帮忙吗?

2 个答案:

答案 0 :(得分: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 :(得分: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