Configurable product modification in Magento

Configurable product modification in Magento

In this article, I’ll give you extension that will change drop down selection (select field) to radio buttons on configurable products in Magento Community edition.

Well, what I had to do is rewrite Mage_Catalog_Block_Product_View_Type_Configurable block, and create a custom phtml file (configurable.phtml) with some custom validation on it.

Everything I just told you equals to this config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Inchoo_Configurable>
            <version>0.1.1</version>
        </Inchoo_Configurable>
    </modules>
    <global>
        <models>
            <configurable>
                <class>Inchoo_Configurable_Model</class>
            </configurable>
        </models>
        <blocks>
            <configurable>
                <class>Inchoo_Configurable_Block</class>
            </configurable>
            <catalog>
                <rewrite>
                    <product_view_type_configurable>Inchoo_Configurable_Block_Frontend_Configurable</product_view_type_configurable>
                </rewrite>
            </catalog>
        </blocks>
    </global>
    <frontend>
        <layout>
            <updates>
                <configurable module="Inchoo_Configurable">
                    <file>configurable.xml</file>
                </configurable>
            </updates>
        </layout>
    </frontend>
</config>

And block rewrite consisted of addition of new method “getRegularConfig” that corresponds to “getJsonConfig”, except it doesn’t return Json encoded data.

And custom template packed in attached zip file is located under “test” theme folder. For installation you need to extract both layout (configurable.xml) and phtml (configurable.phtml) files.
Notice: keep folder structure for phtml file in your theme

And finally, on modern theme it changes configurable product view from this:

To this:

And finally, you can download it here.

Cheers!

You made it all the way down here so you must have enjoyed this post! You may also like:

Programmatically create a configurable Magento product Petar Sambolek
Petar Sambolek, | 20

Programmatically create a configurable Magento product

Magento Shopping Cart Promotion Rule for Product with Custom Options Branko Ajzele
Branko Ajzele, | 34

Magento Shopping Cart Promotion Rule for Product with Custom Options

How to add Currency selector to Magento’s header Zvonimir Buric
Zvonimir Buric, | 60

How to add Currency selector to Magento’s header

