I’ve got such a problem with Magento CMS. I need to retrieve all manufacturers for category.
At first glance this is not a problem, because there are a Filter block and Layer navigation from which you can take the necessary methods.
First of all I create a public method in redefined category model /app/code/local/Mage/ Catalog/Model/Category.php
public function getManufacturers()
{
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
->setItemObjectClass('catalog/resource_eav_attribute');
$setIds = $this->getProductCollection()->getSetIds();
$collection->getSelect()->distinct(true);
$collection
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection->addIsFilterableFilter();;
$collection->load();
return $collection;
}
I call this method in category template:
$manufscturers = $_category->getManufacturers();
So we get a huge object Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection.
Then:
$items = $manufscturers->getItems();
And we get object Mage_Catalog_Model_Resource_Eav_Attribute.
Then I do not know what to do. That is a dead end. Maybe it’s the wrong way?
The version of Magento – 1.4.0.1
Thank’s for your help!
Here is how you should get all manufacturers for a category:
Hope this was useful.
Cheers!