Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Country-State Selector


stevel

Recommended Posts

I recommend that you go over the World Zones contribution carefully and make sure that the zones are correct and, for each country, complete. I have had issues with this contribution in the past.

Link to comment
Share on other sites

Hi Steve and others...

 

Q? On the State selector (works great) but my 1st State by default is Alabama. Some customers tend to skip over this and then their State is left as Alabama even though it really may be Texas.

 

Is there a hack that will make the default State "Please select..." and post an error if not selected??

 

 

Thanks for your time.

 

KJ

define('PROJECTS', 'Something that goes on forever!');

Link to comment
Share on other sites

Hi Steve and others...

 

Q? On the State selector (works great) but my 1st State by default is Alabama. Some customers tend to skip over this and then their State is left as Alabama even though it really may be Texas.

 

Is there a hack that will make the default State "Please select..." and post an error if not selected??

Thanks for your time.

 

KJ

 

I just installed this for a customer (Can't believe it is still immaculate after all this time)

 

I "think" the change I made was

 

catalog/create_account.php

 

echo tep_draw_pull_down_menu('zone_id', $zones_array, STORE_ZONE);

 

Where STORE_ZONE is the selected.

Link to comment
Share on other sites

The change that KJ asked for is in my latest version (1.4.x). Adding the default state in the way you did it will work on the create account page as long as the customer does not get an error filling it out and have to reenter, at which point the state will reset (and won't work if the country is different.) It also doesn't work on the other "address book" pages.

Link to comment
Share on other sites

The change that KJ asked for is in my latest version (1.4.x). Adding the default state in the way you did it will work on the create account page as long as the customer does not get an error filling it out and have to reenter, at which point the state will reset (and won't work if the country is different.) It also doesn't work on the other "address book" pages.

 

Ah ok steve I probably installed 1.4X for my client and was misremembering.

 

I've also noticed people starting to add rubbish to the contribution, such a shame, all the best ones like this get killed by the posting of irrelevant crap.

 

Insaini is a name I've seen doing this before.

Edited by FWR Media
Link to comment
Share on other sites

Ah ok steve I probably installed 1.4X for my client and was misremembering.

 

I've also noticed people starting to add rubbish to the contribution, such a shame, all the best ones like this get killed by the posting of irrelevant crap.

 

Insaini is a name I've seen doing this before.

 

WOW.. you seem like an individual that attacks before knowing anything to begin with.. the contribution i uploaded is EXACTLY the same as the previous versions.. with the difference being ONLY AJAX support .. if you had even looked at the code.. I used stevel's function to the T and only abstracted it to a function (thus instead of having 15 lines of code which are exactly the same in 4 different files.. it is contained now in only 1 file.. ) .. you really should open a couple files.. read and see what the difference is before you open your mouth star..

Link to comment
Share on other sites

I don't understand the attack either. Ajax is a natural fit for this contribution, and was something I thought about doing. It's not for everyone, though. I appreciate Jesse's taking a crack at it.

Link to comment
Share on other sites

WOW.. you seem like an individual that attacks before knowing anything to begin with.. the contribution i uploaded is EXACTLY the same as the previous versions.. with the difference being ONLY AJAX support .. if you had even looked at the code.. I used stevel's function to the T and only abstracted it to a function (thus instead of having 15 lines of code which are exactly the same in 4 different files.. it is contained now in only 1 file.. ) .. you really should open a couple files.. read and see what the difference is before you open your mouth star..

 

Please accept my apologies Insaini. I just get fed up with contributions having loads of rubbish appended to them most of which are useless. I went off "half cocked" because I was having a frustrating evening.

 

I was wrong to direct this at you, especially as I had not viewed your addition.

 

Instead of interacting on the web last night perhaps I should have been reading a page or two from "how to make friends and influence people".

 

<slaps self around head>

Edited by FWR Media
Link to comment
Share on other sites

Please accept my apologies Insaini. I just get fed up with contributions having loads of rubbish appended to them most of which are useless. I went off "half cocked" because I was having a frustrating evening.

 

I was wrong to direct this at you, especially as I had not viewed your addition.

 

Instead of interacting on the web last night perhaps I should have been reading a page or two from "how to make friends and influence people".

 

<slaps self around head>

 

Done and Accepted.. I do know what you mean about a lot of junk be added to contribution pages.. makes it tough to know what to download..

Link to comment
Share on other sites

Done and Accepted.. I do know what you mean about a lot of junk be added to contribution pages.. makes it tough to know what to download..

 

Very gracious of you. Thanks

Link to comment
Share on other sites

No doubt a really simple thing, but I can't see it and would appreciate your help.

 

This evening I noticed my installation of the AJAX country/state selector 1.5.1 was not calling up the saved state when Updating an address. Always showing default Alabama - but all the correct zip, address and country and name info. Will not update the state field, and in fact won't let me off the update page because "a required field " is blank. I'm guessing that would be the state field...

 

To make it even more confusing for me, I have copied the actual files, all of them, from the contribution into place - I had manually changed them a few nights ago, but didn't think I needed to go through that all again. So just copied them all up. New address works fine, jsut update does not. So the source I'm using is exactly what is in the 1.5.1 contribution from April 12.

 

Is there a bug fix I just haven't noticed posted?

 

Thanks

Chris

Link to comment
Share on other sites

No doubt a really simple thing, but I can't see it and would appreciate your help.

 

This evening I noticed my installation of the AJAX country/state selector 1.5.1 was not calling up the saved state when Updating an address. Always showing default Alabama - but all the correct zip, address and country and name info. Will not update the state field, and in fact won't let me off the update page because "a required field " is blank. I'm guessing that would be the state field...

 

To make it even more confusing for me, I have copied the actual files, all of them, from the contribution into place - I had manually changed them a few nights ago, but didn't think I needed to go through that all again. So just copied them all up. New address works fine, jsut update does not. So the source I'm using is exactly what is in the 1.5.1 contribution from April 12.

 

Is there a bug fix I just haven't noticed posted?

 

Thanks

Chris

 

Hmm.. so this is only when updating an address in the 'my account' area and not when creating an account?

 

Let me check

Link to comment
Share on other sites

No doubt a really simple thing, but I can't see it and would appreciate your help.

 

This evening I noticed my installation of the AJAX country/state selector 1.5.1 was not calling up the saved state when Updating an address. Always showing default Alabama - but all the correct zip, address and country and name info. Will not update the state field, and in fact won't let me off the update page because "a required field " is blank. I'm guessing that would be the state field...

 

To make it even more confusing for me, I have copied the actual files, all of them, from the contribution into place - I had manually changed them a few nights ago, but didn't think I needed to go through that all again. So just copied them all up. New address works fine, jsut update does not. So the source I'm using is exactly what is in the 1.5.1 contribution from April 12.

 

Is there a bug fix I just haven't noticed posted?

 

Thanks

Chris

 

Ok I have uploaded the fixed version 1.5.3

 

There are a few small code changes necessary..

 

First open catalog/includes/functions/ajax.php

 

change the function declaration line from

function ajax_get_zones_html($country, $ajax_output = true) {

 

to

function ajax_get_zones_html($country, $default_zone = '', $ajax_output = true) {

 

Next in that same function

change this part

		if ( tep_db_num_rows($zones_query) ) {
		$output .= tep_draw_pull_down_menu('zone_id', $zones_array);	  
	} else {
		$output .= tep_draw_input_field('state');
	}

 

to this

		if ( tep_db_num_rows($zones_query) ) {
		$output .= tep_draw_pull_down_menu('zone_id', $zones_array, $default_zone);	  
	} else {
		$output .= tep_draw_input_field('state', $default_zone);
	}

 

Now open catalog/create_account.php

 

change

						  <?php
			// +Country-State Selector
			echo ajax_get_zones_html($country,false);
			// -Country-State Selector
			?>

 

to this

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

 

Do the same above change to file catalog/includes/modules/checkout_new_address.php

 

Now open catalog/includes/modules/address_book_details.php

 

and change this

				// +Country-State Selector
			echo ajax_get_zones_html($entry['entry_country_id'], false);
			// -Country-State Selector

 

to this

				// +Country-State Selector
			echo ajax_get_zones_html($entry['entry_country_id'],($entry['entry_zone_id'] == 0 ? $entry['entry_state'] : $entry['entry_zone_id']), false);
			// -Country-State Selector

 

 

That should take care of it all

Link to comment
Share on other sites

Ok I have uploaded the fixed version 1.5.3

 

There are a few small code changes necessary..

 

Thanks for taking the time to look at this insaini. Unfortunately - I still have a problem - although slightly improved, because it doesn't show "alabama" every time in edit mode! I applied the entire 1.5.3 version, overwriting everything except languages\english.php which I just left as it was already. In it I have the default state set with define ('DEFAULT_COUNTRY', '223');

 

 

Exact symptoms:

I'm logged in as an existing customer.

I am editing an address in my address book - either the default address or any other existing record in my address book. - via address_book_process.php (url is appended with?edit=number)

Everything looks good, I make my changes and click "update"

Screen refreshes to same address_book_process.php (url is appended with?edit=number) but with changes in all fields except state.

Cannot exit the screen via the update button, but no errors are displayed

Only way out is "back" button or click some other unrelated link

No changes are saved to any part of the address.

 

If you would like to see it in action in my not yet active store, http://www.classicbikebooks.com/ Test user: [email protected] password: letmein

 

Thanks!

Link to comment
Share on other sites

Thanks for taking the time to look at this insaini. Unfortunately - I still have a problem - although slightly improved, because it doesn't show "alabama" every time in edit mode! I applied the entire 1.5.3 version, overwriting everything except languages\english.php which I just left as it was already. In it I have the default state set with define ('DEFAULT_COUNTRY', '223');

Exact symptoms:

I'm logged in as an existing customer.

I am editing an address in my address book - either the default address or any other existing record in my address book. - via address_book_process.php (url is appended with?edit=number)

Everything looks good, I make my changes and click "update"

Screen refreshes to same address_book_process.php (url is appended with?edit=number) but with changes in all fields except state.

Cannot exit the screen via the update button, but no errors are displayed

Only way out is "back" button or click some other unrelated link

No changes are saved to any part of the address.

 

If you would like to see it in action in my not yet active store, http://www.classicbikebooks.com/ Test user: [email protected] password: letmein

 

Thanks!

 

 

Ahhh i think i found the problem..

 

open catalog/address_book_process.php

 

around line 40

  if (isset($_POST['action']) && ($_POST['action'] == 'process')) {

 

change to

  if (isset($_POST['action']) && (($_POST['action'] == 'process') || ($_POST['action'] == 'update'))) {

 

 

Sorry about that.. I will make that change and upload it as a new package hopefully that resolves all issues

 

OH and also ..

 

you may want to put the a css tag for the indicator somewhere in your css file

 

#indicator {
visibility:hidden;
}

 

you can position this as you see fit for your site..

Edited by insaini
Link to comment
Share on other sites

Hi Jesse,

 

I'm just trying to install this on a very modified page here but I am getting an error when i change country from the default...

 

the error is

 

error2.jpg

 

Any ideas what the cause might be?

 

Thanks

 

Dave

Edited by stubbsy
Link to comment
Share on other sites

Hi Jesse,

 

I'm just trying to install this on a very modified page here but I am getting an error when i change country from the default...

 

the error is

 

error2.jpg

 

Any ideas what the cause might be?

 

Thanks

 

Dave

 

The problem i guess is partially my fault i should have realized.. it seems as though you changed the stock osc form name for that page.. the name of the form is usually 'account'

 

youve changed it to 'checkout' not really sure why that is but in any case

 

you need to open /catalog/includes/ajax.js.php

 

and in the getStatesRequest function

 

find the line that begins with document.account and change it to document.checkout .. for the time being.. let me see if I can change that so its not necessary.. as well you have multiple country selections for shipping address and billing address.. ill see if i can modify it so that it works for multiple country selection boxes..

 

but for the time being use the above fix... should work..

 

J

Edited by insaini
Link to comment
Share on other sites

Hi Jesse,

 

I'm just trying to install this on a very modified page here but I am getting an error when i change country from the default...

 

the error is

 

error2.jpg

 

Any ideas what the cause might be?

 

Thanks

 

Dave

 

 

Ive updated the code so that it works with multiple country drop-downs and any form name..

 

code changes..

 

first open catalog/includes/ajax.js.php

 

remove the original two functions named getStates and getStatesRequest

 

and replace with these functions

function getStates(countryID, form, div_element) {
if (request.readyState == 4 || request.readyState == 0) {
	// indicator make visible here..
	getObject("indicator").style.visibility = 'visible';
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var fields = "action=getStates&country="+countryID;

	request.open("POST", 'create_account.php', true);
	//request.onreadystatechange = getStatesRequest;
	request.onreadystatechange = function() {
		getStatesRequest(request, form, div_element);
	};

	request.setRequestHeader("Content-Type", contentType);		
	request.send(fields);
}
}										
//Called when the AJAX response is returned.
function getStatesRequest(request, form, div_element) {
var next = false;
if (request.readyState == 4) {
	// make hidden
	getObject('indicator').style.visibility = 'hidden';
  getObject(div_element).innerHTML = request.responseText;
	if (form.state) {
		form.state.focus();
	} else if (form.zone_id) {
	form.zone_id.focus();
	}
}
}

 

next open catalog/create_account.php

 

change

<?php echo tep_get_country_list('country',$country,'class="formtextinput" onChange="getStates(this.value);"') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?>

 

to

<?php echo tep_get_country_list('country',$country,'class="formtextinput" onChange="getStates(this.value, this.form, \'states\');"') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?>

 

notice the difference in the getStates function call.. two added parameters.. this.form (should never change) and \'states\' this you need to change for any page with multiple country select boxes .. basically if you have a billing select and shipping select change it to be \'billing_states\' and \'shipping_states\' then you also need to change the <DIV element which surrounds the states dropdown in each .. from <div id="states"> to <div id="billing_states"> and for the other one.. shipping states.. should be clear enough?

 

make the above code changes to the files catalog/includes/modules/checkout_new_address.php and catalog/includes/modules/address_book_details.php

 

that should be all there is to it..

 

new package will be uploaded soon..

 

J

Link to comment
Share on other sites

Actually you may just want to download the new package and update manually... ive changed the ajax function and now there is no need to pass in this.form in those function calls anymore ..

 

J

Link to comment
Share on other sites

Hi Jesse,

 

thats still throwing up a runtime error. Any ideas?

 

(btw, the page started off as a page from the FEC contribution so I have no idea why the creator changed the form name)

 

Cheers

 

Dave

Link to comment
Share on other sites

Hi Jesse,

 

thats still throwing up a runtime error. Any ideas?

 

(btw, the page started off as a page from the FEC contribution so I have no idea why the creator changed the form name)

 

Cheers

 

Dave

 

Dave.. I see that you have a link to a file called global.js .. can you post the contents of that file please..

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