简体   繁体   中英

Magento Observer Event on Order Place not firing

I'm trying to run an event when someone clicks place order however it's not firing. I know it works because I can change the event to product update and when I update a product it writes in the log file. I'm using the smashing magazine tutorial, just changing the event.

I've tried both of these events:

  • checkout_submit_all_after
  • checkout_onepage_controller_success_action

What am I doing wrong?

Config.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'
        );
    }
}

just try with below example to put observer class directly and syntax as well as you have space in unique tag like </smashingmagazine_logproductupdate > this should be </smashingmagazine_logproductupdate>

<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>      

hope this will sure help you to solve your issue.

Some point need to take care while creating config xml in Magento.

Always use <Namesapce_Modulename> not <NameSpace_ModuleName> as it will not work when you create object using namesapce/modulename as Magento try to find the class like Namespace_Modulename_Model_Class not NameSpace_ModuleName_Model_Class .

In your case either change your Namespace and Moduel name properly or use the below 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM