Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 2 votes

Country-State Selector


1141 replies to this topic

#1121 eberswine

  • Community Member
  • 35 posts
  • Real Name:josh

Posted 17 June 2011, 16:32

View Poststevel, on 17 June 2011, 15:28, said:

No - I would change the routine in includes/functions/general.php that creates the zones dropdown list (I don't have the code handy so I forget exactly what it is called) to insert the zone code rather than name.


oh, wow, Thanks for the reply, I wouldn't have looked there!!

SO here are the two functions in /includes/functions/general.php:

So, just change the zone_name (from the first function below) to zone_code , right?

// Returns the zone (State/Province) name
// TABLES: zones
  function tep_get_zone_name($country_id, $zone_id, $default_zone) {
    $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
    if (tep_db_num_rows($zone_query)) {
      $zone = tep_db_fetch_array($zone_query);
      return $zone['zone_name'];
    } else {
      return $default_zone;
    }
  }

////
// Returns the zone (State/Province) code
// TABLES: zones
  function tep_get_zone_code($country_id, $zone_id, $default_zone) {
    $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
    if (tep_db_num_rows($zone_query)) {
      $zone = tep_db_fetch_array($zone_query);
      return $zone['zone_code'];
    } else {
      return $default_zone;
    }
  }


#1122 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 17 June 2011, 18:08

View Posteberswine, on 17 June 2011, 16:32, said:

oh, wow, Thanks for the reply, I wouldn't have looked there!!

SO here are the two functions in /includes/functions/general.php:

So, just change the zone_name (from the first function below) to zone_code , right?


No, not those routines. Maybe the routine I am thinking of is in html_output.php. It is the one that creates a dropdown list of zone names. You would replace the call to tep_get_zone_name with one to tep_get_zone_code.

#1123 eberswine

  • Community Member
  • 35 posts
  • Real Name:josh

Posted 17 June 2011, 18:59

View Poststevel, on 17 June 2011, 18:08, said:

No, not those routines. Maybe the routine I am thinking of is in html_output.php. It is the one that creates a dropdown list of zone names. You would replace the call to tep_get_zone_name with one to tep_get_zone_code.


hmmmm.. thanks for the try.. i did a global search and only came up with tep_get_zone_name in customers.php and address_book.php and general.php.. ?

dang.

thanks for your time, i will keep searching!

#1124 eberswine

  • Community Member
  • 35 posts
  • Real Name:josh

Posted 18 June 2011, 00:15

View Posteberswine, on 17 June 2011, 18:59, said:

hmmmm.. thanks for the try.. i did a global search and only came up with tep_get_zone_name in customers.php and address_book.php and general.php.. ?

dang.

thanks for your time, i will keep searching!


dang, still can't find that file ???

#1125 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 18 June 2011, 00:47

That's what I get for trying to remember. Sorry to have led you astray.

On the pages where you are using this, there will be code like this:

    while ($zones_values = tep_db_fetch_array($zones_query)) {
      $zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_name'] . ' (' . $zones_values['zone_code'] . ')');
      }

At least in this version, this gives you lines such as:

New Hampshire (NH)

If you just want NH there, then make this:


    while ($zones_values = tep_db_fetch_array($zones_query)) {
      $zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_code']);
      }

You will have to repeat this in each file where there is a zone dropdown. Be careful as some of them may use different variable names.

#1126 eberswine

  • Community Member
  • 35 posts
  • Real Name:josh

Posted 18 June 2011, 13:00

Ok,

I think I understand how it is working now. I will test and then get back with you!! THanks so much!

I have another quick question for you??

If we have USA as our default Country... And we want to ship to other countries , how do we let both us and the customer, if they choose another country, like Canada for example, to let them know we are charging extra for shipping when "Canada" pops up?

Maybe like a if { COUNTRY = "Canada" { echo "Warning, extra charge" } .. ??

Thanks so much in advance!!

#1127 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 18 June 2011, 14:06

I don't know how you tell customers about shipping now, but most stores compute and display shipping charges on the checkout_shipping page. If you have text on your site that says "Free Shipping!" you need to qualify that as to where you will do free shipping. I don't think the country selection is the place to do it.

#1128 eberswine

  • Community Member
  • 35 posts
  • Real Name:josh

Posted 18 June 2011, 14:08

View Poststevel, on 18 June 2011, 14:06, said:

I don't know how you tell customers about shipping now, but most stores compute and display shipping charges on the checkout_shipping page. If you have text on your site that says "Free Shipping!" you need to qualify that as to where you will do free shipping. I don't think the country selection is the place to do it.


Yes, makes since.. Thanks for your help!! I will be doing testing for the next couple days. I really appreciate your awesome plug-in!! Great stuff!!

#1129 adw49

  • Community Member
  • 29 posts
  • Real Name:Andy
  • Gender:Male
  • Location:Sarasota, FL

Posted 28 June 2011, 15:22

Steve,

I have just installed your cont. and it works great, except for the fact that because I am in Florida, and require multiple tax rates, I created zones and tax zones for each county, for example Florida-Manatee Count (FL), etc., but instead of just the zone code appearing on the customer's billing and shipping address when I look at orders placed, I get the whole zone name with the zip code following. I have tried looking for the code in all the pages, changed some to your suggestion of 18 June, 2011, but nothing changed. I really would appreciate any help you can give. I need the zone name in the drop down to apply the correct sales tax, but only the zone code to appear on any output, such as invoice, delivery note etc.
Thanks in advance.

#1130 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 28 June 2011, 20:49

What you need to do is change the address format for the US format (which if I recall is format 1 by default.) Unfortunately there is no interface in osC to actually edit these - all you can do is select among the formats defined. The default format spells out the zone name but you want the zone code instead.

I have customized my shops and am away from my sources so what I am about to suggest may not work right for you. Open your database in PHPMyAdmin or whatever you use. Select table address_format. Insert a new row. The address_format_id should be the next value, probably 2. For address_format enter:

$firstname $lastname$cr$streets$cr$city, $statezone $postcode

and for address_summary, enter:

US

Once you have finished adding the record, go into your osC admin, and select Locations/Taxes > Countries. Find the entry for United Stated and edit it. Change the Address Format to 2 (or whatever the new format ID was in the step above.)

Now you will have to enter a new order and see if the address appears correct, oh and you may have to go back in and create a new address book entry as it will have the old code. What I don't remember is if the standard osC code defines $statezone in the tep_format_address function in includes/general.php. I have customized mine to allow for more flexibility as many countries need specialized formats that the default code doesn't support. I have always had in the back of my head the notion of writing an address format contribution with CORRECT formats for all the countries, but it is daunting work to research each country and get the right format. I've done it for maybe 15 countries so far - there are ten times as many.

All that should be needed is for variable $statezone to be defined in the function to be the zone code. If it is not there you should be able to figure out how to add it. Let me know if you run into trouble and I'll help you Sunday or later.

#1131 adw49

  • Community Member
  • 29 posts
  • Real Name:Andy
  • Gender:Male
  • Location:Sarasota, FL

Posted 30 June 2011, 12:30

View Poststevel, on 28 June 2011, 20:49, said:

What you need to do is change the address format for the US format (which if I recall is format 1 by default.) Unfortunately there is no interface in osC to actually edit these - all you can do is select among the formats defined. The default format spells out the zone name but you want the zone code instead.

I have customized my shops and am away from my sources so what I am about to suggest may not work right for you. Open your database in PHPMyAdmin or whatever you use. Select table address_format. Insert a new row. The address_format_id should be the next value, probably 2. For address_format enter:

$firstname $lastname$cr$streets$cr$city, $statezone $postcode

and for address_summary, enter:

US

Once you have finished adding the record, go into your osC admin, and select Locations/Taxes > Countries. Find the entry for United Stated and edit it. Change the Address Format to 2 (or whatever the new format ID was in the step above.)

Now you will have to enter a new order and see if the address appears correct, oh and you may have to go back in and create a new address book entry as it will have the old code. What I don't remember is if the standard osC code defines $statezone in the tep_format_address function in includes/general.php. I have customized mine to allow for more flexibility as many countries need specialized formats that the default code doesn't support. I have always had in the back of my head the notion of writing an address format contribution with CORRECT formats for all the countries, but it is daunting work to research each country and get the right format. I've done it for maybe 15 countries so far - there are ten times as many.

All that should be needed is for variable $statezone to be defined in the function to be the zone code. If it is not there you should be able to figure out how to add it. Let me know if you run into trouble and I'll help you Sunday or later.

Thanks for the info. I have managed to get the state abbrev. to appear on the invoice, order etc.
Perhaps you may be able to help with a different problem. If I try and change anything on a customers account, for example, they chose the wrong State/County, I can change it but the record is not saved when I hit the update button in admin. I have tried everything I can think of, but nothing makes any difference.
Thanks again.

#1132 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 30 June 2011, 12:57

You'll have to debug the PHP - perhaps the form is not being submitted correctly or the code path when the form is submitted has errors. I generally start out by inserting a "var_dump($_POST);" in the form action code to see what was submitted (this will block the later redirect but that's ok.) I then add various echo or var_dump commands through the code until I understand what went wrong.

#1133 adw49

  • Community Member
  • 29 posts
  • Real Name:Andy
  • Gender:Male
  • Location:Sarasota, FL

Posted 30 June 2011, 18:43

View Poststevel, on 30 June 2011, 12:57, said:

You'll have to debug the PHP - perhaps the form is not being submitted correctly or the code path when the form is submitted has errors. I generally start out by inserting a "var_dump($_POST);" in the form action code to see what was submitted (this will block the later redirect but that's ok.) I then add various echo or var_dump commands through the code until I understand what went wrong.

