Jump to content
Sign in to follow this  
enigma1

Active Countries

Recommended Posts

Active Countries contribution offers control of the countries table through the osc admin cpanel. In addition the contribution automatically filters the associated states (when present) of the selected country. This approach eliminates selection difficulties visitors experience during the registration process and has no active script dependencies. Multiple modifications are done on the catalog side, to address the 4 areas a user can alter the country information. Those are in the create account, address book change, payment address and shipping address.

 

If only one country is enabled the country drop-down list is replaced by simple text while the requirement asterisk is removed.

 

v1.00 is available to download

 

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

Edited by enigma1

Share this post


Link to post
Share on other sites

After installation I have only 1 country(U.S) active but it is still shown in a dropdown box. Also how do I make the state box into a dropdown box?

 

Thank you

Sean Hawkes

Share this post


Link to post
Share on other sites

Ok, the contribution includes the catalog\ directory. There are some files like the create_account.php This file in the zip archive has this code in it.

 

	if ($process == true) {
  if ($entry_state_has_zones == true) {
	$zones_array = array();
	$zones_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
	$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 {
	$zones_array = array();
	$zones_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
	$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " 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 {
	$zones_array = array();
	$zones_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
	$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);
}

 

because I wanted by default all states in a combo. The default osc has an edit box instead. Should be failry easy to replace (backup first)

 

Now you want to do the same for the other files like for the address change. Now the code for these can be found in the catalog\includes\modules. It is the same code you could replace.

 

 

for the other issue you shouldn't have a drop-down list because the tep_get_country_active_list returns just the text for the country name if just one country is enabled. So double check for the create_account it retrieves this. You should have:

				<td class="main"><b><?php echo ($tmp_object = tep_get_country_active_list('country', $country, 'onChange="this.form.submit();"')) . tep_draw_hidden_field('country_old', $country) . ' ' . (is_array($tmp_object) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></b></td>

 

and double check you have one country selected in the cpanel of the admin.

Share this post


Link to post
Share on other sites

The state dropdown works great now, thank you. But I do only have 1 country selected and I checked the code and I still have a dropdown box for the country. It is not a big deal though and I can live with it the way it is.

 

Thank you

Sean Hawkes

Share this post


Link to post
Share on other sites

well it should not set the drop-list for a single country. If you get a chance can you do a mod as a test to see the number that shows under the drop-down countries box in create_account.php?

 

Here is the code on this I added a line that shows the number of active countries beneath the list:

 

			  <tr>
			<td class="main"><?php echo ENTRY_COUNTRY; ?></td>
			<td class="main"><b><?php echo ($tmp_object = tep_get_country_active_list('country', $country, 'onChange="this.form.submit();"')) . tep_draw_hidden_field('country_old', $country) . ' ' . (is_array($tmp_object) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></b></td>
		  </tr>
<tr><td  class="main"><?php echo count(tep_get_active_countries()); ?></td></tr>

 

Thanks

Share this post


Link to post
Share on other sites

I added your test code and it shows 1 below the country box. Just in case it matters, my web server is running PHP 4.4.0.

 

Sean Hawkes

Share this post


Link to post
Share on other sites

Yes I cannot see refs for the count in php.net and does not make sense because it prints 1 The function tep_get_country_active_list should be like this: (Just optimized it was doing an extra call unecessary but I dont think it causes the problem)

 

////
// Returns a drop-down list of active countries
 function tep_get_country_active_list($name, $selected = '', $parameters = '') {
$countries_array = tep_get_active_countries();
if( count($countries_array) > 1 ) {
  return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
} else {
  return $countries_array[0]['text'];
}
 }

I mean you can see the same check there:

count($countries_array) > 1

will build the drop-down list otherwise it wont.

 

I've tried it with php5 here and one version of php4

Share this post


Link to post
Share on other sites

That did it. Thank you for your help on this, Now that it is working right I think it is the best option I have found for selecting countries and states.

 

Sean Hawkes

Share this post


Link to post
Share on other sites

Hi,

 

I am trying to see what this contribution does but the link given at www.herbalfox.com/us doesn't seemed to work. Is there another demo site to see the country/state effect?


- The Jackal

Share this post


Link to post
Share on other sites

With this contrib you can select from admin which countries are shown in the dropdown box. If only 1 country is selected it is listed without a dropdown box. You can see it at my test site, just click on create account in the login box and you will see it in action.

 

Sean Hawkes

Share this post


Link to post
Share on other sites

Hi Aven today the host does some maintenance for that site you mentioned, but you could try either Sean's page or Mike's There was another one in the readme file.

Share this post


Link to post
Share on other sites

I made a new version available 1.01 that includes a fix for what Sean reported and another fix when a customer changes the country after he places all required information in the form to ensure the form is submitted when the continue button is pressed.

Share this post


Link to post
Share on other sites

I don't know anything about phpMyAdmin.

Can you help a newbie with that? I'm sure it's not a hard thing to do and it will take me like 2 seconds but I've never used it before so I don't know what to do for the sql file.

 

Also is there a program that can be used to search files for a specific string of characters? Like if I wanted to find all of the files in my local catalog directory that contained the word "post code" or something like that. I'm just trying to edit how things look a little bit.

Share this post


Link to post
Share on other sites

The phpmyadmin site is here:

http://www.phpmyadmin.net/home_page/index.php

 

You should d/l it if you have your own server or if you testing on a local machine your shop. Now if you have the phpmyadmin on your host site go and do the following:

 

1. Connect to your phpmyadmin dbase wih your host's cpanel

2. Select your dbase name at the top of the page (probably when you enter is already there)

3. Click the SQL tab

4. Click browse where it says "Location of the text file"

5. Select the sql file included with the package

6. Click go

 

For a good search utility see if there is something in the free software forum. To edit files you could use the phpdesigner but that osc forum has more variety and people have more info.

Share this post


Link to post
Share on other sites

I'm getting this error:

Fatal error: Call to undefined function: tep_not_null() in /homepages/23/d135699034/htdocs/catalog/includes/classes/language.php on line 74

 

I imported the sql before I made the changes to the files but that shouldn't matter, right?

Share this post


Link to post
Share on other sites

no it doesnt matter the order of the install, but where this error happens?. Which page under what conditions?

Share this post


Link to post
Share on other sites

that particular error occurred on the main catalog page.

I also got errors on the product_info.php (when you click on a product) and the my account page and the create account page... although I dont remember what they were.... I already recovered the files needed to make it back to normal.

 

Maybe I just need to try it again.

Share this post


Link to post
Share on other sites

Ok, check the common files for the mods you made. Make sure the general.php and html_output.php files were updated correctly. put those extra functions before the last line in those files.

 

On each these 2 files at the very end should be a line like this

 

?>

 

put the functions above that.

Share this post


Link to post
Share on other sites

That was one of the things you shouldn't do. It does state that explicitly in the readme. Do not override the files with the included ones. Were there for reference only.

Share this post


Link to post
Share on other sites

whoops my fault. I overlooked it somehow.

I'll try to install it again when i'm done working on this other project.

i'll let you know if I get any problems. Thanks.

Share this post


Link to post
Share on other sites

Hi

 

I got your PM

 

Am going to give your mod a go on a fresh install and see what happens - looks good, and slightly easier to install than the 'country-state selector'

 

Was looking for a way to de-select countries.. maybe this is the mod for that (will ask Stev for his opinion if he can do that for country-state too)

 

Thanks


Upon receiving fixes and advice, too many people don't bother to post updates informing the forum of how it went. Until of course they need help again on other issues and they come running back!

 

Why receive the information you require in good faith for free, only to then have the attitude to ignore the people who gave it to you?

 

There's no harm in saying, 'Thanks, it worked'. On the contrary, it creates a better atmosphere.

 

CHOOCH

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
Sign in to follow this  

×