Reputation: 370
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.
Upvotes: 3
Views: 5371
Reputation: 1327
use this in list.phtml:
$_productCollection->clear()
->addAttributeToFilter('attribute_set_id', array('eq' => 63))
->load();
Upvotes: 2
Reputation: 370
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!!
Upvotes: 2
Reputation: 2790
You can try :
Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter();
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento
Upvotes: 1