Jump to content
stevel

Country-State Selector

Recommended Posts

How many fingers am I holding up? :D  This is a joking way of saying "you haven't supplied enough information for me to make any sort of rational guess."

 

The part of C-S Selector that requires care to integrate with other contribs is its addition of the "refresh" action.  Study what it does when a refresh is done and make sure that it can also do this on your page.  Other contribs may make some assumptions about the actions (for example, assuming that any submission of the form is an attempt to log in or create an account.)

 

Hi Steve,

 

Thanks for the reply, I see it adds the refresh function but I do not know what I should be looking for and adding to my combined login/create account page. Can you elaborate on this further?


Most Valuable OsCommerce Contributions:

Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294

FedEx Automated Labels -- Contribution 2244

RMA Returns system -- Contribution 1136

Sort Products By Dropdown -- Contribution 4312

Ultimate SEO URLs -- Contribution 2823

Credit Class & Gift Voucher -- Contribution 282

Cross-Sell -- Contribution 5347

Share this post


Link to post
Share on other sites

It's not the function but rather the "action". When the form is submitted or the page is refreshed, the code at the top of create_account.php looks at the various POST variables to decide what to do. C-S Selector adds a new possible choice, "refresh", which has to do the appropriate things. Other contributions make their own modifications to the choices made in this code. You have to merge them so that the proper actions get handled properly. This will take careful evaluation of each contribs changes to merge the paths.

Share this post


Link to post
Share on other sites

Hello Steve! You have a great contribution here! So far, I haven't had a problem, but I was wondering if maybe you could take a look at the Purchase Without Account Module and see if you can help those of us who love your module expand it a little.

 

The PWA has seven new files that you upload. Perhaps you could take a look at them or at the two that I suspect need to be changed - Order_Info_Process.php and Order_Info_Check.php. The seven files are:

 

/catalog/Order_Info.php

/catalog/Order_Info_Process.php

/catalog/includes/login_pwa.php (has the boxes stacked vertically)

/catalog/includes/login_pwa_optional.php (this is for side-by-side boxes)

/catalog/includes/login_acc.php

/catalog/includes/modules/Order_Info_Check.php

/catalog/includes/languages/english/images/buttons/button_create_account.gif

 

Any help or insights you can give will, I'm sure, be much appreciated by many of us here at the forum.

Share this post


Link to post
Share on other sites

I did not install the PWA contribution, but a look at the code suggests that the only overlap between it and C-S Selector is catalog/create_account.php. And for that, all you need to do is make the edt, based on the C-S Selector version, as described in the PWA Install_Instructions.txt - the change to the code that checks the e-mail address. None of the other files overlap (except for trivial things such as language file edits.)

 

What problem do you see using both of these?

Share this post


Link to post
Share on other sites

Hello Steve

 

Today I've tried your last version (1.2.0) of Country-State Selector. It is great add-on module and saved a lots of time for me.

 

Playing around with your contrib, I found a little bug. This bug effects only checkout_payment_address.php and checkout_shipping_address.php scripts. For create_account.php and address_book_process.php bug haven't been noticed.

 

When I first time access checkout_payment_address.php or checkout_shipping_address.php from my browser (Mozilla 1.7.8) I see default country (US) with the list of States. When I've tried to change the country to another country without zones (states, provinces, etc.) field "State/Province" has not been cleared and I still see state's name in a normal text input field.

 

Do you know why it happens?

 

Thanks in advance for your help.

 

