[ic] Discount problem

Scott Kennedy interchange-users@interchange.redhat.com
Wed May 15 12:27:01 2002


Well, I'm still having trouble with this.  I've tried several different things.
Below is the most current code.  In my previous posts on this subject, I
neglected to mention that the discounts weren't being calculated right.  I have
corrected that problem now.  The discounts are supposed to be stacked meaning
that a discount is applied to the total and then another discount is applied to
the discounted total.  In other words, the percentages aren't applied to the
original total (the total of the order before any discounts) unless only one
discount has been selected.

Anyway, the problem is that when the checkout form gets refreshed the newly
discounted total isn't displayed right away.  For example, let's say the order
total is $1,000.  If a 10% discount is selected (please see code below), the
displayed total should be $900 after the checkout form gets refreshed.  Instead,
the total shown is $1,000.  If I refresh the checkout page again the correct
total of $900 is shown.  This same problem happens again as additional discounts
are selected.  Also, I'd imagine that an incorrect total would be shown on the
receipt page if the order were finalized without refreshing the checkout page a
second time first.  Speaking of recalculating the order, the correct order total
will also be displayed if I go to another page and then come back to the
checkout or basket page.  Could someone please tell me what I am doing wrong
here?  I'm sure that my code could be greatly improved and simplified.

/*BEGIN INCLUDED TEXT*/
[comment]
If basket is not empty set discounts otherwise reset discounts if any are set.
[/comment]
[if items]
[mvasp interpolate="1"]
<DIV ALIGN="CENTER">
<TABLE WIDTH="500">
<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>
</DIV>
<%
	$discount1 = 0; $discount2 = 0;
	$discount = 0; $discount = 0;

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

	if ($discounta eq 'on') {
		$discount1 = .2;
	}

	if ($discountb eq 'on') {
		$discount2 = .05;
	}

	if ($discountc eq 'on') {
		$discount3 = .05;
	}

	if ($discountd eq 'on') {
		$discount4 = .1;
	}

	if ($discounta eq 'on' || $discountb eq 'on' || $discountc eq 'on' || $discountd eq 'on') {
		$cartname = $Tag->value('c_nickname');
		$subtotal = $Tag->subtotal($cartname, 'noformat');
		$amount = $subtotal - ($subtotal * $discount1);
		$Tag->discount('ENTIRE_ORDER', $amount);
		$amount = $amount - ($amount * $discount2);
		$Tag->discount('ENTIRE_ORDER', $amount);
		$amount = $amount - ($amount * $discount3);
		$Tag->discount('ENTIRE_ORDER', $amount);
		$amount = $amount - ($amount * $discount4);
		$Tag->discount('ENTIRE_ORDER', $amount);
	}
	else {
		#Reset all discounts if all buttons are set to off
		$Tag->discount('ENTIRE_ORDER');
	}
	return;
%>
[/mvasp]
[else]
[if discount ENTIRE_ORDER][discount ENTIRE_ORDER][/discount][/if]
[value name=discounta set=""]
[value name=discountb set=""]
[value name=discountc set=""]
[value name=discountd set=""]
[/else]
[/if]
/*END INCLUDED TEXT*/


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