Thanks Steve, Unfortunately my knowledge of PHP is very limited. I have managed do a work around, by going to the database record via phpMyAdmin, and changing the feild content there. This should only be necessary very occasionally if someone tries to register as Tax Exempt without submitting their FL Tax Certificate, then we just change the zone_id # to the county #. Tested it, it works.
But many thanks anyway.

#1134 minipassat

  • Community Member
  • 81 posts
  • Real Name:minipassat

Posted 18 July 2011, 07:19

Hello,

I searched this topic but can't seem to find what to do: My OSC version is MS2.2, I am trying to instal this contribution to work with FEC (fast easy checkout). I use create_account3.php included in the FEC contribution. Can anyone post the code for this file please? The code provided in the Country-Selector's installation file doesn't match FEC's create_account3.php. I have problem with this instructions:

Line 19

Replace:

if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process')) {
$process = true;

with:

// +Country-State Selector
$refresh = false;
if (isset($HTTP_POST_VARS['action']) && (($HTTP_POST_VARS['action'] == 'process') || ($HTTP_POST_VARS['action'] == 'refresh'))) {
if ($HTTP_POST_VARS['action'] == 'process') $process = true;
if ($HTTP_POST_VARS['action'] == 'refresh') $refresh = true;
// -Country-State Selector

Line 57

Replace:

$error = false;


with:

// +Country-State Selector
if ($process) {
// -Country-State Selector
$error = false;


Line 418

Replace:

if ($process == true) {
if ($entry_state_has_zones == true) {
$zones_array = array();
$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");
while ($zones_values = tep_db_fetch_array($zones_query)) {
$zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
}
echo tep_draw_pull_down_menu('state', $zones_array);
} else {
echo tep_draw_input_field('state');
}
} else {
echo tep_draw_input_field('state');
}

with:

// +Country-State Selector
$zones_array = array();
$zones_query = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = " .
(int)$country . " order by zone_name");
while ($zones_values = tep_db_fetch_array($zones_query)) {
$zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_name']);
}
if (count($zones_array) > 0) {
echo tep_draw_pull_down_menu('zone_id', $zones_array);
} else {
echo tep_draw_input_field('state');
}
// -Country-State Selector


Please help!! Thank you very much!!

#1135 white_fallen_angel

  • Community Member
  • 2 posts
  • Real Name:Angie

Posted 19 July 2011, 22:38

Hello. I have a quick question - I just installed Country-State Selector v1.5.5 (AJAX) and it is working as expected, except one small problem.

I have found that when I start out on create_account page, if i submit the form without completing a mandatory field (ex. name or email address etc.), the page returns with the usual error, which is normal, and everything I typed in before stays the same except that the State in the drop-down list had changed from the correct state I selected before to a default value (ex. Alabama). So the costumers does't see that the state had changed to a default value, he's not paying attention to that, he corrects the other fields needed corrections but they leave the default state in there, and so it manages to create a customer account with the wrong State.

What should I modify in order for the State to remain correctly selected and stop returning to the default value in the drop-down State list after the customers returns on the create_account.php page in order to correct some missing fiels?

Thanks!

#1136 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 19 July 2011, 22:51

angel, in my version (1.4), this code fetches the state or zone_id value from the submitted form:

    if (ACCOUNT_STATE == 'true') {
      $state = tep_db_prepare_input($HTTP_POST_VARS['state']);
      if (isset($HTTP_POST_VARS['zone_id'])) {
        $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
      } else {
        $zone_id = -1; // Country-State Selector
      }
    }

I have not looked at the AJAX version to see what it does.

#1137 white_fallen_angel

  • Community Member
  • 2 posts
  • Real Name:Angie

Posted 20 July 2011, 08:01

Thank you for your quick answer. As my knowledge of PHP is very limited, I think the best solution for me is to uninstall the ajax version and install the 1.4 version.
Thanks!

#1138 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 20 July 2011, 12:01

I will comment that if your knowledge of PHP is "very limited", then you will encounter no end of frustration maintaining an osCommerce store. I encourage you to learn enough PHP to understand the code.

#1139 The Munch

  • Community Member
  • 67 posts
  • Real Name:Scott
  • Gender:Male
  • Location:Iowa, USA

Posted 09 November 2011, 22:59

I've seen this question on here before, but haven't seen an answer for it...

Using the AJAX v1.5.5 on osc 2.3.1. All seems to work correctly except one page - /address_book_process.php. The other pages all work correctly. The process page doesn't load at all - meaning I can select a country, but the states don't repopulate. My default country is 223 USA, so all I get are states on that page. All other pages work fine. I've compared to my heart's content, but can't get this figured out yet.
Thank You!!
----------
Using: OSC 2.3.1, Algozone Template, Jcow 5 Pro, CometChat 4 Premium.

Contributions for OSC-2.3.1: QT Pro 4.6.1, Easy Populate EPv2.77a, Admin Notes, Contribution Tracker, Multi-Product Manager, myQBi Quickbooks Sync, Order Editor 5.0.9, Dynamic Sitemap, Tax ID in Order Editor, Separate Pricing Per Customer v4.2.2 ... etc ...

Contributions for OSC-2.2 I've Modified for OSC-2.3.1: Admin Level Account with Categories 2.3.4, File Logging or Email for Failed Admin Login Attempts, Autologon v1.09, Admin Specials by Categories, CCGV 6.0_1, Hide Categories, How Did You Hear About Us, MSRP Listing, Multiple Sales Per Product, osc as info site, OSC Checkout Security Boost v1.1, Points and Rewards Module, Quick Stock Updater, Quick Updates 292, RMA Returns System 2.6, Show Unit Price, Store Mode, Supplier Admin v1.3, Tell A Friend, Required Customer Details v22rc2a, Admin Change Customers Password v3.3, PDF Invoice & PackingSlip 1.6, Quick Price Updates for SPPC v1.5, Country-State Selector v1.5.5 + Limit Countries v2.2, Contact Us Popup Business Card, No Right Click, Delete Customer Account v1.2, Control Login v2.2, Member Type Control v1.1, .... etc...

#1140 The Munch

  • Community Member
  • 67 posts
  • Real Name:Scott
  • Gender:Male
  • Location:Iowa, USA

Posted 12 November 2011, 16:30

(FOR AJAX v1.5.5 - using osc 2.3.1)...

I don't know if this holds true for everyone, but I just fixed my problem (see previous post #1139).

The instructions say :

Quote

Find:
<?php
if (!isset($HTTP_GET_VARS['delete'])) {
include('includes/form_check.js.php');
}
<?

Replace with:
<?php
if (!isset($HTTP_GET_VARS['delete'])) {
include('includes/form_check.js.php');
// +Country-State Selector
require('includes/ajax.js.php');
// -Country-State Selector
}
?>

Just before this is the require for template_top (for osc 2.3.1):
  require(DIR_WS_INCLUDES . 'template_top.php');
Just above this you have to enter your scripts for the page, so I had to add the function refresh_form here:
<!-- ## BOF: Country-State Selector v1.5.5  ## -->
<script type="text/javascript"><!--
function refresh_form(form_name) {
   form_name.refresh.value = 'true';
   form_name.submit();
   return true;
   }
//--></script>
<!-- ## EOF: Country-State Selector v1.5.5  ## --><?php
  require(DIR_WS_INCLUDES . 'template_top.php');

So you get...

?><!-- ## BOF: Country-State Selector v1.5.5 ## -->
<script type="text/javascript"><!--
function refresh_form(form_name) {
   form_name.refresh.value = 'true';
   form_name.submit();
   return true;
   }
//--></script>
<!-- ## EOF: Country-State Selector v1.5.5  ## --><?php
  require(DIR_WS_INCLUDES . 'template_top.php');
  if (!isset($HTTP_GET_VARS['delete'])) {
    include('includes/form_check.js.php');
/* ## LINE ADD: Country-State Selector v1.5.5  ## */
  require(DIR_WS_INCLUDES . 'ajax.js.php');
   }
?>

I'm not sure why I had to do this yet, as the other files didn't need it (I don't think). I haven't completely checked through this answer to this yet, but it certainly made that final page work for me! If someone knows the answer to this, I would love to be enlightened...

Edited by The Munch, 12 November 2011, 16:36.

Thank You!!
----------
Using: OSC 2.3.1, Algozone Template, Jcow 5 Pro, CometChat 4 Premium.

Contributions for OSC-2.3.1: QT Pro 4.6.1, Easy Populate EPv2.77a, Admin Notes, Contribution Tracker, Multi-Product Manager, myQBi Quickbooks Sync, Order Editor 5.0.9, Dynamic Sitemap, Tax ID in Order Editor, Separate Pricing Per Customer v4.2.2 ... etc ...

Contributions for OSC-2.2 I've Modified for OSC-2.3.1: Admin Level Account with Categories 2.3.4, File Logging or Email for Failed Admin Login Attempts, Autologon v1.09, Admin Specials by Categories, CCGV 6.0_1, Hide Categories, How Did You Hear About Us, MSRP Listing, Multiple Sales Per Product, osc as info site, OSC Checkout Security Boost v1.1, Points and Rewards Module, Quick Stock Updater, Quick Updates 292, RMA Returns System 2.6, Show Unit Price, Store Mode, Supplier Admin v1.3, Tell A Friend, Required Customer Details v22rc2a, Admin Change Customers Password v3.3, PDF Invoice & PackingSlip 1.6, Quick Price Updates for SPPC v1.5, Country-State Selector v1.5.5 + Limit Countries v2.2, Contact Us Popup Business Card, No Right Click, Delete Customer Account v1.2, Control Login v2.2, Member Type Control v1.1, .... etc...