[ic] Setting order discount using JavaScript

Scott Kennedy interchange-users@interchange.redhat.com
Sun May 12 23:15:01 2002


I'm trying to set a discount for the entire order using a combination of
JavaScript and Perl.  The code is on the checkout page which may be found at,

    http://neatway.com/cgi-bin/altchoice/index.html

I believe everything works okay with the code that I've made except for a
couple of things:

  1) When a discount is selected the change to the total order cost isn't
     immediately reflected.  I have to do something such as clicking the
     recalculate button so that I can see the new total.

  2) If something is done to alter the order total (examples: sales tax is added
     in, product quantities are changed, options altered, etc.) and then the
     order gets submitted immediately thereafter, the discount, if one is set,
     is ONLY applied to the OLD order total (the total before anything was
     altered on the checkout page).

Here is the code,

/*BEGIN INCLUDED TEXT*/
[if !items]
[if discount ENTIRE_ORDER][discount ENTRIRE_ORDER][/discount][/if]
[else]
[perl]
        $amount = 0;
	$order_total = $Scratch->{order_total};

        $Document->send("order_total = ", $order_total);
	$Document->send("<BR>");

	$discounta = $Tag->value('discounta');
	$discountb = $Tag->value('discountb');
	$discountc = $Tag->value('discountc');
	$discountd = $Tag->value('discountd');

	if ($discounta eq "on") {
		$amount = $order_total - ($order_total * .2);
	}

	if ($discountb eq "on") {
		$amount = $order_total - ($order_total * .05);
	}

	if ($discountc eq "on") {
		$amount = $order_total - ($order_total * .05);
	}

	if ($discountd eq "on") {
		$amount = $order_total - ($order_total * .1);
	}

	$Document->send("Amount = ", $amount); $Document->send("<BR>");

	if ($amount > 0) {
		$Tag->discount('ENTIRE_ORDER', $amount);
	}
	else {
		$Tag->discount('ENTIRE_ORDER');
	}
[/perl]
<TABLE WIDTH="100%">
<TR><TD COLSPAN="3"><P ALIGN="CENTER" STYLE="font-size: 14pt; color:
blue;"><STRONG>Select your <A HREF="/discounts.html" TARGET="_new"
STYLE="font-size: 14pt;">discounts</A> now!</STRONG></P></TD></TR>
<TR><TD><FONT SIZE="-1"><STRONG>20% &quot;Neatway&quot; Help Yourself
Discount</TD><TD>&nbsp; - &nbsp;</TD><TD>Yes <INPUT TYPE=radio NAME="discounta"
VALUE="on" onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discounta value=on]> No <INPUT TYPE=radio
NAME="discounta" VALUE="off" onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discounta value=off
default=off]></STRONG></FONT></TD></TR>
<TR><TD><FONT SIZE="-1"><STRONG>5% Senior Citizens Discount (proof of age 50
required)</TD><TD>&nbsp; - &nbsp;</TD><TD>Yes <INPUT TYPE=radio NAME="discountb"
VALUE="on" onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discountb value=on]> No <INPUT TYPE=radio
NAME="discountb" VALUE="off" onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discountb value=off
default=off]></STRONG></FONT></TD></TR>
<TR><TD><FONT SIZE="-1"><STRONG>5% Cash Discount</TD><TD>&nbsp; -
&nbsp;</TD><TD>Yes <INPUT TYPE=radio NAME="discountc" VALUE="on"
onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discountc value=on]> No <INPUT TYPE=radio
NAME="discountc" VALUE="off" onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discountc value=off
default=off]></STRONG></FONT></TD></TR>
<TR><TD><FONT SIZE="-1"><STRONG>SPECIAL 10% Limited Time
&quot;Introductory&quot; Discount</TD><TD>&nbsp; - &nbsp;</TD><TD>Yes <INPUT
TYPE=radio NAME="discountd" VALUE="on"
onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discountd value=on]> No <INPUT TYPE=radio
NAME="discountd" VALUE="off" onClick="checkout.mv_click_map.value='Recalculate';
(checkout.mv_click_Recalculate.value='Recalculate') && checkout.submit();
return(false);" [checked name=discountd value=off
default=off]></STRONG></FONT></TD></TR>
</TABLE>
[/else]
[/if]
/*END INCLUDED TEXT*/


As you can see from the code, what I am trying to do here is have the discount
changed as soon as someone clicks on one of the radio buttons.  If a radio
button is selected, the order gets recalculated immediately.

Any help someone could offer me would be greatly appreciated.  I figure that
someone has probably already done what I am attempting to accomplish here.


Thanks in advance,
Scott


***********************************************************
/ Custom Web Promotions /
Economical web hosting & online storefronts featuring
Red Hat Linux 7.2 & Red Hat Interchange 4.8.5
http://custweb.com / 888-287-8932 / sales@custweb.com
***********************************************************