PS If you will find the same post in different location pls ignore them. I've just started to use this forum and a little bit confused with its interface :'(

Share this post


Link to post
Share on other sites

Oleg,

 

Does your browser have a "Javascript Console" or some other way of seeing Javascript errors? If so, please use that to see what errors it is reporting.

 

I will try this myself to see if I can locate the problem.

Share this post


Link to post
Share on other sites

Steve,

 

Thanks for the quick response. I couldn't see any errors in Mozilla's Javascript console as well.

 

Will be waiting for your fix.

 

Once again thanks a lot for your help

Share this post


Link to post
Share on other sites

Hi Steve,

Thanks for the quick response - and on a holiday weekend, too! I really appreciate you taking the time to look the PWA over.

 

First, let me preface this post by saying that I have to plead ignorance with php. I took computer programming in college (15 years ago!), so I can kind-of understand what's going on, but the syntax throws me.

 

Having said that, the only thing that really worried me when I installed this module, is it replaced one statement that the PWA had changed, although their almost the same:

 

Original:

<td class="main"><?php echo tep_get_country_list('country') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

 

PWA:

<td class="main"><?php echo tep_get_country_list('country', STORE_COUNTRY) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

 

C-S Selector:

<td class="main"><?php echo tep_get_country_list('country',$country,

'onChange="return refresh_form(create_account);"') . ' ' .

(tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT .

'</span>': ''); ?></td>

 

Where I really thought the problem was, is the PWA code from Order_Info_Process.php and Order_Info_Check.php. In your C-S Selector module you change chunks of code and put in " if ($zone_id ==0) { ". I found similar "chunks" in the above two order.php files, so I thought that some similar change might be warranted there. (I'm probably showing my ignorance here.) :blush:

 

- the change to the code that checks the e-mail address. None of the other files overlap (except for trivial things such as language file edits.)

 

What problem do you see using both of these?

 

At any rate, I'm going to do a little studying on php and see if I can answer you more intelligently on the e-mail question and possibly answer my own questions with the PWA mod.

Share this post


Link to post
Share on other sites

Oh, I think I get it. PWA adds NEW pages that look like create_account, and of course you want the C-S Selector functionality there as well. I'm sorry that I misunderstood.

 

I'll see what I can do.

 

Steve

Share this post


Link to post
Share on other sites

Oleg, here's the fix for the problem you found. In both checkout_shipping_address.php and checkout_payment_address.php, find this line:

  if (!isset($country)){$country = DEFAULT_COUNTRY;}

insert on a line before this the following:

  if ($HTTP_POST_VARS['action'] == 'refresh') {$state = '';}

This was a detail I missed when I simplified the JavaScript. Thanks for pointing it out.

Share this post


Link to post
Share on other sites

Hey Steve,

It's me again. I started learning some php and I've been working all week on this PWA (Purchase Without Account) integration. I'm so close to solving this fix, I can taste it; but now I think I need your help.

 

I've gotten to the point on the blank customer form where I get a state pulldown menu, but it's blank and the black "*" (denoting require information) is missing at the end of the box. As I said before, I think the problems are probably somewhere in the two new files "Order_Info_Process.php" and "Order_Info_Check.php". Here are the two main sections I think are the problems.

 

Original code in Order_Info_Process.php:

 

if (ACCOUNT_STATE == 'true') {

    if ($entry_country_error) {

      $entry_state_error = true;

    } else {

      $zone_id = 0;

      $entry_state_error = false;

      $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country) . "'");

      $check_value = tep_db_fetch_array($check_query);

      $entry_state_has_zones = ($check_value['total'] > 0);

      if ($entry_state_has_zones) {

        $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country) . "' and zone_name = '" . tep_db_input($state) . "'");

        if (tep_db_num_rows($zone_query) == 1) {

          $zone_values = tep_db_fetch_array($zone_query);

          $zone_id = $zone_values['zone_id'];

        } else {

          $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country) . "' and zone_code = '" . tep_db_input($state) . "'");

          if (tep_db_num_rows($zone_query) == 1) {

            $zone_values = tep_db_fetch_array($zone_query);

            $zone_id = $zone_values['zone_id'];

          } else {

            $error = true;

            $entry_state_error = true;

          }

        }

      } else {

        if (!$state) {

          $error = true;

          $entry_state_error = true;

        }

      }

    }

  }

I replaced it with:

  if (ACCOUNT_STATE == 'true') {

// BEG Country-State Selector

    if ($zone_id == 0) {

// END Country-State Selector

      if (!$state) {

          $error = true;

          $entry_state_error = true;

      }

    }

  }

 

Original code for Order_Info_Check.php:

  if (ACCOUNT_STATE == 'true') {

?>

          <tr>

            <td class="main"> <?php echo ENTRY_STATE; ?></td>

            <td class="main"> 

<?php

    $state = tep_get_zone_name($country, $zone_id, $state);

    if ($is_read_only) {

      echo tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state']);

    } elseif ($error) {

      if ($entry_state_error) {

        if ($entry_state_has_zones) {

          $zones_array = array();

          $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($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) . ' ' . ENTRY_STATE_ERROR;

        } else {

          echo tep_draw_input_field('state') . ' ' . ENTRY_STATE_ERROR;

        }

      } else {

        echo $state . tep_draw_hidden_field('zone_id') . tep_draw_hidden_field('state');

      }

    } else {

      echo tep_draw_input_field('state', tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

    }

?></td>

          </tr>

<?php

  }

?>

 

I replaced this with:

<?php

//  $state = tep_get_zone_name($country, $zone_id, $state);

// BEG Country-State Selector

    $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']);

    }

//  if (count($zones_array) > 0) {

    echo tep_draw_pull_down_menu('state', $zones_array);

//  } else {

//    echo tep_draw_input_field('state');

//    echo $state . tep_draw_hidden_field('zone_id') . tep_draw_hidden_field('state');

//      echo tep_draw_input_field('state', tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

//  }

  }

//    if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;

 

?>

 

The numerous comments are there because I was playing with lines, commenting this one and seeing what happens. Then commenting another one, etc.

 

I think you said you downloaded the module, so if you need to see any of the seven new files, you should have them. Thanks in advance for your help.

 