138 comments

  1. I installed this and it’s working, but how do I integrate this into an existing theme?

    I don’t think I need a detailed guide, but general overview would be good enough to get me started.

    Can anyone help?

  2. Shaz, Wouter, murg and me have one problem:

    with my install, it shows me all the options of all attributes in each attributes ?
    For example:
    Color : Red, Blue , S, M, XL (which are size)
    Size: Red, Blue, S, M, XL

    i am using 1.7.2

    doe anybody know how to fix it????

  3. hey.. Thanks.. Is there any option so that some of the
    attribute display as Radio and depending on its selection .. other
    attributes display as dropdown..? as in Attribute 1 display as
    Radio Button and Attribute 2,3 display as dropdown.. ? PLEASE
    HELP!!

  4. Hello,

    the extension looks like it is the perfect solution for me. But I have the same problem like Jason: After Installation I couldn’t see the radiobuttons. (Just an empty box).

    I think my installations doesn’t find the configurable.phtml Any more hints where to place it in a customized theme? I am using magento 1.7. Thanks in advance.

  5. It is good to try when having only one configurable option and no price difference for related simple products. However, found similar problems for more than one configurable options (ie: size, color). Hope someone could share the solution.

  6. This extension is not working the special price.

    Can someone tell how it will work with special prices.

    I mean if any products have special price so how that would work ?

  7. Are there any fixes for Internet Explorer? Unfortunately it looks like people who are still using IE cannot add the product to the cart and are receiving the following error when doing so.. “Please specify the product’s options(s).”

  8. I faced couple of problems with this extension.
    1. All options of color and size are displayed for both.
    2. When I select color first and size options doesn;t change with respect to color selection
    3. Price also doesn’t change

  9. sorry for being lame, but new to magento. Doing development from a previous owner’s half-effort.
    Magento ver. 1.4.1.1 – modern theme
    Same issue, turning dropdown to radio. Downloaded your extension but can’t figure out where to put the files from this post and comments…. thanks much

  10. Hello

    If there is some additional price for options and when I click on radio button the price of products in related block in left side bar also changes.

    If any one fixed this bug please share.

    Thanks in advance.

  11. i have the same problem than Shaz:

    Shaz
    16-03-2012 at 15:21 | #

    with my install, it shows me all the options of all attributes in each attributes ?
    For example:
    Color : Red, Blue , S, M, XL (which are size)
    Size: Red, Blue, S, M, XL

    i am using 1.7.2

    how can i solve this ?

  12. Hi again.
    The problem is following (JS):
    ….
    el.observe(‘click’,function(event){
    //console.log(el.parentNode);
    $$(‘span .price’).each(function(elmn){
    …..
    I mean ‘span .price’ gets updated and since all prices are displayed between
    [code]<span class="price"></span>[/code], all prices get updated…

    Maybe it’s not the best, but it is solution:
    remove [code]<span class="price"></span>[/code] from prices of related products:

    Go to price.phtml, find the line where your price gets displayed (mine:line 199) and replace:

    [code]<span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
    <?php if ($_finalPrice == $_price): ?>
    <?php $suffix=$this->getIdSuffix();
    <?php if ($suffix==’-related’):?>
    <?php $myprice=$_coreHelper->currency($_price, true, true);
    $myprice=str_replace(‘<span class="price">’, ”, $myprice);
    $myprice = str_replace(‘</span>’, ”, $myprice);
    echo $myprice; ?>
    <?php else: ?>
    <?php echo $_coreHelper->currency($_price, true, true) ?>
    <?php endif; ?>
    <?php else: ?>
    <?php echo $_coreHelper->currency($_finalPrice, true, true) ?>
    <?php endif; ?>
    </span>[/code]

    Who knows, maybe this sux, im tired to check all, but anyways i decided to share this with you, maybe it helps at the end… hf gg James!

    P.S. Sry for double post…(tired, missed [code][/code] )

  13. Hi again.
    The problem is following (JS):
    ….
    el.observe(‘click’,function(event){
    //console.log(el.parentNode);
    $$(‘span .price’).each(function(elmn){
    …..
    I mean ‘span .price’ gets updated and since all prices are displayed between
    , all prices get updated…

    Maybe it’s not the best, but it is solution:
    remove from prices of related products:

    Go to price.phtml, find the line where your price gets displayed (mine:line 199) and replace:

    <span class="regular-price" id="product-price-getIdSuffix() ?>”>

    getIdSuffix();

    currency($_price, true, true);
    $myprice=str_replace(”, ”, $myprice);
    $myprice = str_replace(”, ”, $myprice);
    echo $myprice; ?>

    currency($_price, true, true) ?>

    currency($_finalPrice, true, true) ?>

    Who knows, maybe this sux, im tired to check all, but anyways i decided to share this with you, maybe it helps at the end… hf gg James!

  14. Hi, I have the same problem as James Bond, hrhrhr.
    Related products prices change as i klick radio buttons…..
    I hope some of you out there got some idea. Thank you very much for sharing this code guyz. <3

  15. Just one last try as I know there are lots of Guru’s here – can anyone throw me a bone in regards to my questions above about the fact that all related products instantly changing to the price that is selected? What hook / javascript function gets run when you click the radio button and why does it change all the related product prices? Maybe I can hack out the class ID of the related product listings or something? I mean, it’s very trippy watching half a dozen related products all change at the same time when you click, kind of like being at the airport back int the day… but I really need to fix it… TIA for any help anyone can offer / functions to look into / phtml files to explore…

  16. My problem, I have an option size and color (double options for the product configurable). the problem is i can add to cart my product because the color depend in size, Thanks

  17. <?php
    $_product = $this->getProduct();
    $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
    ?>
    <?php if($_product->isSaleable() && count($_attributes)) : ?>
    <div class="product-configuration-radio">
    	<ul>
    	    <?php foreach($_attributes as $_attribute) : ?>
    	        <label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label>
    	            <div class="input-box">
    					<?php $configs = $this->getRegularConfig() ?>
    					<?php foreach($configs['attributes'] as $config) : ?>
    						<?php foreach($config['options'] as $value) : ?>
    	                        <li><label class="label-radio-configurable" id="<?php echo (float)$value['price'] + (float) $_product->getPrice();?>"><?php echo $value['label']?> (+ $<?php printf("%.2f", $value['price'])?>)</label>
    							<input type="radio" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="validate-custom-configurable" value="<?php echo $value['id']?>"></li>
    						<?php endforeach; ?>
    					<?php endforeach; ?>
    	              </div>
    	    <?php endforeach; ?>
    	</ul>
    </div>
    <?php endif; ?>
    
        <script type="text/javascript">
            var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
    		document.observe("dom:loaded", function() {
    			var customValidation = false;
    			var priceFormat = <?php echo $this->helper('tax')->getPriceFormat(); ?>;
    			$$('.validate-custom-configurable').each(function(el){
    				el.observe('click',function(event){
    					//console.log(el.parentNode);
    					$$('span .price').each(function(elmn){
    						elmn.update(formatCurrency(parseFloat(el.parentNode.id), priceFormat)).innerHTML;
    					});
    				});
    			});
    			Validation.addAllThese([
    				['validate-custom-configurable', 'This is a required field.', function(v) {
    					$$('.validate-custom-configurable').each(function(el){
    						if (el.checked) {
    							customValidation = true;
    						}
    					});
    					return customValidation;
    				}]
    			]);
    		});
        </script>

    Here is something a little more sound in my opinion. We added a div for some control and made the list an actual list styling reasons. I also removed the random whitespace around the input elements and removed the solidus for HTML 5 (you can add it back if you want).

  18. Finally fixed the issue after hours of looking at the code it was something to do with data.

    I had to re-complie the files. the second I did that it all came in perfectly!

    To re-complie in the Magento back-end head to:

    system > tools > compilation

    hit the run compilation process button.

    job done. hope this helps anyone having the same issue.

  19. Sergio,

    can’t get my head round this one, its not even using the configurable.phtml template file.

    very strange, complete fresh install of magento as well

  20. I fixed the tax included issue by modifing the file configurable.phtml.
    I post the code here:

    <?php
    $_product    = $this->getProduct();
    $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
    
    $_coreHelper = $this->helper('core');
    $_taxHelper = $this->helper('tax');
    
    ?>
    <?php if ($_product->isSaleable() && count($_attributes)):?>
        <dl>
        <?php foreach($_attributes as $_attribute): ?>
            <dt><label class="required"><em><font style="color:red;">* </font></em><?php echo $_attribute->getLabel() ?></label></dt>
    
                <div class="input-box">
    				<?php $configs = $this->getRegularConfig()?>
    				<?php foreach($configs['attributes'] as $config):?>
                            <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
                                <label class="label-radio-configurable" id="<?php echo $_taxHelper->getPrice($_product, $value['price'], true) + $_taxHelper->getPrice($_product, $_product->getFinalPrice(), true);?>">
    					<?php foreach($config['options'] as $value):?>
                        <?php 
    					$_optionPrice_tx = $_taxHelper->getPrice($_product, $value['price'], true); 
    					?>
                                    <input 
                                        type="radio" 
                                        name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]"
                                        id="attribute<?php echo $_attribute->getAttributeId() ?>"
                                        class="validate-custom-configurable"
                                        value="<?php echo $value['id']?>"
                                    />
                                    <?php echo $value['label']?>
    								<?php if ($value['price'] != 0): ?> 
                                    (+ <?php echo Mage::helper('core')->currency($_optionPrice_tx,true,false); ?>) 
    								<?php endif; ?>
    					<?php endforeach;?>
                                </label>
                            </dd>
    				<?php endforeach;?>
                  </div>
    
        <?php endforeach; ?>
        </dl>
    <?php endif;?>
        <script type="text/javascript">
            var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
    		document.observe("dom:loaded", function() {
    			var customValidation = false;
    			var priceFormat = <?php echo $this->helper('tax')->getPriceFormat(); ?>;
    			$$('.validate-custom-configurable').each(function(el){
    				el.observe('click',function(event){
    					//console.log(el.parentNode);
    					$$('span .price').each(function(elmn){
    						elmn.update(formatCurrency(parseFloat(el.parentNode.id), priceFormat)).innerHTML;
    					});
    				});
    			});
    			Validation.addAllThese([
    				['validate-custom-configurable', 'This is a required field.', function(v) {
    					$$('.validate-custom-configurable').each(function(el){
    						if (el.checked) {
    							customValidation = true;
    						}
    					});
    					return customValidation;
    				}]
    			]);
    		});
        </script>

    For Jason:
    [quote]Anyone got this working in 1.7.0.0?

    installed it and the dropdown completely disappears and doesnt render anything. doesn’t even appear to be using the template configurable.phtml when template hints are turned on
    [/quote]

    For me works in 1.7.0.0
    copy files from app/design/default/test (what’s inside test folder) to your theme folder, and you should be fine.

  21. Anyone got this working in 1.7.0.0?

    installed it and the dropdown completely disappears and doesnt render anything. doesn’t even appear to be using the template configurable.phtml when template hints are turned on

  22. Sorry guys, i decided back then that i wouldnt use this mod.
    i remeber that i fixed the problem, but i dont have the code anymore 🙁

  23. the module seems to not display tax included.
    So i got the dufault price with tax included, the option price without adn when i select option it changes the prise display without taxes. Any idea for a solution?

  24. Any help with my problem above would be so very much appreciated! Nobody else is using related products?

  25. Brilliant solution! However, as soon as you click a radio button, every single product in the list of related products in the sidebar have their prices changed to the price of the selected option. This is quite disconcerting 🙂 Any tips for how to stop that?

  26. Works like a charm except for when using special prices, the price on the product page doesn’t change dynamically. Have tried Marek’s suggestion without luck, any other ideas?

  27. I Downloaded your extension and everything seems to be working fine but I am facing some issues on special price. While using special price, price does not gets updated when selecting radio button. Any help would be appreciated.

  28. Hi, thank you for this extension.
    I have a problem ( bug?) with my install, it shows me all the options of all attributes in each attributes ?
    For example:
    Color : Red, Blue , S, M, XL (which are size)
    Size: Red, Blue, S, M, XL

    Anyone had this problem ?
    Can u feedback ?

    thanks

  29. if you are using special price, change $_product->getPrice()
    into
    $_product->getFinalPrice()

    ..in foreach loop

  30. thank ‘s for your help, The problem is if I have double option for example size and color, if size depend in color
    I can’t add some product(after checked some option) in cart because it’s return please choose a option.

    Thank you

  31. Hey, good info. But when you use this extension magiczoomplus you need to implement your code in /template/magiczoomplus/configurable.phtml

  32. My problem, I have an option size and color (double options for the product configurable). the problem is i can add to cart my product because the color depend in size, Thanks

  33. @Zeeshan hope, that you downloaded the extension, that Mr. Lotar has provided. So if you did it, there is a file in the archive: /app/code/local/Inchoo/Configurable/Block/Frontend/Configurable.php This file contains class Inchoo_Configurable_Block_Frontend_Configurable which has public function getRegularConfig()

    Hope, that helps 🙂

  34. I’m unable to understand where function

    getRegularConfig()

    has been defined. I end up with no success. Kindly guide……!!

  35. Hi, thank you for this extension and updates

    but, problems in “double options”, price change(especially if there is a special price) sections, hoping a fix soon..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.