Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

Hello everyone,

 

 

I figured since I have been doing some work with the auto state drop down contribution that I would share my insights, trials and tribulations in hopes of making installation easier for other people.:)

 

Now of course you may not have the same contributions installed as I do, but the main ones that concern the auto state drop down are as follows:

 

FEC 3.2 (Fast Easy Checkout)

STS v4.5.8

 

If you read the file included when you download the contribution it will state to edit the create_account.php file. Well edit this one as well as create_accountx.php where x is the number of the file you chose when installing the FEC contribution. I just happened to go with 1)

 

It will tell you to place the below code above the <head> tag.

<?php 
$countries_query = tep_db_query("select countries_id from " . TABLE_COUNTRIES . " order by countries_name");
$cl = array(); $s = ''; 
while ($country = tep_db_fetch_array($countries_query)) {
 $cl[] = $country['countries_id'];
 $s .= $country['countries_id'] . ', ';
}
?>
<!-- hide and disable all state lists before showing list pertaining to currently chosen country //-->
<script language="JavaScript">
 function ShowNewList(){
var id = new Array(<?php echo rtrim($s, ', '); ?>);
var x, item;
for (x = 0; x <id.length; x++)
  { item = document.getElementById(id[x]);
	if (item)
  { item.style.display = 'none'; item.disabled = true;}
}   
var pm = document.getElementById('ctry');
id = pm.value;
var item = document.getElementById(id);
item.style.display = '';
item.disabled = false;
 }
</script>

 

One key distinction between what it requests and what has worked for me is that I had to place the above in the actual template files for create_account and creae_account1. The reason for this is that in testing the script(s) on the server the template system stripped out the above code.

 

Now it requests that you find the below code and move it up above the street address cells. (Note this and the next step are done for each file dealt with in the file. I will only point out the differences where I strayed from the original installation once)

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

 

Directly under the <td class="main"><?php echo ENTRY_COUNTRY; ?></td> add in the below code

<?php
 if (ACCOUNT_STATE == 'true') // activate javascript only if states are used
{$parms = 'id="ctry" onchange="ShowNewList()"';}
 else
{$parms = '';}
 if (isset($HTTP_POST_VARS['country']) && is_numeric($HTTP_POST_VARS['country']))
{$select = $HTTP_POST_VARS['country'];}
 else  // default to store's country if new address
{$select = STORE_COUNTRY;}
?>

 

It also states to change tep_get_country_list('country') to tep_get_country_list('country', $select, $parms)

 

After that find the below code:

	if ($process == true) {
  if ($entry_state_has_zones == true) {
	$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']);
	}
	echo tep_draw_pull_down_menu('state', $zones_array);
  } else {
	echo tep_draw_input_field('state');
  }
} else {
  echo tep_draw_input_field('state');
}

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

 

and replace that code with this bit of code

	   foreach ($cl as $id) {
	  if ($id != $select) //if current list is not for selected country set list to not displayed and disabled
		{$parms = 'style="display:none" disabled ';}
	  else
		{$parms = '';}
	  $parms .= 'id="' . $id . '"'; // set id for list for javascript show/hide process
	  $zones_array = array();
	  $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$id . "' order by zone_name");
	  if (tep_db_num_rows($zones_query) == 0) // if no zones for country draw text field
		{echo tep_draw_input_field('state', '', $parms);}
	  else { // otherwise draw pulldown list of zones
		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, '', $parms);
	  }	  
	}
if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT . '</span>';

 

That should be it for the create_account and create_accountx files. backup the old files, save and upload.

 

Now when it says to put the bit of php code and javascript code in the head section of the address_book_process file, I tried it and it didn't work so move on to the next file and add the code for the head in here otherwise when you select a country it will not do a single thing. By placing the code that was meant for the address_book_process in here above what was line 1 we will see that things start to work once the new includes/modules/address_book_details file is uploaded.

 

Remember to make the needed edits to get the country and state fields in order as we did with the create_account file.

 

Now it says to add the same code into the head area for checkout_payment_address, but this didn't work for me. So I went and added it into the module file checkout_new_address along with the regular updates.

 

Now just follow the remaining steps to customize the customers file in the admin area. Once you have that and every other modified file upload you should be good to go. Hopefully this will help someone else out and save them from the headaches I went through to get this working.

 

Jason

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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