Latest News: (loading..)

Archived

This topic is now archived and is closed to further replies.

Supertex

Forcing country selection first, during address creation...

8 posts in this topic

I find myself needing to come up with a solution for situations like this:  Taiwan...no zip, no 'state'.  If I set minimum values to nil, then a bizarre amount of US customers will omit their zip, etc, and have issues during checkout.  So I need to switch the form based on whether or not the address is US.  

 

I plan on moving the country field to the top of the page, but I need to also disable the other fields until the country id is set.  I'm capable of of doing most of what needs to be done, but I need to set and post the country variable first.  I'm sketchy about how to do that.

 

I don't want to reinvent the wheel, so I'm asking:  Has anyone already done something similar, or have any input on the matter?  Concerns?  And as far as I can tell, it will require changes to 4 files:

 

create_account.php

address_book_process.php

checkout_shipping_address.php

checkout_payment_address.php

 

Thoughts?  Tips?

 

 

Share this post


Link to post
Share on other sites

Hi Jack, and thanks for getting back with me.  I'm using 2.3.1.  All the info in my sig is accurate.  I did look through the addons section and didnt see anything except for one or two that force a predetermined country to be selected by default.  Of course, I'm probably searching the wrong keyword...

Share this post


Link to post
Share on other sites

Any of the country state addons will do it but some editing may be needed. This one is the best of them, in my opinion. But you will probably need to also use the world zones. You will need to make a small change to default to a country, if you want. But I don't think that is needed with one of these since they force the correct entries for the chosen country.

Share this post


Link to post
Share on other sites

@@Jack_mcs

 

Thanks for the reply.  Sounds like I need to condense down what it is that I need.  I need to use an 'if-else' (switched on country ID) to change the form itself.  As in, I want to retain "required" status on state and zip for domestic shipments, else have it optional for international orders.  None of the addons I've tried out have done this - they just set a default country, and populate the state drop-down list.

 

Originally, I thought about just putting a country selection page ahead of any other address entry pages, but that seems messy.  

 

Right now, I have THIS addon in place and working.  It uses AJAX to query the states list for a given country, but it doesn't actually set or change $country when the user selects or changes their country.  In addition, I have reordered the fields so that name, email, password, and country are at the top of the page, and the rest of the address fields are disabled until $country is set.

 

I dont know anything about AJAX, but after looking at it, it seems to have its own subroutine for posting data, so I'm assuming that's what I need to modify in order to get the country variable set before the form is submitted...?

 

Regardless...I need to figure out the best way to set $country prior to form submission. 

Share this post


Link to post
Share on other sites

 I haven't tried the one you mentioned so I can't say how it is supposed to work. The one I mentioned has a dropdown for the country and the state. Then the country is chosen the state list is changed to match that country. So the customer can't select a wrong pair, like a US state when the country is Canada.

 

For any of the country code, even the stock, the code will look something like this:

tep_get_country_list('country') . ''

If you change it to

tep_get_country_list('country') . '223'

if will have the US selected on page load. The code for the countries is in the countries database table.

Share this post


Link to post
Share on other sites

@@Jack_mcs

 

I'm with you on the state list matching the country selected.  That's not my problem.  I want to "require" input on the post code field for US addresses, and leave it optional for international addresses.  I also want to enable an additional address line (like 'address 2' or something similar) for international addresses only.  I plan on doing it by using something like:

 

if ($country) != 223 {

     -add extra field-

   }else{

     -do not add field-

   }

 

But I can't do that until the country variable is set, and right now that only happens when the form data is submitted.  I can set a default country but the form itself still needs to change if the customer selects a different country.

Share this post


Link to post
Share on other sites

Somewhere before the posts are checked, add

$country = '223';

That will preset the country to the US (change as desired) and increase the scope of that variable. When the page gets to your code, it should have the selected country. If the customer then selects another country, the page will refresh and that variable will be changed.

 

You may also need to add code to change the state that is recorded if the ACCOUNT_STATE is set to true;

 

This would be handled better with jquery but that might require changes I can't see if your file has been edited.

Share this post


Link to post
Share on other sites