Jump to content

Custom field with the list of countries


cyberespia

Recommended Posts

I have added a new field and everything works fine, but the field will be country and my question is how to insert the countries that already have prestashop.

 

In /myadmin/themes/default/template/controllers/products/informations.tpl  I have

	<div class="form-group">

		<label class="control-label col-lg-3" for="mipais">
			<span class="label-tooltip" data-toggle="tooltip"
				title="{l s='My countries'}">
				{$bullet_common_field} {l s='Country'}
			</span>
		</label>
		<div class="col-lg-3">
			

					<select name="micountry" id="micountry">
						<option value="Peru" {if $product->micountry == 'Peru'}selected="selected"{/if} >{l s='Peru'}</option>
						<option value="Reino Unido" {if $product->micountry == 'Reino Unido'}selected="selected"{/if} >{l s='Reino Unido'}</option>
						<option value="EE UU" {if $product->micountry == 'EE UU'}selected="selected"{/if}>{l s='EE UU'}</option>
					</select>



		</div>
	</div>

How to insert the list of countries available in prestashop?

 

 

For example in Customer Registration, is:

						<select name="id_country" id="id_country" class="form-control">
							{foreach from=$countries item=v}
							<option value="{$v.id_country}"{if (isset($guestInformations) && isset($guestInformations.id_country) && $guestInformations.id_country == $v.id_country) || (!isset($guestInformations) && $sl_country == $v.id_country)} selected="selected"{/if}>{$v.name|escape:'html':'UTF-8'}</option>
							{/foreach}
						</select>

Thanks for any help given

Link to comment
Share on other sites

You can try adding the following before the {foreach from=$countries item='country} loop:

{assign var='countries' value=Country::getCountries((int)$cookie->id_lang, true)}

This will get all active countries and assign it to the $countries variable. If you want inactive countries included too, change true to false.

Link to comment
Share on other sites

Thank you very much for your answer

I tested your code and it works with IDs but  how I get the name of the country?

With the following code:


{assign var='countries' value=Country::getCountries((int)$cookie->id_lang, false)}
					<select name="pais" id="pais">

                                           
							{foreach from=$countries item=pais}
							<option value="{$pais.id_country}">{$pais.name|escape:'html':'UTF-8'}</option>
							{/foreach}

					</select>

I get the following:

<select name="pais" id="pais">
                                           
<option value="189"></option>
<option value="93"></option>
<option value="221"></option>
.
.
.						
</select>

Of course, thank you very much for your attention

Edited by cyberespia (see edit history)
Link to comment
Share on other sites

  • 4 years later...
On 8/3/2016 at 8:44 PM, cyberespia said:

I have added a new field and everything works fine, but the field will be country and my question is how to insert the countries that already have prestashop.

 

In /myadmin/themes/default/template/controllers/products/informations.tpl  I have


	<div class="form-group">

		<label class="control-label col-lg-3" for="mipais">
			<span class="label-tooltip" data-toggle="tooltip"
				title="{l s='My countries'}">
				{$bullet_common_field} {l s='Country'}
			</span>
		</label>
		<div class="col-lg-3">
			

					<select name="micountry" id="micountry">
						<option value="Peru" {if $product->micountry == 'Peru'}selected="selected"{/if} >{l s='Peru'}</option>
						<option value="Reino Unido" {if $product->micountry == 'Reino Unido'}selected="selected"{/if} >{l s='Reino Unido'}</option>
						<option value="EE UU" {if $product->micountry == 'EE UU'}selected="selected"{/if}>{l s='EE UU'}</option>
					</select>



		</div>
	</div>

How to insert the list of countries available in prestashop?

 

 

For example in Customer Registration, is:


						<select name="id_country" id="id_country" class="form-control">
							{foreach from=$countries item=v}
							<option value="{$v.id_country}"{if (isset($guestInformations) && isset($guestInformations.id_country) && $guestInformations.id_country == $v.id_country) || (!isset($guestInformations) && $sl_country == $v.id_country)} selected="selected"{/if}>{$v.name|escape:'html':'UTF-8'}</option>
							{/foreach}
						</select>

Thanks for any help given

Is this the same topic you are talking about?

https://stackoverflow.com/questions/64544159/add-countries-in-form-field-prestashop-1-7-x/64544370#64544370

Have a great day!

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...