Magento how to get configurable product attributes option in view page in custom module


A more challenging task is to get the options and values that are applicable to a particular configurable product. This can solved using the following code:

Open app/design/frontend/yourpackage/yourtheme/template/catalog/product/view.phtml

and copy and paste this code

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

11 comments:

  1. Hi,

    Can I get product option list data on header.phtml file or any other file, where I wanted. Becuase since few days I am struggliing with that, aprart fom options_lists.ptml I am not able to get those data, please suggest.

    any help wld b greatly appreciated.

    ReplyDelete
    Replies
    1. Hi Vivek,

      Please read this http://magebug.blogspot.in/2016/03/magento-techniques-to-show-configurable.html

      Delete
  2. Hi,
    Thanks for post but i want to show options on custom popup window, and after select first option accordingly second appear (like product page), then need to add cart with selected option from there. Please suggest for the same.

    Regards,
    Saurabh

    ReplyDelete
    Replies
    1. Hi Saurabh,

      Read this http://magebug.blogspot.in/2016/03/magento-techniques-to-show-configurable.html

      Delete
  3. hi how to change price for the option selected

    thanks

    ReplyDelete
    Replies
    1. Hi Vellai Durai,

      Read this http://magebug.blogspot.in/2016/03/magento-techniques-to-show-configurable.html

      Delete
  4. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    magento development company in bangalore 

    ReplyDelete
  5. Magento 2 Configurable Product Wholesale Display supports showing all associated products in a grid table view which allows wholesale customers to order and add all chosen items to cart at once.
    Check it here: https://bsscommerce.com/configurable-product-wholesale-display-for-magento-2.html

    ReplyDelete