【问题标题】:Magento - Extension that is listening on Order status changeMagento - 监听订单状态变化的扩展
【发布时间】:2015-01-27 13:54:10
【问题描述】:

我正在使用 Magento 1.9.0.1。

我正在尝试创建一个非常简单的扩展来监听订单状态的变化。

这是我到目前为止所做的:

文件:/VivasIndustries/SmsNotification/etc/config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_SmsNotification>
      <version>0.1.0</version>
    </VivasIndustries_SmsNotification>
  </modules>
  <global>
    <events>
        <sales_order_save_after>
            <observers>
                <vivasindustries_smsnotification>
                    <class>smsnotification/observer</class>
                    <method>orderSaved</method>
                </vivasindustries_smsnotification>
            </observers>
        </sales_order_save_after>
    </events>
  </global>

文件:/VivasIndustries/SmsNotification/Model/Observer.php:

<?PHP
class VivasIndustries_SmsNotification_Model_Observer
{
    public function orderSaved(Varien_Event_Observer $observer)
    {
        Mage::log("Test")
    }
}

文件:/app/etc/modules/VivasIndustries_SmsNotification.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_SmsNotification>
      <active>true</active>
      <codePool>community</codePool>
      <version>0.1.0</version>
    </VivasIndustries_SmsNotification>
  </modules>
</config>

我已经按照本指南完成了所有操作:http://www.danielhanly.com/blog/observing-order-status-changes-magento/

问题是当我检查我的 system.log 文件时,没有带有“Test”的行或文本。似乎它没有在日志文件中插入此文本,这让我认为当我更改订单状态/保存订单时它无法识别。

你能指出我的错误在哪里,并帮助我解决这个问题。

提前致谢!

【问题讨论】:

    标签: php magento


    【解决方案1】:

    尝试在您的事件节点中添加如下类型:

    <events>
            <sales_order_save_after>
                <observers>
                    <vivasindustries_smsnotification>
    <type>model</type>
                        <class>smsnotification/observer</class>
                        <method>orderSaved</method>
                    </vivasindustries_smsnotification>
                </observers>
            </sales_order_save_after>
        </events>
    

    另外,要检查您的代码是否正常工作,请添加 echo 'something';exit;在您的观察者功能中。转到后端并取消任何订单。这也应该调度您的函数,因为订单状态将更改为已取消。

    【讨论】:

    • 我已经完成了您让我做的更改,但它似乎不再起作用。 :(
    • 我发现以下更改:1)关闭 config.xml 中的 标签 2)将配置事件更改为以下内容: modelVivasIndustries_SmsNotification_Model_ObserverorderSaved 3) 请检查最后所有文件权限跨度>
    • 请使用新数据编辑您的答案,因为我无法通过评论之类的答案清楚地理解您。谢谢!
    【解决方案2】:

    您的观察者模型和 app/etc/modules/xml 文件是正确的。您需要将等中的 config.xml 更改为以下内容:

    <?xml version="1.0"?>
    <config>
        <modules>
            <VivasIndustries_SmsNotification>
                <version>0.1.0</version>
            </VivasIndustries_SmsNotification>
        </modules>
        <global>
            <events>
                <sales_order_save_after>
                    <observers>
                        <smsnotification>
                            <type>model</type>
                            <class>VivasIndustries_SmsNotification_Model_Observer</class>
                            <method>orderSaved</method>
                        </smsnotification>
                    </observers>
                </sales_order_save_after>
            </events>
        </global>
    </config>
    

    还只是建议您可以删除 Model Observer.php 中明确提到的对象类型

    你可以通过:

    公共函数 orderSaved($observer)

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 2011-01-31
      • 2019-08-10
      • 1970-01-01
      相关资源
      最近更新 更多