📄 ccship.pl
字号:
# CyberCart Pro Internet Commerce System, Version 3.04
# Copyright 1997, Richard Torzynski
# 1-25-98
# All rights reserved
# Routines for calculating shipping cost for CyberCart
# Place this file in the merchant data directory defined in the
# variable $merchant_data in cybercart.pl
sub ship {
# Calculate shipping and get billing info
&check_form;
# Skip the shipping page if there is no shipping cost
if ($shipping_cost eq "none") {
&billing;
exit;
}
# Check to see if international ok
if ($post_query{'country'} ne $shipping_base && $no_world_shipping) {
print "<h1>International Orders</h1>\n";
print "I'm sorry, but $company does not ship orders outside the United
States.\n";
print "<p>";
&footer;
exit;
}
print "<center>\n";
print "<h1>Shipping Method</h1>\n";
print "</center>\n";
&show_order;
&show_ship;
}
# End sub ship
#--------------------------------------------------------
sub show_ship {
# Show shipping options, if there are any
if (%delivery_method) {
# This is where the merchant has a simple drop down of shipping choices
print qq(
<center>
<table border=1 cellspacing=0 cellpadding=10 width="$Table_width" bgcolor=$Table_Header_Color>
<tr align=left><td colspan=2 bgcolor=$Table_Body_Color>
);
if ((keys (%delivery_method) + keys(%ups_cost)) > 1) {
print "<pre><b><u>Choose Shipping:</u></b>\n</pre>";
} else {
print "<pre><b><u>Shipping:</u></b>\n</pre>";
}
print qq(
</td>
<tr>
<th align=left>Method</th>
<th align=right>Cost</th>
</tr>
);
foreach $key (keys %delivery_method) {
print "<tr bgcolor=$Table_Entry_Color><td>";
print "<input type=radio name=ship_cost value=\"$key\-$delivery_method{$key}\">$key";
print "</td><td align=right>";
print "\$$delivery_method{$key}</td></tr>";
}
} elsif (($shipping_cost eq "actual" && $post_query{'country'} eq "US") ||
($world_shipping_cost eq "actual" && $post_query{'country'} ne "US") ||
($shipping_cost =~ m/special/ && $post_query{'country'} eq $shipping_base) ||
($world_shipping_cost =~ m/special/ && $post_query{'country'} ne $shipping_base)) {
# Files need for calculating shipping rates.
$zone_chart_dir = $shipping_dir . "Zones/";
# If merchant is using actual UPS and USPS Shipping Rates
print qq(
<center>
<table border=1 cellspacing=0 cellpadding=10 width=580 bgcolor=\#$Table_Header_Color>
<tr align=left><td colspan=2 bgcolor=$Table_Body_Color>
);
if ((keys (%delivery_method) + keys(%ups_cost)) > 1) {
print "<pre><b><u>Choose Shipping:</u></b>\n</pre>";
} else {
print "<pre><b><u>Shipping:</u></b>\n</pre>";
}
print qq(
</td>
<tr>
<th align=left>Method</th>
<th align=right>Cost</th>
</tr>
);
# Routine for special shipping charts
if ( ($shipping_cost =~ m/special/ && $post_query{'country'} eq $shipping_base) ||
($world_shipping_cost =~ m/special/ && $post_query{'country'} ne $shipping_base)) {
&special_shipping;
} elsif ($post_query{'country'} eq "US") {
&us_rate;
&ups;
&usps;
} elsif ($post_query{'country'} eq "Canada") {
&ups_canada_zone;
&ups_canada_rate;
} elsif ($post_query{'country'} ne "US"){
&world_zone;
&world_ups_express;
&world_ups_expedited;
}
foreach $key (keys %ups_cost) {
print "<tr bgcolor=$Table_Entry_Color><td>";
if ($ups_cost{$key} > 1) {
$ups_cost{$key} += $handling;
if ((keys (%delivery_method) + keys(%ups_cost)) > 1) {
print "<input type=radio name=ship_cost value=\"$key-$ups_cost{$key}\">\n";
} else {
print "<input type=hidden name=ship_cost value=\"$key-$ups_cost{$key}\">\n";
}
print "$key</td>";
if ($no_decimal) {
printf "<td align=right>%5.0f", $ups_cost{$key};
} else {
printf "<td align=right>%5.2f", $ups_cost{$key};
}
print "</td></tr>";
} else {
print "$key</td><td align=right>N/A</td></tr>\n";
}
}
} elsif ($shipping_cost eq "None") {
# Just print button if shipping cost are included in the price
print qq(
<center>
<input type=hidden name=processing value=$post_query{'processing'}>
<input type=hidden name=action value="billing">
<input type=submit value="Continue">
);
}
foreach $key (keys %post_query) {
# print all the form variables passed
if ($key ne "action") {
print "<input type=hidden name=\"$key\" value=\"$post_query{$key}\">\n";
}
}
if (%delivery_method || ($shipping_cost eq "actual" && $post_query{'country'} eq "US") ||
($world_shipping_cost eq "actual" && $post_query{'country'} ne "US") ||
($shipping_cost =~ m/special/ && $post_query{'country'} eq $shipping_base) ||
($world_shipping_cost =~ m/special/ && $post_query{'country'} ne $shipping_base) ) {
# print button as part of the shipping choice table
print qq(
<tr>
<td colspan=2 bgcolor=$Table_Body_Color><center>
<input type=hidden name=processing value=$post_query{'processing'}>
<input type=hidden name=action value="billing">
<input type=submit value="Continue">
</td></tr></table></center>
);
} elsif (($shipping_cost ne "none" && $post_query{'country'} eq $shipping_base) ||
($world_shipping_cost ne "none" && $post_query{'country'} ne $shipping_base)) {
# print shipping cost and button if flat,percentage,table, weight, or items
&shipping;
if ($shipping > 0) {
print qq(
<center>
<table border=1 cellspacing=0 cellpadding=10 width=\"$Table_width\" bgcolor=$Table_Body_Color\>
<tr>
<td colspan=2 bgcolor=$Table_Header_Color align=center>
<h2>Shipping Cost</h2>
</td></tr>
<tr>
<td bgcolor=$Table_Entry_Color>
$mod
);
if ($show_table && $post_query{'country'} eq $shipping_base) {
print "<pre>$show_table</pre>";
} elsif ($world_show_table && $post_query{'country'} ne $shipping_base) {
print "<pre>$world_show_table</pre>";
}
print qq(
</td>
<td align=right valign=top bgcolor=$Table_Body_Color>
);
if ($no_decimal) {
printf "\$%5.0f", $shipping;
} else {
printf "\$%5.2f", $shipping;
}
print qq(
</td>
</tr>
<tr><td colspan=2 align=center bgcolor=$Table_Header_Color>
<input type=hidden name=processing value=$post_query{'processing'}>
<input type=hidden name=action value="billing">
<input type=submit value="Continue">
</table>
</center>
);
} else {
print qq(
<center>
<input type=hidden name=processing value=$post_query{'processing'}>
<input type=hidden name=action value="billing">
<input type=submit value="Continue">
);
}
}
print "</form>\n";
print "<p>";
&print_links;
&footer;
}
# End sub show_ship
#----------------------------------------------------------
sub shipping {
# Calcuate shipping cost
if ($post_query{'country'} ne $shipping_base) {
$shipping_cost = $world_shipping_cost;
}
if ($shipping_cost eq "percent") {
# to apply a straight percentage shipping cost:
if ($post_query{'country'} ne $shipping_base) {
$shipping_modifier = $world_shipping_modifier;
}
$shipping = $shipping_modifier * $order_total;
$perc = 100 * $shipping_modifier;
$mod = "Shipping \@ $perc\%";
if ($min_shipping && $shipping < $min_shipping) {
$shipping = $min_shipping;
}
print "<input type=hidden name=ship_cost value=\"$mod\-$shipping\">";
if ($min_shipping) {
$mod .= " (Minimum shipping: \$$min_shipping) ";
}
} elsif ($shipping_cost eq "flat") {
# to have one shipping cost:
if ($post_query{'country'} ne $shipping_base) {
$shipping_modifier = $world_shipping_modifier;
}
$shipping = $shipping_modifier;
$mod = "Shipping \@ Flat Rate";
print "<input type=hidden name=ship_cost value=\"$mod\-$shipping\">";
} elsif ($shipping_cost eq "table") {
if ($post_query{'country'} ne $shipping_base) {
%ship_table = %world_ship_table;
}
$mod = "Shipping Table";
foreach $range (sort keys %ship_table) {
($low,$high) = split(/-/,$range);
if ($order_total >= $low && $order_total < $high) {
$shipping = $ship_table{$range};
print "<input type=hidden name=ship_cost value=\"Shipping\-$shipping\">";
}
}
} elsif ($shipping_cost eq "items") {
# use table for shipping
if ($post_query{'country'} ne $shipping_base) {
%ship_table = %world_ship_table;
}
$mod = "Shipping Table";
foreach $range (sort keys %ship_table) {
($low,$high) = split(/-/,$range);
if ($num_items_ordered >= $low && $num_items_ordered <= $high) {
$shipping = $ship_table{$range};
print "<input type=hidden name=ship_cost value=\"Shipping\-$shipping\">";
}
}
} elsif ($shipping_cost eq "percent_table") {
# use percent table for shipping
if ($post_query{'country'} ne $shipping_base) {
%ship_table = %world_ship_table;
}
$mod = "Shipping Table";
foreach $range (sort keys %ship_table) {
$per = $ship_table{$range}*100;
($low,$high) = split(/-/,$range);
if ($order_total >= $low && $order_total < $high) {
$shipping = $ship_table{$range} * $order_total;
if ($min_shipping && $shipping < $min_shipping) {
$shipping = $min_shipping;
}
print "<input type=hidden name=ship_cost value=\"Shipping\-$shipping\">";
}
}
if ($min_shipping) {
$mod .= " (Minimum shipping: \$$min_shipping) ";
}
} elsif ($shipping_cost eq "weight") {
# use weight
if ($post_query{'country'} ne $shipping_base) {
%ship_table = $world_ship_table;
}
foreach $range (keys %ship_table) {
($low,$high) = split(/-/,$range);
if ($total_wt >= $low && $total_wt < $high) {
$shipping = $ship_table{$range};
print "<input type=hidden name=ship_cost value=\"Shipping\-$shipping\">";
}
}
} elsif ($shipping_cost eq "per_item") {
# use per item
# Shipping value already set in show_order routine
$mod = "Shipping Cost on Per Item Basis";
print "<input type=hidden name=ship_cost value=\"$mod\-$shipping\">";
} else {
$shipping="Not able to calculate";
}
if ($min_shipping && $shipping < $min_shipping && $post_query{'country'} eq $shipping_base) {
$shipping = $min_shipping;
} elsif ($min_world_shipping && $shipping < $min_world_shipping && $post_query{'country'} ne $shipping_base) {
$shipping = $min_world_shipping;
}
if ($max_shipping && $shipping > $max_shipping && $post_query{'country'} eq $shipping_base) {
$shipping = $max_shipping;
} elsif ($max_shipping && $shipping > $max_shipping && $post_query{'country'} ne $shipping_base) {
$shipping = $max_world_shipping;
}
}
# end sub shipping
#----------------------------------------------------#
sub us_rate {
# Determine UPS zone
# zone chart: zip,ground,3-day select,2nd day air, 2nd day air am,
# next day airsaver, next day air
# Define the files needed.
$upsgr = $shipping_dir . "Gndres.csv";
$ups2da = $shipping_dir . "2da.csv";
$ups2dam = $shipping_dir . "2dam.csv";
$ups1d = $shipping_dir . "1da.csv";
$ups1ds = $shipping_dir . "1dasaver.csv";
$ups3d = $shipping_dir . "3ds.csv";
$uspspm = $shipping_dir . "uspspm.csv";
$uspsem = $shipping_dir . "uspsem.csv";
$uspsmp = $shipping_dir . "uspsmp.csv";
$uspsnmp = $shipping_dir . "uspsnmp.csv";
# Determine which merchant zip to us. This can also be set in the
# $zone_chart variable in the merchant setup file. If its not there,
# this routine will search the directory containing the files.
# Get the first three digits in the zip
$mzip = substr($merchantzip,0,3);
# routine to look through zone chart files and determine the right one
# to use.
if (!$zone_chart) {
opendir UPS, "$zone_chart_dir" || &error("Cant open $zone_chart_dir at line 511");
@allfiles = readdir UPS;
foreach $a (sort @allfiles) {
($z,$gar) = split(/\./,$a);
if ($mzip < $a) {
$zone_chart = $zone_chart_dir . "$prevfile";
last;
} else {
$prevfile = $a;
}
}
}
# First three digits of customers zip
$zip3 = substr($post_query{'zip'},0,3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -