Magento:如何按类别筛选Mage::getResourceModel(';eav/entity_attribute#u collection';)的结果

Magento:如何按类别筛选Mage::getResourceModel(';eav/entity_attribute#u collection';)的结果,magento,attributes,categories,Magento,Attributes,Categories,我使用了下面的代码来获取制造商的完整列表 $currentCategory = Mage::registry('current_category'); $product = Mage::getModel('catalog/product'); $attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($product->

我使用了下面的代码来获取制造商的完整列表

    $currentCategory = Mage::registry('current_category');
    $product = Mage::getModel('catalog/product');       
    $attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($product->getResource()->getTypeId())->addFieldToFilter('attribute_code', 'brand_name');      
    $attribute = $attributes->getFirstItem()->setEntity($product->getResource());       
    $manufacturers = $attribute->getSource()->getAllOptions(false);      
现在,如何获得属于特定类别的制造商列表?我已经挖掘了一段时间,想找出一种方法来限制分类结果,但没有运气。 ResourceModel是否可以按类别进行筛选


谢谢。

我认为您最好从该类别的产品集合开始,然后获得与这些产品匹配的属性。比如:

$currentCategory = Mage::registry('current_category');
$products = $currentCategory->getProductCollection();
foreach($products as $product):
  $product = Mage::getModel('catalog/product')->load($product->getId());
  $manufacturers[] = $product->getBrandName();      
endforeach;
您需要对阵列进行重复数据消除,但是
array\u unique()
应该可以帮助您完成这项工作

嗯,, 法学博士

编辑

这将防止需要加载每个产品,从而提高性能:

$currentCategory = Mage::registry('current_category');
$products = $currentCategory->getProductCollection();
$products->addAttributeToSelect('brand_name');
$products->load();  //execute the query
$manufacturers = $products->toArray(array('brand_name'));
请记住,使用缓存时,性能损失只需花费一次


JD

感谢您提供了获取属性选项id的好方法。这真的帮了我很大的忙! 下面是我最后为获取选项id及其文本值所做的操作:

$currentCategory = Mage::registry('current_category');
$products = $currentCategory->getProductCollection();
$products->addAttributeToSelect('brand_name');
$products->load();  //execute the query
$manufacturers = $products->toArray(array('brand_name'));   
$temp = array();
foreach($manufacturers as $v) {
    $temp[] = $v['brand_name'];
}
$brands = implode(",",array_unique($temp));
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$readresult=$write->query("SELECT eav_attribute_option_value.option_id, eav_attribute_option_value.value FROM eav_attribute_option_value INNER JOIN eav_attribute_option ON eav_attribute_option_value.option_id=eav_attribute_option.option_id WHERE eav_attribute_option.attribute_id=505 AND eav_attribute_option_value.option_id IN (".$brands.")");

while ($row = $readresult->fetch() ) {
    $brandlist[] = array('value'=>$row['option_id'], 'label'=>$row['value']);
}
brandlist数组将具有选项id和值,以便我可以使用它来链接


再次感谢

我这样做了,但性能与以前的方法不匹配。还有别的想法吗?谢谢,谢谢!我会尝试一下,让你知道它是如何提高性能的。