Friday, January 16, 2015

Magento -Magento how to get configurable product attributes option

<?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
                }
            }?>

No comments:

Post a Comment