Aug 17, 2012

Prestashop - Increasing State ISO-Code Length


I believe that many Prestashop users has issue when inserting ISO Code for state due to the character length. Some countries accept 4 character state ISO Code. However, for certain countries like Malaysia, there are 5 character state ISO Code. Hence, I created this random post for solving this problem, guiding you how to increase ISO Code character.

Let's start the action.
Step 1: Update PS_STATE In SQL Database
i. Go to Database in PhpMyAdmin
ii. Search for ps_state
iii. Go to Structure Tab
iv. Select ISO Code and click on Change
v. Insert 5 to Length/Value field and click Save

Step 2: Change The Length of ISO Code Length Validation
i.  Open /classes/State.php with your editor
ii. Go to line #46 (For version 1.4.7 & above)
iii. Change the following code from
protected  $fieldsSize = array('iso_code' => 4, 'name' => 32);
To protected  $fieldsSize = array('iso_code' => 5, 'name' => 32);

Step 3: Change The Regular Express of ISO Code
i. Open /classes/Validation.php 
ii. Go to line #310 (For version 1.4.7 & above)
iii. Change the following code from
static public function isStateIsoCode($isoCode)
{
 return preg_match('/^[a-z]{1,4}$/ui', $isoCode);
}
To
static public function isStateIsoCode($isoCode)
{
return preg_match('/^[a-z0-9-]{1,5}$/ui', $isoCode);
}

Step 4: Change The Length Input Textbox 
i. Open admin/tabs/AdminStates.php
ii. Go to line #120  (For version 1.4.7 & above)
iii. Update the size value

<input maxlength="5" name="iso_code" size="5" style="text-transform: uppercase;" type="text" value="'.htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
'.$this->l('1 to 5 letter ISO code').' ('.$this->l('official list here').')

It is done now!


3 comments:

  1. This is actually what I'm looking for I got errors upon inserting codes into my Prestashop Themes and I'm now procrastinating to return it back, I'm very greatful I've found this snippet now my site is up and running smooth. Cheers

    ReplyDelete
  2. Thanks Ray for this useful info :)

    ReplyDelete
  3. Hi Ray,
    for info here, new Prestashop vs 1.5 accept iso code for malaysia we don't need again tweak code like this :)

    ReplyDelete