0

I have created a custom module to catch the sales_order_place_after event, but when i finish a order nothing happen. My module it's active.

My module looks like this:

config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <In2itive_OrderComment>
      <version>0.1.0</version>
    </In2itive_OrderComment>
  </modules>
  <global>
    <models>
      <ordercomment>
        <class>In2itive_OrderComment_Model</class>
        <resourceModel>in2itiveordercomment_mysql4</resourceModel>
      </ordercomment>
    </models>
    <events>
      <sales_order_place_after>
        <observers>
          <checkout_submit_all_after_handler>
            <type>model</type>
            <class>in2itive_ordercomment/observer</class>
            <method>logShipping</method>
          </checkout_submit_all_after_handler>
        </observers>
      </sales_order_place_after>
    </events>
  </global>
</config>

and Observer.php located in In2itive/OrderComment/Model/Observer.php :

<?php
class In2itive_OrderComment_Model_Observer
{

    public function logShipping($observer)
    {   Mage::log('your debug', null, 'yourlog.log');
        $order = $observer->getEvent()->getOrder();
        $history = $order->addStatusHistoryComment($order->getShippingMethod(), false);
        $history->setIsCustomerNotified(false);
        $order->save();
    }

}

Even a put a print_R i don't receive nothing. My module it's not catching the event or I don't use the corect log method for this situation?

  • Do you need to set it globally the observer event ? Do you need it for both frontend and backend to be executed ? – Attila Naghi Jun 30 '17 at 11:48
3

Try this XML code:

    <adminhtml>
          <events>
                <sales_order_place_after>
                    <observers>
                        <mynamespace_mymodule_sales_order_place_after>
                            <type>singleton</type>
                            <class>Mynamespace_Mymodule_Model_Observers_Log</class>
                            <method>logShipping</method>
                        </mynamespace_mymodule_sales_order_place_after>
                    </observers>
                </sales_order_place_after
          </events>
    </adminhtml>

and in the Log observer class:

class Mynamespace_Mymodule_Model_Observers_Log
{
   public function logShipping() 
   {
        // Do logic here
   }
}
2

Try below code in file config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <In2itive_OrderComment>
      <version>0.1.0</version>
    </In2itive_OrderComment>
  </modules>
  <global>
    <models>
      <ordercomment>
        <class>In2itive_OrderComment_Model</class>
        <resourceModel>ordercomment_mysql4</resourceModel>
      </ordercomment>
    </models>
    <events>
      <sales_order_place_after>
        <observers>
          <checkout_submit_all_after_handler>
            <type>model</type>
            <class>In2itive_OrderComment_Model_Observer</class>
            <method>logShipping</method>
          </checkout_submit_all_after_handler>
        </observers>
      </sales_order_place_after>
    </events>
  </global>
</config>

OR

<?xml version="1.0"?>
<config>
  <modules>
    <In2itive_OrderComment>
      <version>0.1.0</version>
    </In2itive_OrderComment>
  </modules>
  <global>
    <models>
      <ordercomment>
        <class>In2itive_OrderComment_Model</class>
        <resourceModel>ordercomment_mysql4</resourceModel>
      </ordercomment>
    </models>
    <events>
      <sales_order_place_after>
        <observers>
          <checkout_submit_all_after_handler>
            <type>model</type>
            <class>ordercomment/observer</class>
            <method>logShipping</method>
          </checkout_submit_all_after_handler>
        </observers>
      </sales_order_place_after>
    </events>
  </global>
</config>
1
<frontend>
      <events>
         <checkout_submit_all_after>
                <observers>
                    <checkout_submit_all_after>
                        <class>in2itive_ordercomment/observer</class>
                        <method>logShipping</method>
                    </checkout_submit_all_after>
                </observers>
         </checkout_submit_all_after>
      </events>
</frontend>

Try the above code in your xml

  • Can you please add you other answers here and delete them? – sv3n Jun 30 '17 at 12:22
0

Its possible your observer file is not found try keeping your full file path

<events>
  <sales_order_place_after>
    <observers>
      <checkout_submit_all_after_handler>
        <type>singleton</type>
        <class>In2itive_OrderComment_Model_Observer</class>
        <method>logShipping</method>
      </checkout_submit_all_after_handler>
    </observers>
  </sales_order_place_after>
</events>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.