简体   繁体   中英

Magento filter manufacturers by category

So I have a category called "backpacks" and I want to get all the manufacturers of backpacks. How do I accomplish this in Magento. Is this possible? The following code will get all manufacturers but how to I filter it down further. I am using Magento community 1.3.

$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
              ->setEntityTypeFilter($product->getResource()->getTypeId())
             ->addFieldToFilter('attribute_code', 'manufacturer');

$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);               

print_r($manufacturers);

Any advice would greatly help. I have search and search on Google. But I can't seem to find a way to filter attributes by category. Because I believe that is what I am trying to do.

First you need to get all your products in category with manufacturer attribute attached to it

Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('manufacturer')->addAttributeToFilter('category_id', '3')

and second step is to math manufacturer attribute id-s to their names. And here you can use two approaches and either join the label to collection or map them from another collection of all manufacturer names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM