1

I have ThirdPary_Extension that rewrites a resource class method of Mage_Catalog_Model_Resource_Product_Indexer_Price. However, ThirdPary_Extension goes about doing this a little strange. It's configured to rewrite only Mage_Catalog_Model_Product_Indexer_Price, but in this class' _construct(), it's pointing to a resource class that extends off of Mage_Catalog_Model_Resource_Product_Indexer_Price.

Let me illustrate.

config.xml

...
<models>
     <catalog>
        <rewrite>
            <product_indexer_price>ThirdParty_Extension_Model_Product_Indexer_Price</product_indexer_price>
        </rewrite>
    </catalog>
</models>
...

ThirdParty_Extension_Model_Product_Indexer_Price

class ThirdParty_Extension_Model_Product_Indexer_Price extends Mage_Catalog_Model_Product_Indexer_Price
{
    protected function _construct()
    {
        $this->_init('thirdparty/resource_product_indexer_price');
    }
    ...       
}

ThirdParty_Extension_Model_Resource_Product_Indexer_Price

class ThirdParty_Extension_Model_Resource_Product_Indexer_Price extends Mage_Catalog_Model_Resource_Product_Indexer_Price
{
    protected function _rewrittenMethod()
    {
        // Good stuff
    }
    ...       
}

And in Mage_Catalog_Model_Product_Indexer_Price::reindexAll, you have $this->_getResource()->reindexAll(), which invokes the rewritten method as was intended.

However, this causes some issues. Depending on how you're instantiating the resource model and invoke a method, you may end up with using ThirdParty_Extension_Model_Resource_Product_Indexer_Price (good) or Mage_Catalog_Model_Resource_Product_Indexer_Price (bad), among one or two other things. Obvisouly, the extension works for re-indexing prices, but I'm not a fan of how it's done. Please correct me if I misunderstand this extension.

Now the question, how do I rewrite Mage_Catalog_Model_Resource_Product_Indexer_Price the right (lol!) way?

  1. Rewrite both Mage_Catalog_Model_Product_Indexer_Price and Mage_Catalog_Model_Resource_Product_Indexer_Price to re-align everything nicely? Or..

  2. Rewrite just ThirdParty_Extension_Model_Resource_Product_Indexer_Price

Option #1 would typically be my pick, but I'm thinking maybe there was a reason this rewrite was done in such a way, in which case #2 would be the way to go. What say ye?

1

You can also rewrite resource models.

    <models>
        <catalog_resource>
            <rewrite>
                <product_indexer_price>ThirdParty_Extension_Model_Resource_Product_Indexer_Price</product_indexer_price>
            </rewrite>
        </catalog_resource>

Way to go

I'm always looking to do as less rewrites as possible. So:

  • is there a event fired I can use, use it!
  • how can I rewrite with as less impact as possible to avoid module conflicts or problems in future upgrades!

So, I would only rewrite the resource, because that's the less impact I can do.

  • Yeah, that's what my option #1 would do. I'm just not sure why one would rewrite a resource model method that way. Any idea? – musicliftsme Mar 19 '15 at 14:23
  • This is what only option #2 would do I think, because no rewrite on the model is done, only on the resource – Jeroen Mar 19 '15 at 14:26
  • I'm sorry, you're right. I got slightly confused when you said "You can also rewrite..." because it was already mentioned (implied) in the post. Any idea though on my original question? I took approach #1 BTW. – musicliftsme Mar 19 '15 at 14:28
  • I'll add some to my answer – Jeroen Mar 19 '15 at 14:34

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.