0

I used an observer in my extension called checkout_type_onepage_save_order_after but I don't know why this observer work even customers do not use my extension!

My extension is custom shipping extension and for saving my orders with api in my shipping panel, should use observer

code is

<global>        
<events>
    <checkout_type_onepage_save_order_after>
        <observers>
            <mycompany_myextension_order_complete>
                <class>myextension/observer</class>
                <method>myextensionCompleteOrder</method>
            </mycompany_myextension_order_complete>
        </observers>
    </checkout_type_onepage_save_order_after>
</events>
</global>

How can I prevent load observer when customers do not select this shipping method ?

1 Answer 1

0

Observer will always observe your event. In order to prevent it from calling whatever function you want to execute, you should set if condition in your observer function.

<?php
class Namespace_Module_Model_Observer
{
   public function myextensionCompleteOrder($observer)
   {
      $quote  = $observer->getEvent()->getQuote();

      $shipping_method = $quote->getShippingAddress()->getShippingMethod(); //selected shipping method
      if ($shipping_method == 'your_shipping_method') {
         //do your stuff here
         //......
        }
   }
}

Hope this will help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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