I looked around, and i found something similar but still can solved my problem. So i decided to ask here. sorry if there is a duplicate question already asked.

I want to override the getProductCollection() in Layer.php in magento, but here is my problem.

below is the original code with my own code:

public function getProductCollection()

    if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {

        $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];

    } else {

        //Original collection code
        //$collection = $this->getCurrentCategory()->getProductCollection();

        /* I want to do the below code*/
        $collection = Mage::getModel('catalog/product')->getCollection();
        $collection->addFieldToFilter('customYesNoAttribute', 1);
        /*custom code ends*/

        $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

    return $collection;  

what this code does is that it will get all products for every category, then filter the products for a attribute carry with the Category.

For example:

Category: Cup
Custom Category Attribute: isCup

Product: Coffee Cup
Custom Attribute: isCup->Yes

Product: T-Shirt
Custom Attribute: isCup->No

when i open the "Cup" category, the above code gets the isCup attribute from the category, and filter all products with isCup=Yes, and show on the category.

The main reason why i want to do this is I don't want to manually add products to category because my client has over 5k products. It will be a nightmare to maintain them.

But my problem with the above code is now a blank white page with nothing. Any help will be greatly appreciated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.