3

I'm trying to rewrite the Magento Catalog Product Collection - basically I have a specific filtering rule that must be applied every time a product collection is loaded, so I'm figuring that putting it into the collection directly is the best way of doing it.

However, I've never really played with this before, and I've not been able to get it working so far.

The relevant part of my config.xml is

  <global>
        <models>
            <catalog>
                <rewrite>
                    <resource_product_collection>Lw_Restrict_Model_Resource_Product_Collection</resource_product_collection>
                </rewrite>
            </catalog> 

And for testing, my app/code/local/Lw/Restrict/Model/Resource/Product/Collection.php just contains:

 <?php
 die("??");
 class Lw_Restrict_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection {

     protected function _beforeLoad() {
         echo "Load!!";
         parent::_beforeLoad();
     }

 }

So if I go to a category page for example, I'd actually expect the page to die, which it isn't!

Could someone point out whatever obvious thing I've obviously missed is please!!

Thanks!

6

After doing some extra reading, I figured out the XML should look like this:

            <catalog_resource>
                <rewrite>
                    <product_collection>Lw_Restrict_Model_Resource_Product_Collection</product_collection>
                </rewrite>
            </catalog_resource> 
  • 2
    Yep was just about to put that, but better than using a rewrite would be to use an observer on collection load i.e. catalog_product_collection_load_before. – Jonathan Hussey May 19 '15 at 0:53
2

Your issue at wrong calling for resource type at config.xml

it should be catalog_resource from catalog.

As per as ,magento catalog_resource resource type class is Mage_Catalog_Model_Resource

See at config.xml of Mage_Catalog Module:

 <catalog_resource>
                <class>Mage_Catalog_Model_Resource</class>

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.