1

I created a configurable product and I set the dropdown as a selection method. How can I change it in radio buttons? it's possible? I saw some guides on Magento 1.9 where they set the radio buttons instead of the drop-down selection

My Magento version is 2.2.

Thanks in advanced!

enter image description here

2 Answers 2

2

The input type of any attribute that is used for a product variation must be one of the following:

  1. Dropdown
  2. Visual Swatch
  3. Text Swatch

So radio button is not supported for configurable product attribute.

Reference: https://docs.magento.com/m2/ce/user_guide/catalog/product-create-configurable.html

2
  • Thanks for your reply! ibb.co/dDvLsq I talk about this method Nov 6, 2018 at 8:50
  • @KernelPanic Yes. But that is not supported in configurable product. Nov 6, 2018 at 8:51
0

/var/www/html/magento2/vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml

getProduct(); $_attributes = $block->decorateArray($block->getAllowAttributes()); ?> isSaleable() && count($_attributes)) :?>
<?php foreach ($_attributes as $_attribute) : ?>
    <div class="field configurable required">
        <label class="label" for="attribute<?= $block->escapeHtmlAttr($_attribute->getAttributeId()) ?>">
            <span><?= $block->escapeHtml($_attribute->getProductAttribute()->getStoreLabel()) ?></span>
        </label>
        <?php
        $attributeId=$_attribute->getAttributeId();
        ?>
        <div class="control" id="data_radio">
    </div>
<?php endforeach; ?>
        <script type="text/javascript">

            require(
                [
                    'jquery',
                    'Magento_Ui/js/modal/modal'
                ],
                function($, modal){
            var html = "";
            var attributesId = "<?php echo $attributeId ?>";
            var result = <?= /* @noEscape */ $block->getJsonConfig() ?>;
                    var repsone=result['attributes'][attributesId]['options'];
                    var optionPrices = result['optionPrices'];
                    $.each( repsone, function( key, value ) {
                        var product_prices = value.products[0];
                        var final_price = optionPrices[product_prices].finalPrice.amount;
                        html+= '<input type="radio" name="super_attribute[<?= $block->escapeHtmlAttr($_attribute->getAttributeId()) ?>]" id="html" name="fav_language" value="'+value.id+'">';
                        html+= '<label for="html">';
                        html+= value.label+"-"+final_price;
                        html+='<label>';
                    });

                    $("#data_radio").append(html);
            });
        </script>
<script type="text/x-magento-init">

    {
        "#product_addtocart_form": {
            "configurable": {
                "spConfig": <?= /* @noEscape */ $block->getJsonConfig() ?>,
                "gallerySwitchStrategy": "<?= $block->escapeJs($block->getVar(
                    'gallery_switch_strategy',
                    'Magento_ConfigurableProduct'
                ) ?: 'replace'); ?>"
            }
        },
        "*" : {
            "Magento_ConfigurableProduct/js/catalog-add-to-cart": {}
        }
    }
</script>

enter image description here

1
  • This seems to work fairly well but any chance you'd know how to update price-box.js to account for the price getting updated when a radio is selected? Apr 28, 2022 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.