Magento v1.x.x.x

For a cleaner product options section on the Magento product page, take a look at replacing the default ‘– Please Select –‘ first value in each dropdown (select) option with the option title, and then removing the option title above the dropdown:

Magento-Select-Title

First you need to find the two .phtml files located at the paths below:

app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php

and…

app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php

Copy these files to your local code directory and edit as below.

Further reading on the Magento local code folder here


On line 58 of Select.php, you’ll find this IF statement within function ‘public function getValuesHtml()’:

1
2
3
4
if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN) {
     $select->setName('options['.$_option->getid().']')
                    ->addOption('', $this->__('-- Please Select --'));
}

First, we need to get the option title:

1
$getOptionName = ucwords($_option->getTitle());

And replace the ‘– Please Select –‘ value with it. Here’s the final section of code:

1
2
3
4
5
if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN) {
     $getOptionName = ucwords($_option->getTitle());
     $select->setName('options['.$_option->getid().']')
                    ->addOption('', $this->__($getOptionName));
}

Now, the Configurable.php file. We simply amend the ‘chooseText’ by replacing line 256, which is:

1
'chooseText'        => Mage::helper('catalog')->__('Choose an Option...'),

with:

1
'chooseText'        => Mage::helper('catalog')->__('Select ' . $info['label']),

Now we have the option title in the first select option of our dropdown option. All we need to do now is remove the option title, that is by default position above the dropdown.

To do this, find the two files located at the path below and copy them into your theme directory under the same path:

app/design/frontend/base/default/template/catalog/product/view/options/type/select.phtml

and

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

Simply comment out or remove everything in between the ‘dt’ tag in both files. Please note the required indicator is output within this code, it’s up to you what you do with it.


In the configurable.phtml file, you’ll also want to replace the ‘option’ tag with the below:

1
<option><?php echo $this->__('Select ') ?><?php echo $_attribute->getLabel() ?></option>

And add the below code above the select element. This will be used as a hidden reference to the select label:

1
<div id="Select <?php echo $_attribute->getLabel() ?>"></div>

The complete ‘dd’ tag will look like this:

1
2
3
4
5
6
7
8
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
     <div class="input-box">
          <div id="Select <?php echo $_attribute->getLabel() ?>"></div>
          <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
               <option><?php echo $this->__('Select ') ?><?php echo $_attribute->getLabel() ?></option>
          </select>
     </div>
</dd>

To make the hidden reference usable on configurable product pages, we need to update configurable.js, found in:

js/varien/configurable.js

Update line 171, which reads:

1
element.options[0] = new Option(this.config.chooseText, '');

to:

1
element.options[0] = new Option(jQuery(element).prev().attr('id'), '');

Update:

If you want to keep the title displayed for different types of options, such as radio or checkbox, the select.phtml file needs a little more updating. Here’s the finished complete file, it essentially checks the type of option and displays the title depending on this check:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
    $_option = $this->getOption();
    if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO
        || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX
        ) { $_isRadCheck = true; }
?>

<?php if ($_isRadCheck): ?>
    <dt><label<?php if ($_option->getIsRequire()) echo ' class="required"' ?>><?php if ($_option->getIsRequire()) echo '<em>*</em>' ?><?php echo $this->__('Select ') ?><?php echo  $this->htmlEscape($_option->getTitle()) ?></label></dt>
<?php endif; ?>

<dd<?php if ($_option->decoratedIsLast){?> class="last"<?php }?>>
    <div class="input-box">
    <?php if ($_option->getIsRequire()) echo '<em>*</em>' ?>
        <?php echo $this->getValuesHtml() ?>
        <?php if ($_option->getIsRequire()): ?>
            <?php if ($_isRadCheck): ?>
                <span id="options-<?php echo $_option->getId() ?>-container"></span>
            <?php endif; ?>
        <?php endif; ?>
    </div>
</dd>
magento-title-show-radio