Adding a Missing Region/Province/State to Ubercart 

The Districts of Hong Kong

According to Wikipedia:

Hong Kong in administration is divided into 3 regions and 18 districts.

The 3 regions are: Hong Kong Island (HK), Kowloon (KLN), and the New Territories (NT)

The Problem:

Our company has many customers in Hong Kong.  Unfortunately, it was impossible for them to supply a correct Billing Address or Shipping Address due to an error in Ubercart 3.x with respect to the list of available Regions in Hong Kong, which was missing Kowloon as a choice.  As a consequence of this, the GUI dropdown that our clients used to construct their Billing Address and Shipping Address only listed two of the three Regions of Hong Kong (Hong Kong Island, New Territories).  Lacking the correct choice, customers chose to leave it unselected when registering their address.  This resulted in strange shipping and billing addresses with the word Unknown appearing in them:

This situation caused considerable stress and anxiety for customers, ourselves and local delivery people because all of us rely on correct and complete delivery information to co-ordinate various aspects of deliveries (logistics, scheduling and routing).

Ubercart Database Information

Country Information

In Ubercart 3.x, country information is stored in the uc_countries table:

MariaDB [hph]> describe uc_countries;

+--------------------+------------------+------+-----+---------+-------+

| Field              | Type             | Null | Key | Default | Extra |

+--------------------+------------------+------+-----+---------+-------+

| country_id         | int(10) unsigned | NO   | PRI | NULL    |       |

| country_name       | varchar(255)     | NO   | MUL |         |       |

| country_iso_code_2 | char(2)          | NO   |     |         |       |

| country_iso_code_3 | char(3)          | NO   |     |         |       |

| version            | smallint(6)      | NO   |     | 0       |       |

+--------------------+------------------+------+-----+---------+-------+

Hong Kong Entry

The entry for Hong Kong in uc_countries contains the following data:

MariaDB [hph]> select * from uc_countries where country_name ="Hong Kong";

+------------+--------------+--------------------+--------------------+---------+

| country_id | country_name | country_iso_code_2 | country_iso_code_3 | version |

+------------+--------------+--------------------+--------------------+---------+

|        344 | Hong Kong    | HK                 | HKG                |       1 |

+------------+--------------+--------------------+--------------------+---------+

Zone Information

In Ubercart 3.x, region information related to uc_countries is stored in uc_zones:

MariaDB [hph]> describe uc_zones;

+-----------------+------------------+------+-----+---------+----------------+

| Field           | Type             | Null | Key | Default | Extra          |

+-----------------+------------------+------+-----+---------+----------------+

| zone_id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |

| zone_country_id | int(10) unsigned | NO   | MUL | 0       |                |

| zone_code       | varchar(32)      | NO   | MUL |         |                |

| zone_name       | varchar(255)     | NO   |     |         |                |

+-----------------+------------------+------+-----+---------+----------------+

Incorrect Region Entries

The stock (incomplete) entries for Hong Kong contains the following data:

MariaDB [hph]> select * from uc_zones where zone_country_id=344;

+---------+-----------------+-----------+-----------------+

| zone_id | zone_country_id | zone_code | zone_name       |

+---------+-----------------+-----------+-----------------+

|      79 |             344 | HK        | Hong Kong       |

|      80 |             344 | NT        | New Territories |

+---------+-----------------+-----------+-----------------+

There is no entry for "Kowloon", which is the problem.

Fixing the  Missing Kowloon Problem

Enabling All Future Hong Kong Orders to Offer Kowloon as a Province/State Choice:

Moving forward, all future orders should feature Kowloon as a drop-down Provice/State choice.  This can be implemented by inserting a row into the uc_zones table:

MariaDB> INSERT INTO uc_zones VALUES ("","344","KL","Kowloon");

Query OK, 1 row affected, 1 warning (0.00 sec)

The table now contains the following data:

MariaDB [hph]> select * from uc_zones where zone_country_id=344;

+---------+-----------------+-----------+------------------+

| zone_id | zone_country_id | zone_code | zone_name        |

+---------+-----------------+-----------+------------------+

|      79 |             344 | HK        | Hong Kong Island |

|      80 |             344 | NT        | New Territories  |

|    4374 |             344 | KL        | Kowloon          |

+---------+-----------------+-----------+------------------+

Which results in desired interface behavior:

Comments

I believe is in the ubercart\uc_store\countries folder.

Supply a pull request for the relevant one and it should get added.

I've just had a quick look

Have a look at United Kingdom, which adds a Zone array... and do something similar with the hong_kong_344_1.cif file.

Hello @DrAlbany

Thanks for pointing out the files!  Super!

Yes, a line should be added to the .cif file located at:

/ubercart/uc_store/countries/hong_kong_344_1.cif

like this:

  // Make the entries in the zones table.
  $zones = array(
    array(344, 'HK', 'Hong Kong'),
    array(344, 'KL', 'Kowloon'), 
    array(344, 'NT', 'New Territories'),
  );

As for the abbreviation, I am not sure what the 2-letter ISO code should be for the Kowloon District of Hong Kong.  There were no entries found at:

https://www.iso.org/obp/ui/#search

Nor can I find 2-letter codes associated with Kowloon anywhere else.  There's plenty of 3-letter codes (KKC), but no 2-letter ones. 

My instincts tell me that the 2-letter code for Kowloon is going to be KW when you consider one of the 3-letter codes on offer:

LOCODE:

HK,KWN,Kowloon

Or it is going to be KL when you consider the Region abbreviations:

Hong Kong Island (HK), Kowloon (KLN), and the New Territories (NT).

We need to make a choice.  I vote for KL because it matches the two words that compose the Region name (Gao/Kao ="9", Long="Dragon")

In the meantime, can someone please do a pull/revision request for me please?

Updating source files is a much better, safer and more sustainable way of doing this than manipulating the database directly.

g.

-----

 

bugfolder's picture

@Graham, I've submitted a PR against the issue that should fix the problem (adding Kowloon to the HK zones). Can you test it?