Author Topic: Country List Order and UK Counties - Hack  (Read 14440 times)

Datatonic

  • Jr. Member
  • **
  • Posts: 95
    • Datatonic
Country List Order and UK Counties - Hack
« on: February 01, 2009, 04:40:48 am »

I have been setting up a Virtuemart store.

We are based in the UK and after the UK, the United States are our biggest customers. 

I wanted to add all the UK counties and their respective countries to VM and also change the order in which the countries are listed in the country drop down boxes.

Here's how I did it.

I used the instructions here to add the proper UK Counties. http://forum.virtuemart.net/index.php?topic=33968.0

I also went a step further and delete the United Kingdom, leaving England, Northern Ireland, Scotland and Wales in its place.

Next I wanted to change the order of the countries, putting England, Northern Ireland, Scotland, Wales and United States first, with the rest of the countries running alphabetically after them.

To do this I exported the vm_country table and put these Countries at the top of the list, I also put the countries in proper alphabetical order, as the default was sorted to the country code rather than the country name.

I then changed the country id's in vm_state to match the newly sorted countries.

I have attached an sql file that will drop this into the database for you.

BE WARNED THIS WILL DELETE YOUR EXISTING vm_country and vm_state TABLES AND REPLACE IT WITH NEW ONES.  MAKE SURE YOU BACK UP YOUR DATABASE BEFORE IMPLEMENTING THIS!!!!!

If you would like to change the order, you will need to edit the SQL and remember to change the country id's in the vm_state statements to match the new order.

Next you need to change the following (this step also comes from the UK Counties instructions mentioned above).

Open /administrator/components/com_virtuemart/classes/ps_country.php

At line 33 (in VM 1.1.3)

Code: [Select]
function &get_country_by_code( $code ) {
$db = new ps_DB();
$country_code_type = strlen( $code );
switch ($country_code_type) {
case 2:
$country_code_type_field = 'country_2_code';
break;
case 3:
$country_code_type_field = 'country_3_code';
break;
default:
return false;
            

to

Code: [Select]
function &get_country_by_code( $code ) {
$db = new ps_DB();
$country_code_type = strlen( $code );
switch ($country_code_type) {
case 2:
$country_code_type_field = 'country_2_code';
break;
case 3:
$country_code_type_field = 'country_3_code';
break;
default:
$country_code_type_field = 'country_2_code';
     
Next up we need to change the way VM lists the countries from the Country Name to the Country ID, to do this open  /administrator/components/com_virtuemart/classes/ps_html.php

At Line 216 (in VM 1.1.3)

Change

Code: [Select]
$q = "SELECT country_id, country_name, country_3_code from #__{vm}_country ORDER BY country_name ASC";
To

Code: [Select]
$q = "SELECT country_id, country_name, country_3_code from #__{vm}_country ORDER BY country_id ASC";

This sorts the countries drop down by the country id rather than country name and voila, the main countries your visitors come from are at the top of the drop down list, with the rest running alphabetically after them.

[attachment cleanup by admin]

sugapablo

  • Beginner
  • *
  • Posts: 3
Re: Country List Order and UK Counties - Hack
« Reply #1 on: March 31, 2009, 02:47:04 am »
Got an easier way:

~/administrator/components/com_virtuemart/classes/ps_html.php

function getCountryList()

change the SQL query from:
Code: [Select]
SELECT country_id, country_name, country_3_code
from #__{vm}_country
ORDER BY country_name ASC

Code: [Select]
SELECT country_id, country_name, country_3_code
from #__{vm}_country
ORDER BY FIELD(country_name,'United States','England','Whatever other country','etc') DESC,
country_name ASC

This will put the countries you select in the country_name field first, followed by the rest.

Enjoy!



RCheesley

  • Jr. Member
  • **
  • Posts: 81
Re: Country List Order and UK Counties - Hack
« Reply #2 on: February 21, 2011, 12:50:11 pm »
This causes a bit of a problem with the Tax rates which are now screwed - can't find the right fields as they've all been changed! OOps!  Just looking at a workaround.

Ruth

Datatonic

  • Jr. Member
  • **
  • Posts: 95
    • Datatonic
Re: Country List Order and UK Counties - Hack
« Reply #3 on: February 22, 2011, 16:37:54 pm »
Ruth - I'll take a look at the tax rates and edit the post above to ensure it works.  Tbh I have always done this on a fresh install before modifying anything else.  I'll have a look and see what can be done.

wavey_davey

  • Beginner
  • *
  • Posts: 4
Re: Country List Order and UK Counties - Hack
« Reply #4 on: October 11, 2011, 16:28:53 pm »
Sorry to post in an old thread - but this is the only one that's close to my issue.

I'm trying to reorder the Country list so that United Kingdom appears at the top, but all my efforts don't seem to alter the order of the countries in the Dropdown box at all.

I have found the function, getCountryList, and it is already set to order by Country_id, but my list is still alphabetic.  Is there possibly another location where a similar function is stored?  Would having a non standard template affect this?

Any help much appreciated

Dave

softpill

  • Beginner
  • *
  • Posts: 3
  • Skype Name: unixbreak
Re: Country List Order and UK Counties - Hack
« Reply #5 on: October 01, 2013, 18:16:31 pm »