cancel
Showing results for 
Search instead for 
Did you mean: 

Change the order for the "State/Province" and "Country" fields to select the country first

Change the order for the "State/Province" and "Country" fields to select the country first

Hi everyone,

 


In most of the pages in Magento, we can find the "State/Province" before the "Country" field. Since the "State/Province" depends on the country, that is confusing since the customer has go to next field and select the country, and then go back to the previous field and select the state/province.

 

This is not correct in the most important page in the storefront, the onepage checkout:

 

Screen Shot 2017-01-10 at 11.28.04 AM.png

 

And you can also see the wrong order in some pages of the admin panel:

 

Screen Shot 2017-01-10 at 11.24.44 AM.png

 

In other pages, like the shopping cart page, the order is correct:

Screen Shot 2017-01-10 at 11.27.49 AM.png

 

It would be better if the country can be selected first, then the state/province and finally the ZIP/Postal Code (just like the shopping cart page).

 

12 Comments
avoelkl
M2 Certified

Oh yes, that would make SO MUCH sense. This behaviour is really annoying, also in Magento 1 currently. The order should be changed.

Gabriel Guarino
Moderator

Thanks @avoelkl!

I think the order could be based on the "General -> General -> Country Options -> Default Country" store configuration setting.

If the country is United States, then the order should be the one that is currently applied in Magento 1 and Magento 2 (generally the order for checkout forms in USA is Street, City, State, ZIP, Country).

 

If the country is not United States, I think the order should be the one that is currently discussed on this topic.

beejhuff
Contributor

This is a great suggestion, Gabriel! Thanks for submitting it - I've scheduled a few retweets and will keep monitoring voting numbers to try and encourage #RealMagento participation on this one.

erfanimani
M2 Certified

Thanks for posting! It's indeed confusing for anyone that's not from the US.

Damian Culotta
Moderator

This is a really old discussion. I'm not sure which rule follow every country but normally it seems that the default behavior is ok if your sotre works with 1 country only.

If you'll allow multiple countries the order should be (well, in my opinion) the proposed one on this topic.

At the end, the option to configure this will be the best solution for everyone.

beejhuff
Contributor

@Damian Culotta Great point & I feel best possible scenario that helps EVERYONE is intelligent defauts, but I'd go a little further if most seemless user experience is truly the objective...

 

  1. Hide It altogether for those stores who only have ship/sell enabled for one country - if it's not an option, by definition it seems inappropriate to display in a drop-down selector, maybe even at all. ( I'm guessing this may be mostly non-European merchants, though could be wrong...but definitely most US sites).

  2. When > 1 Ship/Sell Countries enabled, then use Gabriel's suggestion.  
Damian Culotta
Moderator

@beejhuff,

 

You have my vote.

 

andrew40404
New Contributor

I agreed with @beejhuff. He has my vote

erfanimani
M2 Certified

In the meantime.. I vaguely remember someone posting a guide on how to do this yourself, and if I remember correctly it was a combination of multiple layout xml, eav attribute and template changes. Anyone have the link saved? If not, I'll try to post it here.

erfanimani
M2 Certified

For the people that are wondering - it's quite easy to change the sort order of the shipping address on the checkout, just one layout XML change is needed.

 

The `sortOrder` attribute of the `country_id` field needs to be set to `null`, so that it properly falls back to the values defined in the `eav_entity_attribute` table (which are set to intelligent defaults).

 

...

<item name="country_id" xsi:type="array"> <item name="sortOrder" xsi:type="null"/> </item>

...

(For the complete XML, check out https://github.com/magento/magento2/issues/6325 )

 

To see the defaul sort orders, run the following query:

 

select a.attribute_id, a.attribute_code, b.sort_order
from eav_attribute a,
eav_entity_attribute b
where a.entity_type_id = 2 and a.attribute_id = b.attribute_id;

Which outputs.. 

 

Untitled.png

 

It's quite odd, the sort order of country is specifically changed (and only country_id), for the checkout shipping form - not entirely sure why, seems like a mistake..

 

On top of that, the country_id sortOrder for the billing address is hardcoded to 115, so neither changing it in the eav_entity_attribute or layout XML is going to solve it - you'll need to create a plugin or change the entire class with DI. (closed) bug report here: https://github.com/magento/magento2/issues/6325 (code has changed in the meantime, but the problem still exists).