Jump to content
stevel

Country-State Selector

Recommended Posts

Hi there,

 

At first, thanks for this contribution, this will prevent frustrated customers i already had on my site.

 

It seems to work but when creating an account i have the following at the top of the "Your Address" box :

 

'' . ENTRY_COUNTRY_TEXT . '': ''); ?>

 

plus

 

At the bottom of the same box there is: ENTRY_COUNTRY instead of just "Country"

 

Does somebody have an idea?

 

Thanks very much


HIM - Dark Light - Out on 26/09/05

Share this post


Link to post
Share on other sites
Sorry I missed that one and it works like a charm!

 

Thanks a lot for your quick response and great help!!

 

- Orverda

 

Hi Steve,

 

I have also included "Gender" as a required field in all froms/pages related to customer address. When customers creat a new account (creat_account.php), change shipping or payment address (checkout_shipping_address.php , checkout_payment_address.php), the defualt setting for both male and female radio buttons are unchecked (not chosen) , which is exactly what I want. But when registered customers to add a new address to his/her address book (address_book_process.php), the FEMALE radio button in the address form is already checked as default. I have seen this problem in most of OSC powered stores I visited so far.

 

I am trying to make the FEMALE button unchecked, but couldn't find any where in address_book_process.php that I could make the change.

 

I know this post could be kind of "other topic", but I couldn't find any clues in entire forums, so I am hoping to get advises from you as to which files are related to this issue that I can work on.

 

Thanks in advance for your help!

 

- Orverda

Share this post


Link to post
Share on other sites

Sandra,

 

It looks as if you made an error in includes/languages/english.php, where these values are defined. Perhaps there's an extra or missing quote somewhere, or these definitions removed? What you want is something like this:

define('ENTRY_COUNTRY', 'Country:');
define('ENTRY_COUNTRY_ERROR', 'You must select a country from the Countries pull down menu.');
define('ENTRY_COUNTRY_TEXT', '* (Page will refresh when changed)');

 

Orverda,

 

