Php Magento获得一个类别的制造商

Php Magento获得一个类别的制造商,php,magento,Php,Magento,我目前可以获得制造商列表及其首个产品的代码如下: $attribute = Mage::getModel('eav/entity_attribute') ->loadByCode('catalog_product', 'manufacturer'); $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')

我目前可以获得制造商列表及其首个产品的代码如下:

    $attribute = Mage::getModel('eav/entity_attribute')
                    ->loadByCode('catalog_product', 'manufacturer');

    $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setAttributeFilter($attribute->getData('attribute_id'))
                ->setStoreFilter(0, false);

    $preparedManufacturers = array();            
    foreach($valuesCollection as $value) {
        $preparedManufacturers[$value->getOptionId()] = $value->getValue();
    }   

    $prefs = array();        

    if (count($preparedManufacturers)) {
        foreach ($preparedManufacturers as $optionId => $value) {
            $manufacturerItem = array();
            $manufacturerItem['manufacturerID'] = $optionId;
            $manufacturerItem['manufacturerName'] = $value; 

            $firstProductId=Mage::getModel('catalog/product')->getCollection()
                ->addStoreFilter(0)
                ->addAttributeToFilter('manufacturer',$optionId)->getFirstItem()->getId();              

            $product = Mage::getModel('catalog/product')->load($firstProductId);
            $manufacturerItem['productImageURL'] = (string)Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(100);;
            $prefs['manufacturer'][] = $manufacturerItem;
        }

        $mainBlock = $this->getLayout()->createBlock(
                                       'Mage_Core_Block_Template',
                                       'mainContentProducts',
                     array(
                         'template' => 'page/manufacturer.phtml'
                     )
            ) // NOTE - Custom Variables Below
            ->setData('prefs', $prefs);

        $this->getLayout()->getBlock('content')->append($mainBlock);            
    } 

如果我有一个类别ID,a如何获得制造商及其首个产品的列表?

我相信这可以满足您的需求

$category = Mage::getModel('catalog/category')->load(**Id Goes Here**);

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addCategoryFilter($category)
    ->addAttributeToSelect('manufacturer')
    ->addAttributeToSort('entity_id','ASC')
    ->groupByAttribute('manufacturer');
然后,您可以循环整个集合,它将为每个制造商提供第一个产品