简体   繁体   English

Magento滤波器厂家按类别

[英]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.我如何在 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.我正在使用 Magento 社区 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.第二步是数学制造商将 id-s 属性分配给他们的名字。 And here you can use two approaches and either join the label to collection or map them from another collection of all manufacturer names.在这里,您可以使用两种方法,或者将 label 加入到集合中,或者将 map 从所有制造商名称的另一个集合中加入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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