在Magento中获取productid的活动属性

时间:2013-04-27 12:54:59

标签: php magento magento-1.7

我想获取有效产品的所有属性,但我总是获得所有属性。这是我的代码:

    $product= Mage::getModel('catalog/product')->load($productid);
    $attribute= $product->getResource()->getAttribute("color"); 
    $optionscolor = $attribute->getSource()->getAllOptions(false);

    foreach ($optionscolor as $option) {    
         echo "<option value='".  $option['value']."'>".  $option['label']."</option>";  
    }       

对于这个产品,我有4种颜色(黑色,红色,蓝色和黄色)。但是这段代码给了我所有12种颜色......为什么?

1 个答案:

答案 0 :(得分:0)

您必须使用前端模型,而不是此属性的源模型。

试试这个:

$optionscolor = $attribute->getFrontend()->getValue($product);