I will pay $20.00 to YOU!!!

greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread

I will pay $20.00 to whomever can help me fix my problem... (1st come 1st served)

I added the below code and a few other small snippets of code to my Shopping Cart script to have the ability to give someone a Gift Certificate ID Number to put in their order form for a discount. It reads a TXT file database where each Gift Certificate ID is on a different line in the format of the ID being first, then a separator line ( | ) and then the dollar amount of that Gift Certificate and then subtracts the Gift Certificate amount from the sale total. It works PERFECT and it looks like SM11562|1.00

Now I am trying to add something to it so that it will see the amount of the Gift Certificate ID as a percentage as well as a dollar amount like SM11562|10%

In the code below, you will see the newly added code commented out with #'s. It looks ok to me, but if I have the order form call on a percentage amount like SM11562|10%, the script will not execute and gives me a misconfiguration error or it will only subtract the number (ie: subtract 10 instead of 10%). The problem is in the new code. Can someone please take a look at it and see what you think will fix it for me please?

--------------------------------------------------- sub buy_items2 { &check_required; if ($useverify eq '1') { &CC_Verify; } if ($FORM{'gift_certificate'}) { $gift_cert=1; open (FILE,"$discount_file"); @CONTENTS=; close(FILE); $SIZE=@CONTENTS;

for ($i=0;$i<$SIZE;$i++) { $_=$CONTENTS[$i]; ($cert_id, $cert_discount) = split(/\|/,$_); if ($FORM{'gift_certificate'} eq $cert_id) { # if ($cert_discount =~ /.*\%/) { # ($percentage,$null) = split(/%/,$cert_discount); # $discount = ($totalprice*$percentage)/100; # $discount =~ s/(.*)\.(\d\d).*/$1\.$2/; # # $totalprice=$totalprice-$discount; # } # else { $discount=$cert_discount; $totalprice=$totalprice-$discount; # } } } } else { $gift_cert=0; }

&send_order; ---------------------------------------------------

-- Scott Moore (admin@giftworld.net), May 16, 1998

Answers

well it's alittle late but maybe other pple will read this dont mkae it so complicated dont use 1% or 10% use just |10|

then in the code take $totalprice = $totalprice - ($totalprice * ($discount / 100)); saves the hassle of all the extra programnig you'd have to do trying to seperate the %'s and should handle the formula as well

-- Chris Ward (webmaster@cuztomcomputerz.hypermart.net), May 08, 1999.


You can try 0.10 to calulate the discount it should work because that is how the tax rate is figured. Just change add to total to subtract total. Jim

-- James L. Farmer (jim@team-blankets.com), May 26, 1999.

Moderation questions? read the FAQ