Magento – Find Select HTML Tag for Countries on Checkout Page

checkoutmagento-1.8onepage-checkout

Where can I the html select tag for countries on the checkout page?

<div class="field form-group">
       <label for="billing:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
       <div class="input-box">
          <?php echo $this->getCountryHtmlSelect('billing') ?>
       </div>
</div>

with this $this->getCountryHtmlSelect('billing'), it returns the html select tag below,

<select name="billing[country_id]" id="billing:country_id" class="validate-select" title="Country" >
<option value="" > </option>
<option value="AF" >Afghanistan</option><option value="AL" >Albania</option>
<option value="DZ" >Algeria</option>
...

But I need to add a class name to the select tag,

class="form-control validate-select"

But where can I find this select tag?

Best Answer

The country select box is prepared by the block,

To change its behavior you just need override the function to you local folder like below.

Just copy the core\Mage\Checkout\Block\Onepage\Billing.php to you local folder like

local\Mage\Checkout\Block\Onepage\Billing.php

Now you just need to put the below code in that file see I have added the "form-control" to setClass() function.

its done now your class will be added to the select box.

public function getCountryHtmlSelect($type)
{
    $countryId = $this->getAddress()->getCountryId();
    if (is_null($countryId)) {
        $countryId = Mage::helper('core')->getDefaultCountry();
    }
    $select = $this->getLayout()->createBlock('core/html_select')
        ->setName($type.'[country_id]')
        ->setId($type.':country_id')
        ->setTitle(Mage::helper('checkout')->__('Country'))
        ->setClass('validate-select form-control')
        ->setValue($countryId)
        ->setOptions($this->getCountryOptions());
    if ($type === 'shipping') {
        $select->setExtraParams('onchange="if(window.shipping)shipping.setSameAsBilling(false);"');
    }

    return $select->getHtml();
}