Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Country-State Selector


stevel

Recommended Posts

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!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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!!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...

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.

Link to comment
Share on other sites

(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 :

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
Link to comment
Share on other sites

  • 3 weeks later...
  • 11 months later...

Hi Everyone

 

I installed the latestest contribution and wanted to install Ajax Price Update.

 

In the instructions of Ajax Price update it is asking me to change some code in /catalog/includes/functions/html_output.php which breaks the state selection when changing country. Just gives the old input box.

 

The code to change is:

 

Replace:

 

$field = '<select name="' . tep_output_string($name) . '"';

 

Replace with:

 

$field  = '<input type="hidden" id="hid_' . tep_output_string($name) . '" value="0" > ';
$field .= '<select onchange="changePrice(this.id)" id="' . tep_output_string($name) . '" name="' . tep_output_string($name) . '"';

 

Anyone can please help me how to get the two contributions to work?

Link to comment
Share on other sites

  • 3 months later...

I have 2.2rc2a version of osC and version 1.4.1 of this fantastic contribution longtime.

 

Just had a country to sell and I recently had to add another. To my surprise I noticed that when you change country refresh_form function does not work.

 

I have installed over 150 contributions in each of my stores and I have to be careful with javascript and ajax, too often in conflict with each other and do not work, so I am forced to look for other options as simple as possible. I can not use AJAX for this reason.

 

I found this solution hopefully help anyone who has the same problem as me and does not want to or can not upgrade version.

 

Basically is to eliminate the function of form_check.js.php refresh_form (if does not work is useless you are in this file) and add it create_account.php, address_book_process.php, checkout_shipping_address.php and checkout_payment_address.php which are the files you really need the function to work.

 

Delete from catalog/includes/modules/form_check.js.php (for osC 2.2rc2a)

<?php // +Country-State Selector ?>
function refresh_form(form_name) {
form_name.action.value = 'refresh';
form_name.submit();
return true;
}
<?php // -Country-State Selector ?>

 

Find in catalog/create_account.php and catalog/address_book_process.php (for osC 2.2rc2a)

<link rel="stylesheet" type="text/css" href="stylesheet.css">

 

And add below

<?php // +Country-State Selector ?>
<script language="javascript"><!--
var selected;
function refresh_form(form_name) {
form_name.action.value = 'refresh';
form_name.submit();
return true;
}
//--></script>
<?php // -Country-State Selector ?>

 

Find in catalog/checkout_shipping_address.php and catalog/checkout_payment_address.php (for osC 2.2rc2a)

//--></script>
<?php require(DIR_WS_INCLUDES . 'form_check.js.php'); ?>

 

And add above

<?php // +Country-State Selector ?>
function refresh_form(form_name) {
form_name.action.value = 'refresh';
form_name.submit();
return true;
}
<?php // -Country-State Selector ?>

 

This works correctly as refresh_form function.

 

Sorry for bad translation, I do not speak English and use a translator online.

 

Best regards from Spain!

Link to comment
Share on other sites

  • 7 months later...

Hello,

 

I've implemented the contribution from v1.5.6 (NimaP, 13/06/2013). My osC version is 2.3.3.4.

 

My state dropdown list doesn't update when I select another country (which of course does have states).

 

The Firefox browser indicates a javascript error:

 

TypeError: getObject(...) is null

 

Unfortunately, I can only trace that back to ajax.js.php

 

Can anyone give me a clue what's causing this problem (or even suggest a solution)?

 

Kind regards,

 

Dennis

Link to comment
Share on other sites

Some further digging into ajax.js.php revealed where I made my 2 mistakes.

 

I omitted (assuming it was "extra"):

 

<div id="indicator"><?php echo tep_image(DIR_WS_IMAGES . 'indicator.gif'); ?></div>

 

I also stripped the following <div> tags from:

 

<div id="states">
<?php
// +Country-State Selector
echo ajax_get_zones_html($country,'',false);
// -Country-State Selector
?>
</div>

 

Both were in retrospect essential for the script to function. After I put them back into my code the script updated the dropdown list just fine.

 

Kind regards,

 

Dennis

Link to comment
Share on other sites

  • 2 months later...

Hi Steve,

 

This is a great add-on. I have one minor question - on the account form under Your Address, the text Country: no longer displays. I looked at both english.php files, but I don't see a syntax error. Any idea where I can fix this.

 

Thanks so much,

JoAnne

Link to comment
Share on other sites

  • 2 years later...

Hi

 

I'm sure this has been asked before, so apologies if I'm repeating myself.

 

I've got the addon installed great on osC v2.3.4 bootstrap (minus the table tags!).

 

I've got the default country set to 222 (United Kingdom) but when you first go on the create_account.php page the dropdown of zones doesn't appear, just a plain text input field. You have to select another country and then re-select UK again for the zone dropdown to then appear.

 

Any ideas how the zone dropdown can be there when you first load the page rather than having to re-select the country?

 

Many thanks

 

Glen

Link to comment
Share on other sites

Hi

 

I'm sure this has been asked before, so apologies if I'm repeating myself.

 

I've got the addon installed great on osC v2.3.4 bootstrap (minus the table tags!).

 

I've got the default country set to 222 (United Kingdom) but when you first go on the create_account.php page the dropdown of zones doesn't appear, just a plain text input field. You have to select another country and then re-select UK again for the zone dropdown to then appear.

 

Any ideas how the zone dropdown can be there when you first load the page rather than having to re-select the country?

 

Many thanks

 

Glen

 

Hi all

 

Please ignore my previous post as I've now fixed the issue.

 

For anyone else experiencing the same issue, I simply hadn't put the following to the /includes/languages/english.php file...

Insert anywhere convenient:
// +Country-State Selector
define ('DEFAULT_COUNTRY', '222');
// -Country-State Selector

Edited by GlenPig
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...