Jump to content

How to customize dropdown city on address page?


abdulcrb

Recommended Posts

I'm facing same problem. My first attempt is edit file address-form.tpl by adding below condition

          {if $field["name"] eq "city"}
            <p class="required city select">
                <label for="city">{l s='City'} <sup>*</sup></label>
                <select name="city" id="id_city">
              <option value="">-3</option>
                </select>
            </p>
Edited by hasan197 (see edit history)
Link to comment
Share on other sites

 

I'm facing same problem. My first attempt is edit file address-form.tpl by adding below condition

          {if $field["name"] eq "city"}
            <p class="required city select">
                <label for="city">{l s='City'} <sup>*</sup></label>
                <select name="city" id="id_city">
              <option value="">-3</option>
                </select>
            </p>

This Problem Solve , I Edit Classes CustomerAddressFormatter.php and edit  function getFormat, I use City get from external api rajaongkirapi

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...
  • 2 weeks later...
9 hours ago, rizkyprogrammer said:

You can check this my article for create dropdown with rajaongkir API for city of indonesia,

https://aidil.web.id/2018/04/08/prestashop-1-7-rajaongkir-city-dropdown/dropdown.png.fe6187ea2bbe939d7531a9fd0e31425f.png

 

awesome work, thx

 

my RU example

        foreach ($fields as $field) {
            $formField = new FormField();
            $formField->setName($field);

            $fieldParts = explode(':', $field, 2);

            if ($field === 'city') { 
                $url='http://api.boxberry.de/json.php?token=XXXX.YYYY&method=ListCitiesFull';
                $handle = fopen($url, "rb");
                $contents = stream_get_contents($handle);
                fclose($handle);
                $data=json_decode($contents,true);
                if(count($data)<=0 or $data[0]['err'])
                {
                    error_log('Ошибка получения городов! '.$data[0]['err'], 0);
                }
                else
                {
                  $formField->setType('select');

                  foreach ($data as $obj) {
                      $citys_array[] = $obj['Name'];
                  }

                  sort($citys_array);
                  array_unshift($citys_array, 'Санкт-Петербург');
                  array_unshift($citys_array, 'Москва');
                  $final = array_unique($citys_array);
                  
                  foreach ($final as $city) {
                      
                      $formField->addAvailableValue(
                          $city,
                          $city
                      );
                  }
                }
            }

 

Link to comment
Share on other sites

  • 1 year later...
On 4/9/2018 at 12:02 AM, Evgenii Pavlov said:

 

$url='http://api.boxberry.de/json.php?token=XXXX.YYYY&method=ListCitiesFull'; $handle = fopen($url, "rb");

Evgenii Pavlov - your application load all list of cities ? not only the ones related to respective county ?

I can't see you sending the parameter for county...

 

Thank you,

Daniel

Link to comment
Share on other sites

  • 9 months later...
  • 8 months later...

This will be a long process for layman.  I have a complete module that solve this for you.  Both on city and zip code drop-down.  And it will display everywhere an address is found.  It also have a feature to allow customers to add their city and zip code if is not listed.  Well,  you can disable the feature if you don't want the customer to add their own city and zip code.  I will send the link here if you want or can message me if you want too.  Works perfectly fine.  

Link to comment
Share on other sites

  • 3 months later...
On 1/5/2021 at 5:23 PM, Mr. Trice said:

This will be a long process for layman.  I have a complete module that solve this for you.  Both on city and zip code drop-down.  And it will display everywhere an address is found.  It also have a feature to allow customers to add their city and zip code if is not listed.  Well,  you can disable the feature if you don't want the customer to add their own city and zip code.  I will send the link here if you want or can message me if you want too.  Works perfectly fine.  

May i get the Module, Please. Sounds a good Module. 

Link to comment
Share on other sites

  • 2 weeks later...
On 4/19/2021 at 9:23 PM, num47 said:

May i get the Module, Please. Sounds a good Module. 

Contact faddons.com, that's my team mates.  Or you can chat me personally on whatsapp +2347039732276 The module is cheap to get.  

Link to comment
Share on other sites

  • 2 months later...
On 4/19/2021 at 9:23 PM, num47 said:

May i get the Module, Please. Sounds a good Module. 

You can checkout the demo here> 

Backoffice = https://demo.faddons.com/prestashop/admin914gpvxwo
 

email: [email protected]

pass: demodemo

the module is hooked under international menu

Front office =  https://demo.faddons.com

 

the module also has a function to add a text to display at the front office incase you want the customer to add his/her own city and zipcode if not listed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...