'Disable choose an option in configurable products of Magento

I want to disable choose an option in configurable products drop-down.Rather it should automatically select a default product. Where and what to edit?



Solution 1:[1]

You can have those changes in the following file.

app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/product/view/type/options/configurable.phtml

And Better work with "Template Path Hints" Enabled from the backend. You will know what and where you need to customize.

UPDATE:

Open this file:

/app/design/frontend/default/your_theme/template/catalog/product/view/type/options/configurable.phtml

Right below

var spConfig = new Product.Config(< ?php echo $this->getJsonConfig() ?>);

add this JavaScript code:

//we create new function
spConfig.setInitialState = function(dropdown_id)
{
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection
dropdown[0].remove();
//change selections in dropdowns
for(index = 0; index < dropdown.length; index++)
{
if(dropdown[index].value != "")
{
dropdown.selectedIndex = index;
var element = dropdown;
var event = 'change';
//fire events
if(document.createEventObject)
{
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else
{
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true );
return !element.dispatchEvent(evt);
}
}
}
};
<?php foreach($_attributes as $_attribute): ?>
spConfig.setInitialState("attribute< ?php echo $_attribute->getAttributeId() ?>")
<?php endforeach; ?>

For more information See Here and more Here

Full Working file

/app/design/frontend/default/your_theme/template/catalog/product/view/type/options/configurable.phtml

<?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 name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
                    <option><?php echo $this->__('Choose an Option...') ?></option>
                  </select>
              </div>
        </dd>
    <?php endforeach; ?>
    </dl>
    <script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
      //we create new function
        spConfig.setInitialState = function(dropdown_id)
        {
        //select dropdown
        var dropdown = $(dropdown_id);
        //remove empty option from dropdown so it is not selectable after initial selection
        dropdown[0].remove();
        //change selections in dropdowns
        for(index = 0; index < dropdown.length; index++)
        {
        if(dropdown[index].value != "")
        {
        dropdown.selectedIndex = index;
        var element = dropdown;
        var event = 'change';
        //fire events
        if(document.createEventObject)
        {
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
        }
        else
        {
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true );
        return !element.dispatchEvent(evt);
        }
        }
        }
        };
        <?php foreach($_attributes as $_attribute): ?>
        spConfig.setInitialState("attribute<?php echo $_attribute->getAttributeId() ?>")
        <?php endforeach; ?>
    </script>
<?php endif;?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1