How do I calculate shipping as a percent rather than a specific dollar amount?greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread |
The S-Mart cart I'm setting up needs to calculate the "shipping" amount as 5-percent of the total price (instead of a fixed dollar amount), AND then add 8.25-percent (California) on top of that if the user chooses the CA tax selection. Is there a way to define this with a shipping option in the S-mart.cgf file. Or will I have to (cringe) hack the CGI? Anyone have any site running this way? In other words: subtot * 0.05% * .0825-if-selected = total instead of subtot + $7.00 * .0825-if-selected = totalthanks,
-- Chad P. (bobbob42@hotmail.com), July 28, 1999
Hi,You will have to change "smart.cgi" and "smart.cfg" for shipping. In "smart.cfg" find this.
elsif ($shipping eq '4') { my($low,@prices); @prices = sort number keys %shipping; $low = $prices[0]; foreach $price (@prices) { if ($price > $low && $price <= $totalprice) {$low = $price}; } $shipamt = $shipping{$low}; $totalprice += $shipamt; }
Change this line.
$shipamt = $shipping{$low};
To this.
$shipamt = int(($shipping{$low} * $totalprice) * (10 ** 2) + .5) / (10 ** 2);
There are three places you have to change. Make sure you change them all.
Change in the "smart.cfg" this.
# Shipping #######################
# 0 = No shipping # 1 = Shipping by number of items # 2 = Non-variable shipping # 3 = Shipping by weight # 4 = Shipping by price
$shipping = "4";
Change $shipping to = 4
Then change this.
# For shipping by price: # (price,shipping,price,shipping,etc) if ($shipping eq '4') { %shipping = ('0.00','0.00','0.01','0.05'); }
Change the %shipping to look like above.
For your tax change in the "smart.cfg" to look like this.
# Death and taxes. ######################## # 0 = No taxes calculated. # 1 = Calculate Tax by State # 2 = Always calculate tax
$tax = "1";
# Default tax amount, if state is not specified, or if tax is always calculated # Example: You live in Ohio, so you have to charge sales tax to Ohio residents; # set $taxamt = "0" (as a default) and then set OH to '.065' as shown below.
$taxamt = "0";
if ($tax eq '1') { %taxes = (CA, '0.0825') }
In your "order.html" if you replace the state box to a drop down box with a two letter state code it will add in the right tax for you. If you do not do that you will not get the tax right. If you go to my web site you can copy a "order.html" I have there. Or send me an e-mail and I will send you the file. Change the html link and e-mail to your site. http://www.team-blank ets.com/s-order.html
Jim
-- James L. Farmer (jim@team-blankets.com), July 28, 1999.
Thank you Jim, you are a genius! Not only was your suggesion speedy and easy-to-understand, it also worked perfectly the first time!!! Good script, a convenient message area, and helpful people: this stuff is great! Thank you very much, -chad "yehaw!"
-- Chad P. (bobbob42@hotmail.com), July 29, 1999.
The only thing I see missing is excluding the credit card numbers from the email to the client. Just modify as follows:
-- Kevin (keving@businesswebworks.com), August 01, 1999.
Hi,The exclude is at the top of the "order.html" file.
INPUT type=hidden name=exclude value="cardtype,cardnumber1,cardnumber2,cardnumber3,cardnumber4,expire month,expireyear "
Jim
-- James L. Farmer (jim@team-blankets.com), August 01, 1999.