Tuesday, 4 September 2012

Magento: Add a custom State / Province / Region to a Country

 Add North and South Island to New Zealand

So let’s say that like me, you live in New Zealand and want to add 2 regions: North Island and South Island. The country id for New Zealand is NZ, the region code is a unique identifier so I’m going with NORTH and at the moment I’m only interested in the en_US locale.
First I will insert North Island into directory_country_region as follows:

INSERT INTO `directory_country_region` 
(`region_id`,`country_id`,`code`,`default_name`) 
VALUES (NULL,'NZ','NORTH','North Island');
 
Note the NULL entry for the region_id field which will auto_increment. I need to find out this new region_id for my next insert so I can either browse the table manually, or this query will do the trick:

SELECT * FROM `directory_country_region` 
WHERE `country_id`='NZ' AND`code`='NORTH' AND `default_name`='North Island';
In my case, the new region_id is 320, so with that I’ll now insert into directory_country_region_name as follows:

INSERT INTO `directory_country_region_name` 
(`locale`,`region_id`,`name`) 
VALUES ('en_US','320','North Island');
 
Now I just repeat those steps for South Island and I’m all set.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.