hotnixon2000
asked on
Custom Shipping Script by weight for my shopping cart
I am trying to write a custom shipping by weight script for my shopping cart. However, the script is not working correctly. It is calling the Shipping Method 1 when and item is 1lb or under. It is calling Shipping Method 2 when the order is 1.1lbs to 3 lbs. and it is calling the Shipping Method 3 when the order is over 3 lbs. This is not what I want at all.
Here's a breakdown of what I'm looking to do:
1. If the customer orders anything from 0.1 lbs to 5 lbs I want the shipping to be $3.50/lb
2. If the customer orders anything from 5.1 lbs to 10 lbs I want the shipping to be $2.75/lb.
3. If the customer orders anything from 10.1 lbs to 20 lbs I want the shipping to be $2.15/lb.
4. If the customer orders anything from 20.1 lbs and up I want the shipping to be $1.75/lb.
5. Anything with no weight, would be free shipping.
6. All Shipping methods should be displayed as FedEx Standard Overnight
I thought I had incorporated if and elsif statements to the attached code, perhaps I didn't do it correctly. I am not the most skilled PERL writer so I believe I probably forgot some things as far as creating variables. I greatly appreciate any assistance in this issue.
########################## ########## ########## ########## ########## ########## ########## ########## ##
#########
######### This script bases price on the cart weight.
######### There is a charge per pound.
#########
######### A listing of available variables:
#########
######### $ship_items_found Count Of shippable items
#########
######### $ship_methods_found Count of items with a
######### shipping method already
#########
######### $cart_items_found Count of rows in the cart
#########
######### $cart_quantity_found Total quantity of items
######### in the cart
#########
######### $tracking_subtotal Subtotal of the prices for
######### all items in the cart
#########
######### $cart_total_weight Total weight of all items
######### in the cart in pounds.
#########
######### Directly below, enter in the name for this
######### method to be displayed to the user.
#########
my $ship_meth_name = "Shipping Method 1";
my $price_per_pound = "3.50";
my $ship_total = "0.00";
my $ship_display = "";
my $ship_meth_name1 = "Shipping Method 2";
my $price_per_pound1 = "2.75";
my $ship_total = "0.00";
my $ship_display = "";
my $ship_meth_name2 = "Shipping Method 3";
my $price_per_pound2 = "2.15";
my $ship_total = "0.00";
my $ship_display = "";
#########
######### Figure out what the shipping charge will be by
######### multiplying the weight by the price per pound.
#########
$ship_total = ($price_per_pound * $cart_total_weight);
$ship_total1 = ($price_per_pound1 * $cart_total_weight);
$ship_total2 = ($price_per_pound2 * $cart_total_weight);
#########
######### Format the $ship_total as a price.
#########
$ship_total = sprintf("%.2f", $ship_total);
$ship_total1 = sprintf("%.2f", $ship_total1);
$ship_total2 = sprintf("%.2f", $ship_total2);
#########
######### Create the display based on the price.
#########
if (($ship_total <= "4") && ($ship_total > "0")) {
$ship_display = "$ship_meth_name - $currency_symbol$ship_tota l";
} elsif (($ship_total <= "10") && ($ship_total > "4")) {
$ship_display = "$ship_meth_name1 - $currency_symbol$ship_tota l1";
} elsif ($ship_total > "10") {
$ship_display = "$ship_meth_name2 - $currency_symbol$ship_tota l2";
} else {
$ship_display = "FREE Shipping";
} ######### End of if statement.
#########
######### Print the HTML display for the shipping
######### charge.
#########
print <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">
<TR BGCOLOR="$html_pri_tablero w_color">
<TD VALIGN="TOP"><FONT FACE="$html_small_font_fac e" SIZE="$html_small_font_siz e" COLOR="$html_small_font_co lor"><B>Sh ipping Method</b> <FONT COLOR="$html_notnull_font_ color"><B> $html_notn ull_charac ter</b></f ont><BR><B R></font>
<INPUT TYPE="RADIO" NAME="shipinfo" VALUE="$ship_meth_name\:$s hip_total" CHECKED> <FONT FACE="$html_base_font_face " SIZE="$html_base_font_size " COLOR="$html_base_font_col or">
$ship_display
</font></td>
</tr>
<TR BGCOLOR="$html_alt_tablero w_color">
<TD VALIGN="TOP"><FONT FACE="$html_small_font_fac e" SIZE="$html_small_font_siz e" COLOR="$html_small_font_co lor">Total weight is $cart_total_weight.</td></ tr>
</table>
</center>
<BR>
ENDOFTEXT
Here's a breakdown of what I'm looking to do:
1. If the customer orders anything from 0.1 lbs to 5 lbs I want the shipping to be $3.50/lb
2. If the customer orders anything from 5.1 lbs to 10 lbs I want the shipping to be $2.75/lb.
3. If the customer orders anything from 10.1 lbs to 20 lbs I want the shipping to be $2.15/lb.
4. If the customer orders anything from 20.1 lbs and up I want the shipping to be $1.75/lb.
5. Anything with no weight, would be free shipping.
6. All Shipping methods should be displayed as FedEx Standard Overnight
I thought I had incorporated if and elsif statements to the attached code, perhaps I didn't do it correctly. I am not the most skilled PERL writer so I believe I probably forgot some things as far as creating variables. I greatly appreciate any assistance in this issue.
##########################
#########
######### This script bases price on the cart weight.
######### There is a charge per pound.
#########
######### A listing of available variables:
#########
######### $ship_items_found Count Of shippable items
#########
######### $ship_methods_found Count of items with a
######### shipping method already
#########
######### $cart_items_found Count of rows in the cart
#########
######### $cart_quantity_found Total quantity of items
######### in the cart
#########
######### $tracking_subtotal Subtotal of the prices for
######### all items in the cart
#########
######### $cart_total_weight Total weight of all items
######### in the cart in pounds.
#########
######### Directly below, enter in the name for this
######### method to be displayed to the user.
#########
my $ship_meth_name = "Shipping Method 1";
my $price_per_pound = "3.50";
my $ship_total = "0.00";
my $ship_display = "";
my $ship_meth_name1 = "Shipping Method 2";
my $price_per_pound1 = "2.75";
my $ship_total = "0.00";
my $ship_display = "";
my $ship_meth_name2 = "Shipping Method 3";
my $price_per_pound2 = "2.15";
my $ship_total = "0.00";
my $ship_display = "";
#########
######### Figure out what the shipping charge will be by
######### multiplying the weight by the price per pound.
#########
$ship_total = ($price_per_pound * $cart_total_weight);
$ship_total1 = ($price_per_pound1 * $cart_total_weight);
$ship_total2 = ($price_per_pound2 * $cart_total_weight);
#########
######### Format the $ship_total as a price.
#########
$ship_total = sprintf("%.2f", $ship_total);
$ship_total1 = sprintf("%.2f", $ship_total1);
$ship_total2 = sprintf("%.2f", $ship_total2);
#########
######### Create the display based on the price.
#########
if (($ship_total <= "4") && ($ship_total > "0")) {
$ship_display = "$ship_meth_name - $currency_symbol$ship_tota
} elsif (($ship_total <= "10") && ($ship_total > "4")) {
$ship_display = "$ship_meth_name1 - $currency_symbol$ship_tota
} elsif ($ship_total > "10") {
$ship_display = "$ship_meth_name2 - $currency_symbol$ship_tota
} else {
$ship_display = "FREE Shipping";
} ######### End of if statement.
#########
######### Print the HTML display for the shipping
######### charge.
#########
print <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">
<TR BGCOLOR="$html_pri_tablero
<TD VALIGN="TOP"><FONT FACE="$html_small_font_fac
<INPUT TYPE="RADIO" NAME="shipinfo" VALUE="$ship_meth_name\:$s
$ship_display
</font></td>
</tr>
<TR BGCOLOR="$html_alt_tablero
<TD VALIGN="TOP"><FONT FACE="$html_small_font_fac
</table>
</center>
<BR>
ENDOFTEXT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry - you should change the 4 or the 5 in the if statement so they match up depending on where you want the first boundary.
ASKER
Works like a charm! Thank you. I knew I was making it more complicated than it really was.
No problem and thanks for the points - I'm sure you would have cracked it but sometimes a fresh look at something makes all the difference.