Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento product list with custom productCollection

Tags:

php

magento

For my module I need to create a custom productCollection built with various addAttributeToFilter modifiers. However, I have no idea how to get such a collection into a product list like the default magento one. So basicly I'd like to create a pre-filtered product list, could anyone give me some advice on how to start such a thing?

EDIT: Just to clarify, I can make the collection, just not show it like the default product list.

like image 382
Ossie7 Avatar asked Jan 29 '26 01:01

Ossie7


2 Answers

After hours of struggling I found a solution: I overrided Mage_Catalog_Block_Product_List and made my own _getProductCollection with:

$collection = parent::_getProductCollection();
$collection->addAttributeToFilter('attribute', array('operator' => 'value'));
/* more filters go here */
$this->_productCollection = $collection;
return $this->_productCollection;

This seemed to be the only way to get the original product list working without any errors or category problems.

With thanks to Guerra!!

like image 109
Ossie7 Avatar answered Jan 30 '26 15:01

Ossie7


use this in list.phtml:

$_productCollection->clear()
        ->addAttributeToFilter('attribute_set_id', array('eq' => 63))
        ->load();
like image 41
Waqas Ali Khan Puar Avatar answered Jan 30 '26 16:01

Waqas Ali Khan Puar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!