获取magento中当前产品的可配置产品属性标签和id


get configurable product attributes labels and id of current product in magento

当I print_r $myArray…显示color属性的所有标签。

我只想显示当前产品使用的那些属性(标签和id)。此外,我的网站正在使用一些自定义主题,我想启用默认的可配置选项与产品一起显示。

<?php 
 $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
 foreach ($attribute->getSource()->getAllOptions(true, true) as $instance) 
 {
         $myArray[$instance['value']] = $instance['label']; 
 }
 print_r($myArray);
?>

这段代码可以帮助我也搜索确切的这个,发现它在另一个博客

<?php $cProduct = Mage::getModel('catalog/product')->load($_product->getId());
            //check if product is a configurable type or not
            if ($cProduct->getData('type_id') == "configurable")
            {
                //get the configurable data from the product
                $config = $cProduct->getTypeInstance(true);
                //loop through the attributes
                foreach($config->getConfigurableAttributesAsArray($cProduct) as $attributes)
                {
                    ?>
                    <dl>
                        <dt><label class="required"><em>*</em><?php echo $attributes["label"]; ?></label></dt>
                        <dd>
                            <div class="input-box">
                                <select name="super_attribute[<?php echo $attributes['attribute_id'] ?>]" id="attribute<?php echo $attributes['attribute_id'] ?>">
                                    <?php
                                    foreach($attributes["values"] as $values)
                                    {
                                        echo "<option>".$values["label"]."</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </dd>
                    </dl>
                    <?php
                }
            }?>