Magento:从数据库中获取制造商/品牌

kar*_*rto 1 magento

我有来自Mukesh Chapagain的代码:链接到这里

$_product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();
Run Code Online (Sandbox Code Playgroud)

这似乎并没有让制造商接受,即使我把它们作为属性.是因为制造商领域是下拉列表吗?

任何获得制造商属性的帮助将不胜感激

Gow*_*wri 7

检索所有制造商

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

foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
     $attributeArray[$option['value']] = $option['label'];
     }  

foreach($attributeArray as $key=>$val){
echo $val;

}
Run Code Online (Sandbox Code Playgroud)

从制造商处获取产品

    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('manufacturer');
    $collection->addFieldToFilter(array(
        array('attribute' => 'manufacturer', 'eq' =>$designer_id),
    ));
Run Code Online (Sandbox Code Playgroud)

选择制造商的产品

 $_productCollection=$this->getLoadedProductCollection();
 foreach ($_productCollection as $_product):
  echo $_product->getAttributeText('manufacturer');
 endforeach;
Run Code Online (Sandbox Code Playgroud)