<?php /** * file path: * magento_root/app/code/local/Some/Extension/Model/Observer.php */ class Some_Extension_Model_Observer { public function someMethod( $observer ) { /** *Do some stuff here */ return $observer; } } ?>
This observer is catching some event using someMethod(), and it is described in the extension’s config.xml file (note that we are using only the required parameters for this example):
<?xml version="1.0"?>When we already have a starting point, we need to override the observer’s method – someMethod(). Let’s prepare our extension for this stage:1.0.0 Some_Extension_Model singleton some_extension/observer someMethod
<?xml version="1.0"?>true local
<?xml version="1.0"?>1.0.0 Our_Extension_Model
In this case, we can make a conventional model rewrite. We need to add the rewrite to the model’s node in config.xml:
Our_Extension_Model Our_Extension_Model_Rewrite_Observer
Here is the rewritten observer file itself:
<?php /** * file path: * magento_root/app/code/local/Our/Extension/Model/Rewrite/Observer.php */ class Our_Extension_Model_Rewrite_Observer extends Some_Extension_Model_Observer { public function someMethod( $observer ) { /** * Our stuff here */ return $observer; } } ?>By the way, recently we have faced with the observer declaration that can not be overridden that way:
Actually, there are two ways to reach our goal here. And in both ways we need to make our extension dependent on the other extension (which is being overridden) in the Our_Extension.xml:singleton Some_Extension_Model_Observer someMethod
<?xml version="1.0"?>The first way is to disable the second extension’s observer and bind our observer to the same event instead. Add the events node to our extension’s config.xml with this content (the events node is included):true local
Furthermore, the second way is to adjust the model call to use pseudonyms in the original observer’s identifier by rewriting it. The whole config.xml of our extension will look like this:disabled singleton Our_Extension_Model_Rewrite_Observer someMethod
<?xml version="1.0"?>This approach allows us to make the conventional rewrite using a safe way. Moreover, the last thing that we would like to mention is that there was no interference into the Some_Extension code.0.1.0 Our_Extension_Model Our_Extension_Model_Rewrite_Observer singleton Some_Extension_Model_Observer someMethod
No comments:
Post a Comment