[TL:DR]
I have Core_Class_A
and Core_Class_B extends Core_Class_A
.
I need to rewrite both of them and add a common functionality.
So I made this:
Custom_Class_A extends Core_Class_A
.
The question is which one from below should I use (thumbs up and thumbs down for each):
Custom_Class_B extends Custom_Class_A
Custom_Class_B extends Core_Class_B
[Full Version]
I'm working on an extension that adds a new filter in the layered navigation: in stock / out of stock (you will see it public in a few days).
The code, no big issue so far, the strategy...I have my doubts.
Because there are no events I can use in the layered navigation section to add my new filter, I had to rewrite 2 blocks: Mage_Catalog_Block_Layer_View
and Mage_CatalogSearch_Block_Layer
. (If someone has better ideas, please share, but this is not in the scope of the question).
For the Mage_Catalog_Block_Layer_View
I did it like Vinai thought me indirectly (see this review about one of Vinai's extensions).
I added the methods I wanted to rewrite, just called parent::methodName()
and dispatched an event that everyone can observe.
Here is an example for the method _initBlocks
. My new method looks like this:
protected function _initBlocks()
{
parent::_initBlocks(); //call the parent method
//dispatch an event that I can observe and add my logic.
Mage::dispatchEvent('catalog_layer_view_init_blocks', array('block' => $this));
}
But the problem comes for Mage_CatalogSearch_Block_Layer
. This block extends the first one Mage_Catalog_Block_Layer_View
.
For example I need to rewrite the method _initBlocks
as shown above. But the problem is that Mage_CatalogSearch_Block_Layer
does not have its own _initBlocks
method. it uses the one from the parent class Mage_Catalog_Block_Layer_View
.
What do I do here?
Should I use the same system as above or should I just make my new class [Namespace]_[Module]_Block_Catalogsearch_Layer
extend my own class I created for rewriting Mage_Catalog_Block_Layer_View
and just copy the different methods from Mage_CatalogSearch_Block_Layer
?.