X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   check box for "same as billing address" (https://forum.x-cart.com/showthread.php?t=9160)

SMDStudios 01-10-2005 04:25 AM

This appears not necessary for the 4.0.x versions??? Or is this mod just for the thrill of having the info actually populate into the fields? :)

joestern 01-10-2005 04:30 AM

I don't use 4.0x, and I would prefer to have the info populate.

CC 01-16-2005 06:20 AM

As an update to this, find the following, this works in 4.0.9 and should work in 4.0.10

In copybilling.js:
Code:

function InitSaveVariables_shipping(form){
s_firstname = form.s_firstname.value;
s_lastname = form.s_lastname.value; 
s_address = form.s_address.value;
s_address_2 = form.s_address_2.value;
s_city = form.s_city.value;
s_state = form.s_state.value;
_s_state = document.getElementById('_s_state').value;
s_country = form.s_country.value;
s_zipcode = form.s_zipcode.value;
}

function copybilling(form){
if (form.copyb.checked){
InitSaveVariables_shipping(form);
form.s_firstname.value = form.firstname.value;
form.s_lastname.value = form.lastname.value;
form.s_address.value = form.b_address.value;
form.s_address_2.value = form.b_address_2.value;
form.s_city.value = form.b_city.value;
form.s_country.value = form.b_country.value;
form.s_zipcode.value = form.b_zipcode.value;
change_states(document.getElementById('s_country'), 's_state', 'State/Province', '', '', '', '');
form.s_state.value = form.b_state.value;
document.getElementById('_s_state').value = document.getElementById('_b_state').value;
}

else {
  form.s_firstname.value = "";
  form.s_lastname.value = "";
  form.s_address.value = "";
  form.s_address_2.value = "";
  form.s_city.value = "";
  form.s_country.value = form.b_country.value;
  form.s_zipcode.value = "";
  change_states(document.getElementById('s_country'), 's_state', 'State/Province', '', '', '', '');
  form.s_state.value = form.b_state.value;
  document.getElementById('_s_state').value = "";
  }
}


This will carry over names, address lines, states/counties depending on what you have and zip/post code. We only ship in one country so I havent tested the country drop down, but it should work ok.
Only on the checkout signup will this work for names.

On register.php this will not work, as it doesnt ask for a name.
To make it work you need PhilJ's code you need to create a second register_billing_address.tpl such as register_billing_address2.tpl which would look to copybilling2.js with PhilJ's code in.
Using the code above will leave you with JS errors on the page.

The other files are just the same, although I presonally prefer a Button to click instead of a tick box. Looks more professional.

CC 01-16-2005 06:25 AM

I should add, the First name and Last name needs to be removed from the Billling Address info in XC IMO.

I havent got around to removing them yet, but it is stupid that a new customer has to give 3 names on checkout! Thats 6 boxes they have to fill in just to give names.

This IMO is silly as a lot of customers leave sites based on complicated signup forms, this not only looks complicated, it is totally unnecessary.

Not to mention this is open to a security risk or easy mistakes for new customers on signup.

Anyway, cant say too much as that is way off topic. ;)

joestern 01-17-2005 08:00 AM

Thanks for posting the revised code.

Unfortunately, this still does not seem to be working for me.... I am using version 3.x of x-cart, not 4.x Does anyone have any idea whether that might be the cause, and where I would look to see about changing the .js file to fix this for the older version?

The problem I'm having is that I get an error in IE, and when I check the box, it does not populate the new fields. The error I get is:

Code:

Line: 9
Char: 1
Error: Object required
Code: 0



Thanks in advance--I really want to get this working. It's a GREAT mod!

CC 01-17-2005 09:58 AM

Looks like your fields are named differently to the 4.0.x fields.

If you look in the copybilling.js code it is pretty straight forward.
Look to see what your fields are call in 3.x and then match them up the this code.

joestern 01-17-2005 10:20 AM

I looked in 3.x and the fields appear to be the same.

CC 01-17-2005 10:31 AM

#-o

I'll take a look shortly...

joestern 01-17-2005 11:17 AM

I hugely appreciate it. I should say that address_2 in our cart is address2, which I changed in copybilling.js. It fixed an earlier error, but produced the "object required" error in the earlier post.

joestern 01-17-2005 08:29 PM

Update: I've figured out where the problem is, but can't seem to get it fixed.

There are two problems; one I have figured out. The firstname/lastname needed to be "b_firstname" and "b_lastname"...easy.

It also appears that it is the "state" code that is causing a problem. If I remove all of the state code from copybilling.js, it works fine, but of course does not copy the state over. I'm wondering whether 3.x handles the state selection differently than 4.x. Here is my states.tpl file:

Code:

{* $Id: states.tpl,v 1.1.4.3 2004/04/09 07:07:28 svowl Exp $ *}
{if $states ne ""}
<select name="{$name}" {$style}>
{* <option value="XX">Please Select Below</option> *}
{section name=state_idx loop=$states}
<option value="{$states[state_idx].state_code}"{if $default eq $states[state_idx].state_code and $default_country eq $states[state_idx].country_code} selected{/if}>{$states[state_idx].state}</option>
{/section}
</select>
{else}
<input type=text size=32 name="{$name}" value="{$default}">
{/if}


Here's the relevant part of register_billing_address.tpl:

Code:

<tr valign=middle>
<td align=right>{$lng.lbl_state}</td>
<td>{if $states ne ""}<font class=Star>*</font>{/if}</td>
<td nowrap>
{include file="main/states.tpl" states=$states name="b_state" default=$userinfo.b_state default_country=$userinfo.b_country}
</td>
</tr>


Any thoughts would be greatly appreciated.


All times are GMT -8. The time now is 09:09 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.