Click to See Complete Forum and Search --> : Discount Code Help for Noob. Stranded !


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>&nbsp;</td></tr>
CTAB;
break;
}
}
}
if(!$revisedtotal){
$coupontable="<br><center><span style=\"background-color:#ffff44;
border:2px solid #000000\"><b>&nbsp;&nbsp;$cpentered is
invalid or has expired!&nbsp;&nbsp;</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: &nbsp;</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:&nbsp;&nbsp;
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"> $fpt</span>&nbsp;</td>
</tr>
<tr height="25" bgcolor=$bgcolor><td colspan=4
align=right>
$invshiptext $expedited&nbsp;&nbsp;
</td><td align="right" bgcolor=#ffffcc
title="Package weight $ounces OZ.">
<span class="coltot">$shtotShow</span>&nbsp;</td>
</tr>
$taxrow
$revisedtotal
<tr height="25" bgcolor=$bgcolor><td colspan=4 align="right">
Total due for order # $orn:&nbsp;&nbsp;
</td><td align="right" bgcolor=#ffffcc>
<span class="coltot"><b>$totaldue</b></span>&nbsp;</td>
</tr></table> <!-- END MAIN TABLE -->

$coupontable

ShrineDesigns
01-17-2005, 01:30 AM
from what i can see the file "coupons" stores any/all coupon codes in this manner:[name/coupon code] | [%, NULL] | [amount or percentage to deduct] | [experation]

ddewell1
01-17-2005, 07:12 AM
Thanks. But when I try that (see string) I get "12345 is invalid or has expired!"

[test/12345] | [%, NULL] | [.10] | [02/01/2005]

Maybe the format of the coupon name and code or date format I'm using (??))

Not sure.

Thanks for quick reply. the cart is located at www.dadsotr.com.

Any suggestions?

D

DaiWelsh
01-17-2005, 10:37 AM
I think the poster meant name/coupon code to be just one field, the slash was because it could be either as you choose, it just needs to be a single unique string. Similarly, the second field can either be to get a percent discount or anything else to get a fixed discount, therefore:

FIRST|%|10|{date}

would be a 10% discount if they enter "FIRST" as the name/code

FISH| |2|{date}

would be a £2 (or $2 or whaetever) discount if they entered "SECOND" as name/code.

The reason for the {date} is that you need to know what format date it expects - judging by the fact that it just uses > it is probably a unix timestamp (which is why a gui to create this file would be handy) but to be sure, check where $now is set. If it is a timestamp it expects then you can find out what value to use by executing a simple php script like

echo(strtotime("17 January 2005"));

which should output the timestamp fior the entered date (see http://uk2.php.net/strtotime for more format options).

HTH,

Dai

ddewell1
01-17-2005, 12:09 PM
Thanks Dai:

I feel I'm on the right track.

Here is the string I entered in the coupons file.

FIRST|%|10|{2006-04-04 01:59:59}

But still get invalid or expired error.

There is a string $now=time();

Just above the coupon code and then it references it here

if($tcpx[0]==$_POST['coupon'] && $tcpx[3] > $now){

I do not find an echo string anywhere in the PHP file.

a real bugger for this amateur. Unless I try every single date format out there.

??

What am I doing wrong?

Doug

ShrineDesigns
01-17-2005, 02:18 PM
i think he may have used the 'U' (seconds since the Unix epoch, see date function (http://www.php.net/manual/en/function.date.php)) format for the date

ddewell1
01-17-2005, 02:25 PM
How can I delete or null the date validation altogether. To end a discount sale at checkout, I simply edit the coupons file.

Anyone want to create the coupons file the way it should be? Or do I need to do some discovery on my ISP date methods.

I can really do without the whole date thing.

If it's possible to edit the PHP code without Parse errors. (Which is what I get when I remove $now=time();

You guys are really great to be helping like this. It was one of the biggest draws to the cart. I wish I could make this work.

D

ShrineDesigns
01-17-2005, 02:43 PM
i think the easiest way would be to set the experation date of the coupon to 10 or so years into the future, thus, the coupon would be valid for that duration$coupon_date = date('U', mktime(0, 0, 0, 1, 15, 2015));

ddewell1
01-17-2005, 02:56 PM
sounds fine to me. I can just null out or *** in the coupon name field.

But does this go into the PHP code (Where?) or the coupons file at the end of the coupon string?

I can email the php cart file if it will help. I would think it would be easier to see the whole cart for you guys and where in the code this coupon code sits.

Thanks again.

D

ShrineDesigns
01-17-2005, 03:25 PM
sure, i'll pick through it, not too difficult, whoever did this was an amateur

shrinedesigns@yahoo.com

DaiWelsh
01-17-2005, 03:39 PM
I will leave shrine designs to look at your code as he is keen and I am very busy ;) but I would suggest a simple php script to allow editing of this file would be a doddle and that way php can do the date conversion for you, you could just pick the date from dropdowns. If I had more time I would write one myself.

ddewell1
01-17-2005, 04:01 PM
Thanks Dai:

I've sent the file to Shrine Designs. Appreciate your help and attention.

Doug

ddewell1
01-20-2005, 09:43 AM
I think my PHP Patient died on the operating table. Anyone else wnat to take a crack at it?

Thanks

Doug
ddewell1@tampabay.rr.com