An interesting find. In includes/modules/address_book_details.php, this code is responsible for the behavior:

  if (ACCOUNT_GENDER == 'true') {
   if (isset($gender)) {
     $male = ($gender == 'm') ? true : false;
   } else {
     $male = ($entry['entry_gender'] == 'm') ? true : false;
   }
   $female = !$male;

It attempts to detect whether Male was specified either in the form or coming from an existing entry. But then it blindly sets $female "not $male", even if the current entry has neither value set. Try this code instead:

  if (ACCOUNT_GENDER == 'true') {
   if (isset($gender)) {
     $male = ($gender == 'm') ? true : false;
     $female = !$male;
   } else {
     $male = ($entry['entry_gender'] == 'm') ? true : false;
     $female = ($entry['entry_gender'] == 'f') ? true : false;
   }

I have not tested this, but I think it will do the right thing.

Share this post


Link to post
Share on other sites

Sandra,

 

It looks as if you made an error in includes/languages/english.php, where these values are defined. Perhaps there's an extra or missing quote somewhere, or these definitions removed? What you want is something like this:

define('ENTRY_COUNTRY', 'Country:');
define('ENTRY_COUNTRY_ERROR', 'You must select a country from the Countries pull down menu.');
define('ENTRY_COUNTRY_TEXT', '* (Page will refresh when changed)');

 

Hi Stevel,

 

thanks for your prompt reply,

 

I did not have "define('Entry_country", "country:');

 

this solved the problem at the bottom of the "your address box" but i still get the error

'' . ENTRY_COUNTRY_TEXT . '': ''); ?>

at the top of this box. You can see that on my create account page

 

do you have any ideas?

 

thanks very much


HIM - Dark Light - Out on 26/09/05

Share this post


Link to post
Share on other sites

You also need the define for ENTRY_COUNTRY_TEXT. Perhaps a syntax error causes it to not be seen. The error may be on an earlier line. Compare your english.php carefully against the pre-edited one provided in the contribution.

Share this post


Link to post
Share on other sites
You also need the define for ENTRY_COUNTRY_TEXT.  Perhaps a syntax error causes it to not be seen. The error may be on an earlier line.  Compare your english.php carefully against the pre-edited one provided in the contribution.

 

Hi Stevel,

 

I have copied all define-codes which are for the create account from the pre-edited one from the contribution and i still get the error.

 

thanks in advance


HIM - Dark Light - Out on 26/09/05

Share this post


Link to post
Share on other sites

Oh, I see. You have a syntax error in create_account.php which is causing the PHP code to be put out as HTML rather than executed. My guess is that there's a missing or extra quote somewhere near where ENTRY_COUNTRY_TEXT appears in the source.

Share this post


Link to post
Share on other sites
Oh, I see.  You have a syntax error in create_account.php which is causing the PHP code to be put out as HTML rather than executed.  My guess is that there's a missing or extra quote somewhere near where ENTRY_COUNTRY_TEXT appears in the source.

 

Stevel, thanks a lot, you were right and it solved my problem. there was a bit of a mess in create_account.php probably because i just copied the code from the installation file.

 

Thanks a lot for your help and for this great contribution

 

Sandra


HIM - Dark Light - Out on 26/09/05

Share this post


Link to post
Share on other sites
Orverda,

 

An interesting find.  In includes/modules/address_book_details.php, this code is responsible for the behavior:

  if (ACCOUNT_GENDER == 'true') {
   if (isset($gender)) {
     $male = ($gender == 'm') ? true : false;
   } else {
     $male = ($entry['entry_gender'] == 'm') ? true : false;
   }
   $female = !$male;

It attempts to detect whether Male was specified either in the form or coming from an existing entry. But then it blindly sets $female "not $male", even if the current entry has neither value set.  Try this code instead:

  if (ACCOUNT_GENDER == 'true') {
   if (isset($gender)) {
     $male = ($gender == 'm') ? true : false;
     $female = !$male;
   } else {
     $male = ($entry['entry_gender'] == 'm') ? true : false;
     $female = ($entry['entry_gender'] == 'f') ? true : false;
   }

I have not tested this, but I think it will do the right thing.

 

 

Hi Steve,

 

The new code above is working great. Though "wrong topic", I am so glad I aksed the right person - You Are the Solution. Thank You!

 

- Orverda

Share this post


Link to post
Share on other sites
Steve, I was wondering if you could tell me teh advantages of your contribution over the following one:

 

http://www.oscommerce.com/community/contributions,2148

 

Reason being, it only mods 3 files. I currently have a seperate pricing per customer contrib. installed, and im half afraid yours may interfere. I was modding the first file in your install list, and its already dealing with some of the same lines modded in the seperate pricing contribute.

 

Your input is appreciated, thanks.

Share this post


Link to post
Share on other sites

That contribution is a simpler one for stores that sell to primarily one country. One major difference is that if the customer changes the country, the state list does not change to be that of the new country. The customer would have to submit the form, get an error, and then correct the state. Whereas in my contrib, the list refreshes automatically.

 

If you sell to one or two countries only it's a bit simpler than Country-State Selector, but it's not as "general purpose". Pick whichever one best meets your needs.

 

I doubt you'd see much conflict between C-S Selector and a separate pricing contrib.

Share this post


Link to post
Share on other sites

this is what im mainly worried about in the first file im changing.....

 

as per directions for the address_book_process.php file:

Line 191

 

Replace:

 

  if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) {with:

 

// +Country-State Selector

}

 

  if ($refresh) {

    // Recreate $entry from post values collected above

    $entry = array(

      'entry_firstname' => $firstname,

      'entry_lastname' => $lastname,

      'entry_street_address' => $street_address,

      'entry_postcode' => $postcode,

      'entry_city' => $city,

      'entry_state' => "",

      'entry_zone_id' => (int)0,

      'entry_country_id' => (int)$country);

    if (ACCOUNT_GENDER == 'true') $entry['entry_gender'] = $gender;

    if (ACCOUNT_COMPANY == 'true') $entry['entry_company'] = $company;

    if (ACCOUNT_SUBURB == 'true') $entry['entry_suburb'] = $suburb;

    }

  else

// -Country-State Selector

  if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) {

 

at that place in my file I apparently already had edited for SPPC:

// BOF Separate Pricing Per Customer
 if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) {
   $entry_query = tep_db_query("select entry_gender, entry_company, entry_company_tax_id, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "'");
// EOF Separate Pricing Per Customer

 

how exactly should i implement your code into this....just simply do replace the line as stated in your directions or will it mess up the SPPC mod and lose my "company tax id" field? Thanks

Share this post


Link to post
Share on other sites

The code you show from SPPC starts at the line after //- Country-State Selector in the above excerpt. There is no conflict here. I included that last line to make it easy to see where it goes - it doesn't get changed in my contrib.

 

As for the "company tax id" field, you'd want to add it in the places that the other ACCOUNT_ fields are manipulated, including the excerpt above. So you would add a line of the form:

'entry_company_tax_id' => $company_tax_id,

to the array constructor.

Share this post


Link to post
Share on other sites

yes, I realize that the one line that is in the SPPC mod is the same line that is replaced in your mod(but isnt modified). My concern is the following line in the SPPC mod.......im wondering if that will conflict with yours....??

 

The SPPC line that resides after yours is:

    $entry_query = tep_db_query("select entry_gender, entry_company, entry_company_tax_id, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "'");

Share this post


Link to post
Share on other sites

also, is there anywhere else in your mofified code that I need to modify to incorporate for the added "company tax id" field asneed by the SPPC mod?

 

Thanks for your time!

Share this post


Link to post
Share on other sites
yes, I realize that the one line that is in the SPPC mod is the same line that is replaced in your mod(but isnt modified). My concern is the following line in the SPPC mod.......im wondering if that will conflict with yours....??

 

The SPPC line that resides after yours is:

 ? ?$entry_query = tep_db_query("select entry_gender, entry_company, entry_company_tax_id, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "'");

Share this post


Link to post
Share on other sites

I found the following references of "ACCOUNT COMPANY" throughout the install file....

 

if (ACCOUNT_COMPANY == 'true') $entry['entry_company'] = $company;

 

twice:

if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);

 

 

so I simply add "'entry_company_tax_id' => $company_tax_id," after each of those?

Share this post


Link to post
Share on other sites

No. You need to look at what each line is doing for the "company" field and do the same thing for company_tax_id. It's not the same line of code everywhere.

 

In the cases above, you could duplicate the line and replace "company" (lowercase only) with "company_tax_id" and it should work. But you will need to apply some thought to the process.

Share this post


Link to post
Share on other sites

I could use alittle more info, if you would be so nice.

 

I only see the "ACCOUNT_COMPANY" reference in three files:

 

address_book_process.php

checkout_payment_address.php

checkout_shipping_address.php

 

The first looks like it is used to keep the entered info on the page there after the page refreshes. The second two look like the display the comapny info during checkout. Well, the value im interested in adding doesnt need displayed during checkout....so should I skip adding it to the checkout_payment_address.php and checkout_shipping_address.php files? Im really not sure what the address_book_process.php page is even for, so im unsure if I should bother adding the company_tax_id field there or not.

 

All of the above got me wondering.....if the ACCOUNT_COMPANY firls is in these files, why wouldnt it be in other files where the company info field is located, such as the create_account page? I guess im just trying to understand more about how this contribution functions related to the company fields, both for incorporating the company_tax_id field i need(or dont need) to add as well as for helping to learn more about PHP. You can obviously tell im no wizard...it takes me awhile to rough through this stuff.

 

Thanks for your time.

Edited by Sid04

Share this post


Link to post
Share on other sites

what are the :

 

if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);

 

lines in the checkout_payment_address.php and checkout_shipping_address.php files actually doing? I may not even want to add the company tax id section to these depending on what they are there for. Basically, the customer needs to be able to enter the tax id on the create account page page upon registering and has to be able to edit it in their account info section.

Share this post


Link to post
Share on other sites

Those lines are executed when the user submits the page, and sets the variable ($company) in this case from whatever the user put in for the Company field in the form. It skips this if the Company field was disabled in admin.

 

If you are adding fields to the form, then you need lines similar to this to transfer the information from the form to the variable. You don't have to protect the assignment with an if test if you know you'll always want it.

Share this post


Link to post
Share on other sites

currently the company_tax_id field is not included in the checkout pages for the user to alter at that point, so I guess I dont need to add it to your contribution on those pages either?

 

Also, on the address_book_process page....the company_tax_id field can not be altered. It is shown as text, but not in a box that you can change it. Does that matter as far as adding it to your contribution.......do i need to since its not a editable field on that page?

 

What does the address_book_details page deal with? I cant seem to find it >_<

Share this post


Link to post
Share on other sites

address_book_details is in includes/modules. It is common functionality for address book pages. If the company_tax_id is a field in the address book record, then you would add it at least as a hidden form field and a variable so that it gets written to the database properly. Your interest is in making sure the data gets carried along and written to the order record properly.

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

×