Saturday, October 9, 2010

PrestaShop Tips - How to fix sort problem in State dropdown list

At PrestaShop, if you are shipping your products to a country that contains States, you will have to manually create States list at you back office. And also you have to set the country as "Contains states". If you do not configure correctly, there will be some errors at payment process, at least this will happen if you use Paypal.
See here on how to configuration for country contains States


If you are using 1.3.1 or lower, here is another problem if you don't input States data in the alphabetical order of name. The drop down list in address page will displayed incorrectly at FireFox.

See below screen for FireFox and IE.





Why would this happen?
I checked that the data is sorted correctly in both source code PHP and Javascript. The problem is caused by different browser. It seems that IE and FireFox behave in different. I guess that FireFox is using the value[key] as sort key to display stats the drop down list, not in the order that PrestaShop prepared in a Javascript array.

See here is Javascript code in HTML page:




Solution:
The only solution I can figure out for this issue, is to change the ID of your states to make them in a correct order.

I also heard that the new version 1.3.2 of PrestaShop has fixed the problem, so you have another option to upgrade to a new version 1.3.2.

Temporary Fix solution 1:
Delete those States that are not in correct order.
Re-input your States data in alphabetical order of the State Name.

Temporary Fix solution 2:
Re-assign the ID in database, by tools like PhpMyAdmin. But you must start the new ID from the max number that currently used in State table.

Note:
After you modified your state data, you must update your related state ID in address tables, other wise, when you use existing account/address to place an order, error will occurs.

The following post discussed on how to fix the problem by change PHP code, you can have a try.

http://www.prestashop.com/forums/viewthread/73116/

No comments: