ddewell1
01-16-2005, 08:52 PM
I recently bought a shopping cart in PHP. Now I won't attempt to put on "airs". I'm not a PHP'er. But I have tried enough combos with below script, to know I can't do this without help.
The cart was supposed to come with a discount editor for the script with a GUI interface of his site. I tried for days to ask him for help and he eventually refunded my purchase price. So I have a free Cart without the use of the PHP discount editor.
Arrgghh! I have deciphered enough to know that the script calls for a "coupons" file. If it sees it, it displays the option to the customer to enter a coupon to receive a the discount for that coupon upon checkout.
What I don't know and can't figure out is what I need to do to the script (I think nothing) or what I need to add in PHP or text in the coupons file that will be validated by the script to get the desired discount I want.
On a island...... Thanks
$revisedtotal="";
if(is_file("coupons")){
if($_POST['coupon']){
$cpentered= $_POST['coupon'];
$cpxa=file("coupons");
foreach($cpxa as $cpx){
$tcpx=split("\|",trim($cpx));
if($tcpx[0]==$_POST['coupon'] && $tcpx[3] > $now){
if($tcpx[1]=="%"){
$discount=fmtDec($prodtotal *($tcpx[2] /100));
}else{
$discount=fmtDec($tcpx[2]);
}
if(($prodtotal-$discount) > .01){
$totaldue=fmtDec($grandtotal - $discount);
$couponnum=$tcpx[0];
$revisedtotal=<<<CTAB
<tr height="25" bgcolor=$bgcolor><td colspan=4 align="right">
coupon # $couponnum applied!
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"><b>-$discount</b></span> </td></tr>
CTAB;
break;
}
}
}
if(!$revisedtotal){
$coupontable="<br><center><span style=\"background-color:#ffff44;
border:2px solid #000000\"><b> $cpentered is
invalid or has expired! </b></span></center>";
}
}else{
$coupontable=<<<CTABE
<form name=frmC action=ezcart.php method=post>
<table align=center width=97% style="border:1px solid #808080"
cellspacing=0 cellpadding=3>
<tr><td bgcolor=$color_b>If you have a coupon or discount code,
please enter it here: </td><td><input type=text name=coupon></td>
<td bgcolor=$color_b>
<input type=hidden name=applycoupon>
<input type=submit name=checkout value="Calculate New Total"
title="Click to apply the discount offer">
</td></tr></form></table>
CTABE;
}
}
$orn=getOrderNo();
$cex=time()+864000;
setcookie( "order_no", $orn, $cex, $cookie_path, "$server");
setcookie( "order_no", $orn, $cex, $cookie_path, "www.$server");
$style=style();
$script=getScript2();
if($_COOKIE['customer_zip']=="N/A"){
$orderForm=getCartFILE("international_confirm");
}else{
$orderForm=getCartFILE("domestic_confirm");
}
if($shipclr==$color_a){$bgcolor=$color_b;}else{$bgcolor=$color_a;}
return <<<INVOICE
<html><head> $script $style </head><body bgcolor="$color_body" onLoad="init()">
<table align=center width=97% style="border:1px solid #808080" cellspacing=0 cellpadding=3>
<tr bgcolor=$color_b><th colspan=5> Order No. $orn </th></tr>
<tr bgcolor=$color_b>
<td align="center" width="8%"><span class="colhd">Qty</span></td>
<td align="center" width="8%"><span class="colhd">Ea.</span></td>
<td align="left" width="38%"><span class="colhd">Item</span></td>
<td align="left" width="35%"><span class="colhd">Options</span></td>
<td align="center" width="11%"><span class="colhd">Price</span></td>
</tr>
$rows
<tr height="25" bgcolor=$shipclr><td colspan=4 align="right">
(USD) Order Total:
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"> $fpt</span> </td>
</tr>
<tr height="25" bgcolor=$bgcolor><td colspan=4
align=right>
$invshiptext $expedited
</td><td align="right" bgcolor=#ffffcc
title="Package weight $ounces OZ.">
<span class="coltot">$shtotShow</span> </td>
</tr>
$taxrow
$revisedtotal
<tr height="25" bgcolor=$bgcolor><td colspan=4 align="right">
Total due for order # $orn:
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"><b>$totaldue</b></span> </td>
</tr></table> <!-- END MAIN TABLE -->
$coupontable
The cart was supposed to come with a discount editor for the script with a GUI interface of his site. I tried for days to ask him for help and he eventually refunded my purchase price. So I have a free Cart without the use of the PHP discount editor.
Arrgghh! I have deciphered enough to know that the script calls for a "coupons" file. If it sees it, it displays the option to the customer to enter a coupon to receive a the discount for that coupon upon checkout.
What I don't know and can't figure out is what I need to do to the script (I think nothing) or what I need to add in PHP or text in the coupons file that will be validated by the script to get the desired discount I want.
On a island...... Thanks
$revisedtotal="";
if(is_file("coupons")){
if($_POST['coupon']){
$cpentered= $_POST['coupon'];
$cpxa=file("coupons");
foreach($cpxa as $cpx){
$tcpx=split("\|",trim($cpx));
if($tcpx[0]==$_POST['coupon'] && $tcpx[3] > $now){
if($tcpx[1]=="%"){
$discount=fmtDec($prodtotal *($tcpx[2] /100));
}else{
$discount=fmtDec($tcpx[2]);
}
if(($prodtotal-$discount) > .01){
$totaldue=fmtDec($grandtotal - $discount);
$couponnum=$tcpx[0];
$revisedtotal=<<<CTAB
<tr height="25" bgcolor=$bgcolor><td colspan=4 align="right">
coupon # $couponnum applied!
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"><b>-$discount</b></span> </td></tr>
CTAB;
break;
}
}
}
if(!$revisedtotal){
$coupontable="<br><center><span style=\"background-color:#ffff44;
border:2px solid #000000\"><b> $cpentered is
invalid or has expired! </b></span></center>";
}
}else{
$coupontable=<<<CTABE
<form name=frmC action=ezcart.php method=post>
<table align=center width=97% style="border:1px solid #808080"
cellspacing=0 cellpadding=3>
<tr><td bgcolor=$color_b>If you have a coupon or discount code,
please enter it here: </td><td><input type=text name=coupon></td>
<td bgcolor=$color_b>
<input type=hidden name=applycoupon>
<input type=submit name=checkout value="Calculate New Total"
title="Click to apply the discount offer">
</td></tr></form></table>
CTABE;
}
}
$orn=getOrderNo();
$cex=time()+864000;
setcookie( "order_no", $orn, $cex, $cookie_path, "$server");
setcookie( "order_no", $orn, $cex, $cookie_path, "www.$server");
$style=style();
$script=getScript2();
if($_COOKIE['customer_zip']=="N/A"){
$orderForm=getCartFILE("international_confirm");
}else{
$orderForm=getCartFILE("domestic_confirm");
}
if($shipclr==$color_a){$bgcolor=$color_b;}else{$bgcolor=$color_a;}
return <<<INVOICE
<html><head> $script $style </head><body bgcolor="$color_body" onLoad="init()">
<table align=center width=97% style="border:1px solid #808080" cellspacing=0 cellpadding=3>
<tr bgcolor=$color_b><th colspan=5> Order No. $orn </th></tr>
<tr bgcolor=$color_b>
<td align="center" width="8%"><span class="colhd">Qty</span></td>
<td align="center" width="8%"><span class="colhd">Ea.</span></td>
<td align="left" width="38%"><span class="colhd">Item</span></td>
<td align="left" width="35%"><span class="colhd">Options</span></td>
<td align="center" width="11%"><span class="colhd">Price</span></td>
</tr>
$rows
<tr height="25" bgcolor=$shipclr><td colspan=4 align="right">
(USD) Order Total:
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"> $fpt</span> </td>
</tr>
<tr height="25" bgcolor=$bgcolor><td colspan=4
align=right>
$invshiptext $expedited
</td><td align="right" bgcolor=#ffffcc
title="Package weight $ounces OZ.">
<span class="coltot">$shtotShow</span> </td>
</tr>
$taxrow
$revisedtotal
<tr height="25" bgcolor=$bgcolor><td colspan=4 align="right">
Total due for order # $orn:
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"><b>$totaldue</b></span> </td>
</tr></table> <!-- END MAIN TABLE -->
$coupontable