我有来自Mukesh Chapagain的代码:link here
$_product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();
即使我将它们作为属性,这似乎也不会吸引制造商。这是因为制造商字段是下拉列表吗?
获得制造商属性的任何帮助将不胜感激
答案 0 :(得分: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;
}
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('manufacturer');
$collection->addFieldToFilter(array(
array('attribute' => 'manufacturer', 'eq' =>$designer_id),
));
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product):
echo $_product->getAttributeText('manufacturer');
endforeach;
答案 1 :(得分:0)
老实说,我不知道有问题的代码有什么问题。
但是,我最近一直致力于相关的事情 - 如果你正在尝试使用一系列产品。而不是试图修复可能没有破坏的东西,而不是将其视为另一种建议。
首先,您需要下载我的library of query patterns。它包含一个下拉属性类。以下内容为集合添加了manufacturer_text
列。
$products = Mage::getResourceModel('catalog/product_collection');
Knectar_Select_Product_Values::enhanceProducts($products, 'manufacturer');
foreach ($products as $product) {
echo $product->getManufacturerText(), '<br>';
}