Friday, May 3, 2013

Magento : Change options of configurable product to radio button

Magento : Change options of configurable product to radio button

Replace the configurable.phtml code with below code:
<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
    <dl>
    <?php foreach($_attributes as $_attribute): ?>
        <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
        <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
            <div class="input-box">
                <select style="display:none;" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
                   
                  </select>
              </div>
        </dd>
    <?php endforeach; ?>
    </dl>
    <script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
    </script>
<?php endif;?>
<div id="r"></div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#attribute<?php echo $_attribute->getAttributeId() ?> option").each(function(i, e) {
    if(jQuery(this).val() == '')
    {}
    else
    {
    jQuery("<input type='radio' name='r' />")
        .attr("value", jQuery(this).val())
        .attr("checked", i == 0)
        .click(function () {
            jQuery("#attribute<?php echo $_attribute->getAttributeId() ?>").val(jQuery(this).val());
        })
        .appendTo("#r");
        jQuery("<span >&nbsp;&nbsp;&nbsp;"+jQuery(this).html()+"&nbsp;&nbsp;&nbsp;</span>")
        .appendTo("#r");
    }
       
});
});


</script>

19 comments:

  1. Hi Afroz ,

    Nice post ,Thanks for sharing ,looking forward for more posts .



    Magento Developers

    ReplyDelete
  2. Hey thanks for sharing this. I tried this but I had some issues while implementing this. Anyways finally it was resolved.

    ReplyDelete
  3. Hi,

    I am a Magento developer and I am struggling to resolve a particular bug for my client.
    when the product is out of stock, is there a way to clear all customers shopping cart of this product, instead of disabling the product?
    My product is Magento out of stock

    Can you please explain how?

    ReplyDelete
    Replies
    1. You can do this making a module or cron job.
      Get all the shopping cart items from quote object.
      Check if out of stock, remove them from quote object.

      Thanks

      Delete
    2. Thanks Afroz..

      I've cleared the bug. Got an idea when I got in "quote object:

      Thanks a lot

      Delete
  4. Hi,

    Sorry my question is not related to this. I have been trying to write a custom api in magento just to display hello world and i have been having resource path not callable and I try to debug but the same result.

    Can you pls help post a tutorial on creating magento custom api. Just to display a simple string will be ok.

    Thanks.

    ReplyDelete
  5. Replies
    1. Hi Andrej, Please don't compare anyone with God. There is none other than God. God is one and only one.

      Delete
  6. Worked like a charm. Thank you.

    ReplyDelete
  7. Hi ...

    I used your code ..Iam new in magento let me know hw I view the code in hellowires theme...

    Need to edit view.phtml?

    ReplyDelete
    Replies
    1. I got it... But Price doesn't change when i select option

      Delete
  8. This code works in magento 1.8? i find several configurable.phtml files, can you tell me where is located?

    thanks

    ReplyDelete
  9. This is Great Code.. working Good Thank you. for sharing.

    ReplyDelete
  10. how to get id of selected custom radio button in magento
    and how to keep radio button checked by default on a specific radio button
    plz help me.....

    ReplyDelete
  11. how to get id of selected custom radio button in magento
    and how to keep radio button checked by default on a specific radio button
    plz help me.....

    ReplyDelete
  12. Extremely rattling Article. The substance stream and elegance of forming is astounding. i buy the focal purposes and smart conditions of Magento in a very purpose by point path during this article among others I browse a comparative subject.
    Outsource ecommerce website development services
    Affordable ecommerce development services

    ReplyDelete
  13. Nice post ,Thanks for sharing ,looking forward for more posts .

    ReplyDelete