[ic] Setting order discount using JavaScript

Scott Kennedy interchange-users@interchange.redhat.com
Mon May 13 09:23:00 2002


On Mon, 13 May 2002 cfm@maine.com wrote:

|On Sun, May 12, 2002 at 10:19:49PM -0500, Scott Kennedy wrote:
|> 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
|>
|
|Be careful that a visitor cannot alter that javascript and post the
|page with his own discount.  That's a pretty common hack to many
|carts that carry pricing in the page.

Sorry for the previous post.  I looked the code over and I believe that I'm safe
here because the discounts are calculated in the Perl section.

I'm close, I think, to getting this working 100%.  The problem seems to be that
the values aren't updated right away.  For example, let's say I click a radio
button for a 5% discount (please see included code below) to be applied to an
order totalling $100.  When the checkout form gets refreshed, the order total
should be $95.  Instead, it still shows $100.  As I've said before, I have to
monkey with something in order for the true total to be displayed.  Also, the
total may or may not be correct on the receipt page, if something was changed
prior to submitting the checkout form.

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


|--
|
|Christopher F. Miller, Publisher                               cfm@maine.com
|MaineStreet Communications, Inc           208 Portland Road, Gray, ME  04039
|1.207.657.5078                                         http://www.maine.com/
|Content/site management, online commerce, internet integration, Debian linux
|_______________________________________________
|interchange-users mailing list
|interchange-users@interchange.redhat.com
|http://interchange.redhat.com/mailman/listinfo/interchange-users
|


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