1

Just like there is a default value for 'State/Province' field which is: 'Please select region, state or province' I need to add a default value to City field in billing and shipping steps in checkout. In my case the City is drop-down list getting its list of cities from database.

In app>design>frontend>base>default>template>checkout>onepage>billing.phtml, the city field code is:

<div class="field">
     <label for="billing:city" class="required"><em>*</em><?php echo $this->__('City') ?>
     </label>

     <div class="input-box">
        <input type="text" title="<?php echo $this->__('City') ?>" 
             name="billing[city]" 
             value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" 
             class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>"
             id="billing:city"/>
     </div>
</div>
1
  • I don't see any dropdown (ex: <select>) in your code. Commented Aug 21, 2015 at 6:43

2 Answers 2

0

If I understand you, you want to force your users to have default value on city section then change this:

value="<?php echo "your city name"; //$this->escapeHtml($this->getAddress()->getCity()) ?>" 

This will make default city on city field.

PS

By default Magento pools city data for registered customer from database using $this->escapeHtml($this->getAddress()->getCity()) function.

So when you change this, it will never pool that data.

3
  • Let me check this.Please note that i am using an extension for drop-down city list so I will edit the extension's billing.phtml and shipping.phtml files.Does that too would pose issue to pool data for registered customers if i follow your answer? Commented Aug 21, 2015 at 6:41
  • Yes, every extension I believe are written magento way. Commented Aug 21, 2015 at 6:42
  • Your answer works.But there is already an empty space at the top of drop-down city list i want that space be taken up by default value.If possible please take a few seconds to check my site www.apollo-sports.com.pk/magento select any product and go to check out to see what there in billing.please?First select country Romania and then the first State and then cities will appear Commented Aug 21, 2015 at 6:47
0

If like the state/province you just want to show what is effectively help text, I suggest you add a placeholder attribute to the input box. So something like...

<<input type="text" title="<?php echo $this->__('City') ?>" 
         name="billing[city]" 
         value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" 
         class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>"
         id="billing:city"
         placeholder="<?php echo $this->__('Please enter city'); ?>"/>

Then if they empty the value out the placeholder text will appear again.

Regards, Andy

1
  • Hi I tried your way but the placeholder text disappears upon selecting any country and / or State :( Commented Aug 21, 2015 at 6:58

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.