【问题标题】:Magento Observer Event on Order Place not firing订单位置上的 Magento 观察者事件未触发
【发布时间】:2013-12-06 21:53:36
【问题描述】:

当有人点击下订单但它没有触发时,我正在尝试运行一个事件。我知道它有效,因为我可以将事件更改为产品更新,并且当我更新产品时它会写入日志文件。我正在使用粉碎杂志教程,只是更改事件。

我已经尝试了这两个事件:

  • checkout_submit_all_after
  • checkout_onepage_controller_success_action

我做错了什么?

配置.xml

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

    <!-- Configure our module's behavior in the global scope -->
    <global>

        <!-- Defining models -->
        <models>

            <!--
                Unique identifier in the model's node.
                By convention, we put the module's name in lowercase.
            -->
            <smashingmagazine_logproductupdate>

                <!--
                    The path to our models directory, with directory
                    separators replaced by underscores
                -->
                <class>SmashingMagazine_LogProductUpdate_Model</class>

            </smashingmagazine_logproductupdate>

        </models>

        <events>
            <checkout_submit_all_after>
                <observers>
                    <smashingmagazine_logproductupdate>
                        <class>smashingmagazine_logproductupdate/observer</class>
                        <method>logUpdate</method>
                        <type>singleton</type>
                    </smashingmagazine_logproductupdate >
                </observers>
            </catalog_product_save_after>
        </events>

    </global>

</config>

Observer.php

<?php
/**
 * Our class name should follow the directory structure of
 * our Observer.php model, starting from the namespace,
 * replacing directory separators with underscores.
 * i.e. app/code/local/SmashingMagazine/
 *                     LogProductUpdate/Model/Observer.php
 */

class SmashingMagazine_LogProductUpdate_Model_Observer
{
    /**
     * Magento passes a Varien_Event_Observer object as
     * the first parameter of dispatched events.
     */
    public function logUpdate(Varien_Event_Observer $observer)
    {



        // Write a new line to var/log/product-updates.log
        $name = 'asdf';
        $sku = 'weee';
        Mage::log(
            "{$name} ({$sku}) updated",
            null, 
            'product-updates.log'
        );
    }
}

【问题讨论】:

    标签: php magento


    【解决方案1】:

    只需尝试使用下面的示例直接放置观察者类和语法,并且在 &lt;/smashingmagazine_logproductupdate &gt; 这样的唯一标签中有空格,这应该是 &lt;/smashingmagazine_logproductupdate&gt;

    <events> 
         <checkout_submit_all_after>
              <observers>
                <smashingmagazine_logproductupdate>
                     <class>SmashingMagazine_LogProductUpdate_Model_Observer</class>
                     <method>logUpdate</method>
                </smashingmagazine_logproductupdate>
              </observers>
         </checkout_submit_all_after>
    </events>      
    

    希望这能帮助您解决问题。

    【讨论】:

      【解决方案2】:

      在 Magento 中创建配置 xml 时需要注意一些事项。

      始终使用&lt;Namesapce_Modulename&gt; 而不是&lt;NameSpace_ModuleName&gt;,因为当您使用namesapce/modulename 创建对象时它将不起作用,因为Magento 会尝试查找Namespace_Modulename_Model_Class 而不是NameSpace_ModuleName_Model_Class 这样的类。

      在您的情况下,请正确更改您的命名空间和模块名称或使用以下 config.xml

      <events>
             <checkout_submit_all_after>
                  <observers>
                      <SmashingMagazine_LogProductUpdate_Model_Observer>
                          <class>SmashingMagazine_LogProductUpdate_Model_Observer</class>
                          <method>logUpdate</method>
                          <type>singleton</type>
                      </SmashingMagazine_LogProductUpdate_Model_Observer>
                  </observers>
              </catalog_product_save_after>
      </events>
      

      【讨论】:

        猜你喜欢
        • 2016-11-01
        • 1970-01-01
        • 2011-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多