2

I want to override event for method saveDownloadableOrderItem :

<adminhtml>
   <sales_order_item_save_commit_after>
     <observers>
        <downloadable_observer>
              <class>downloadable/observer</class>
              <method>saveDownloadableOrderItem</method>
          </downloadable_observer>
      </observers>
  </sales_order_item_save_commit_after>
</adminhtml>

1 Answer 1

4

Option 1
If you want to add some more logic int he method saveDownloadableOrderItem but still be able to call the original method you can do this.
Create a new module and in the config.xml file of it, under the global tag, add this:

<models>
    <downloadable>
        <rewrite>
            <observer>[Namespace]_[Module]_Model_Observer</observer>
        <rewrite>
    </downloadable>
</models>

then create the file [Namespace]/[Module]/Model/Observer.php in your module with this content

public function saveDownloadableOrderItem($observer)
{
    //your code here.
}

Option 2
If you want to completely disable the original method and use your own you can do this:
Create a module and in the config.xml file add this code:

<adminhtml>
    <events>
        <sales_order_item_save_commit_after>
            <observers>
               <downloadable_observer>
                   <class>[yourmodule]/observer</class>
                   <method>yourMethodName</method>
               </downloadable_observer>
            </observers>
         </sales_order_item_save_commit_after>
    </events>
</adminhtml>
4
  • why not in <events> ?
    – Krupali
    Nov 28, 2016 at 13:04
  • I don't understand. what do you mean? You want to completely change what happens? I mean, that method should not be called at all, instead your method should be called?
    – Marius
    Nov 28, 2016 at 13:06
  • Yes I want to called my method instead of "saveDownloadableOrderItem" .
    – Krupali
    Nov 28, 2016 at 13:07
  • 1
    I've edited the answer. But there is on catch. If you chose option 2 your class & method will be called only on the admin part. the frontend part will still use the original method. With the first approach, your new method will be called for both admin & frontend.
    – Marius
    Nov 28, 2016 at 13:10

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.