CG

Share this post


Link to post
Share on other sites

Great contrib Steve!!! :thumbsup: It appears to work fine with the "Must Agree To Privacy-statement" contrib. THANKS!!!

 

P.S. I did have a similar contrib or maybe something I found in a forum topic that I put in place quite a while ago... it changed the "Please Select" default to (for me) "United States" but it doesn't work because there is no db link behind the default. You get the "Please select a country" error when you try to create or update the user.

 

THE ISSUE: I can't find where I changed that default to save my life!!!! I thought for sure is was going to be in languages->english.php->PULL_DOWN_DEFAULT but that isn't it. I also searched all of the address related files for "United States" and got nothing. Where did I hard code that country???? Any suggestions? Where else would the default dropdown entry be stored?

 

It's not a big issue since the country is defaulted correctly now but it is still bad coding on my site.

 

Thanks again Steve and thanks in advance for the help with the default.

 

Regards,

T-DOGG

Edited by tdogg

Share this post


Link to post
Share on other sites

I'm away from my sources right now, but there are two different things you are talking about.

 

First, the "Please Select" text is added by tep_get_country_list (or something like that) in html_output.php (I think). It's just an initial element defined for the array, and if you are using C-S Selector, you don't really need it at all.

 

Second, the default position in the list is set by one of the arguments to the tep_draw_country_list (?) routine, where you specify the default value (country code), and it locates the item in the list with that ID value and makes it the default. C-S Selector does that for you.

Share this post


Link to post
Share on other sites
...the "Please Select" text is added by tep_get_country_list (or something like that) in html_output.php (I think).

OK...impressed! u were dead on with the file and code:

// Creates a pull-down list of countries
 function tep_get_country_list($name, $selected = '', $parameters = '') {
   $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
   $countries = tep_get_countries();

 

THANK YOU FOR SAVING MY SANITY!!! :wacko:

 

again...contrib works as designed!!! two thumbs up! :thumbsup: :thumbsup:

 

Regards,

TDGG

Share this post


Link to post
Share on other sites

I found the problem. I set Telephon minimum numbers to blank which caused an error and didn't load the file with the refresh function. Problem solved.

 

Does anybody know how to make Date of Birth or Gender not-required, but still show it as an optional entry for the customer to fill in?

 

Chris.....

Share this post


Link to post
Share on other sites

Remove the following lines (they aren't adjacent) from includes/form_check.js.php:

<?php if (ACCOUNT_GENDER == 'true') echo '  check_radio("gender", "' . ENTRY_GENDER_ERROR . '");' . "\n"; ?>
<?php if (ACCOUNT_DOB == 'true') echo '  check_input("dob", ' . ENTRY_DOB_MIN_LENGTH . ', "' . ENTRY_DATE_OF_BIRTH_ERROR . '");' . "\n"; ?>

 

In create_account.php, remove

    if (ACCOUNT_GENDER == 'true') {
     if ( ($gender != 'm') && ($gender != 'f') ) {
       $error = true;

       $messageStack->add('create_account', ENTRY_GENDER_ERROR);
     }
   }

and:

    if (ACCOUNT_DOB == 'true') {
     if (checkdate(substr(tep_date_raw($dob), 4, 2), substr(tep_date_raw($dob), 6, 2), substr(tep_date_raw($dob), 0, 4)) == false) {
       $error = true;

       $messageStack->add('create_account', ENTRY_DATE_OF_BIRTH_ERROR);
     }
   }

Lastly, in includes/languages/english.php, change the values for ENTRY_GENDER_TEXT and ENTRY_DATE_OF_BIRTH_TEXT to an empty string.

Share this post


Link to post
Share on other sites

I made all the edits, everything looks normal. Except when I change the country to something else it submits the form instead of refreshing the page.

 

I have the member approval mod installed so that might have something to do with it, even though it makes very minor changes. Also when I submit the form and then press back, or just leave the page and go back none of the information is there. Probably doesnt have anything to do with it but I just thought I'd mention that.

 

Anyone know what's wrong?

Edited by yatahaze

Share this post


Link to post
Share on other sites

when a customer logs on my site displays product prices including tax

but when they make any changes to the Primary Address,

ie: address line 1 (say, house number to 47 instead of 7)

and stays logged on, it changes the site prices to exclude tax instead of include tax?

 

when the customer logs off and back on again its back to normal?

 

Ive come to the conclusion this has something to do with the..Country-State Selector module.

 

Please help !!

Share this post


Link to post
Share on other sites
Paul,

 

Are you using the latest version of the contrib?  See here for a fix which I incorporated into a later update.

 

Thanks for your help Steve,

 

Just tried this update, didnt make any difference ?

 

The initial version I used was: country-state-selector_1_2_3_4_5_6_7.zip

 

What do you recommend?

 

Regards

 

Paul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×