Z
zig
Hi - I'm relatively new to Perl and I'm looking to write a custom
script to be used with ClickCartPro for calculating shipping rates.
Normally this is relatively straightforward but I would like to declare
two conditions at the same time: determine which country to ship to
dependant upon the variable '$fd_trackitem_shipcountry' and then
calculate the shipping in that category based upon the total quantity.
So far I have the script below but it returns the correct country +
'Rest of the World' and the base price for 1 unit.
If anyone has the time to look and possibly verify my script, I would
be very oblidged:
######### My rather poor attempt at
######### re-arranging the order
######### of the statements.
#########
######### First declaration:
#########
#########
$custom_code_result = "";
my $ship_meth_name1 = "UK Delivery";
my $ship_total1 = "0.00";
my $ship_display1 = "";
if ($item_quantity = "1") {
$ship_total1 = "2.00";
}elsif ($item_quantity = "2") {
$ship_total1 = "2.50";
}elsif ($item_quantity = "3") {
$ship_total1 = "3.50";
}elsif ($item_quantity = "4") {
$ship_total1 = "4.00";
}elsif ($item_quantity > "4") {
$ship_total1 = "4.00";
}
if (($fd_trackitem_shipcountry eq "United
Kingdom")||($fd_trackitem_shipcountry eq "Highlands & Islands
Scotland")
||($fd_trackitem_shipcountry eq "Isles Of
Scilly")||($fd_trackitem_shipcountry eq "Isle of
Man")||($fd_trackitem_shipcountry eq "Channel
Islands")||($fd_trackitem_shipcountry eq "Northern Ireland")){
$ship_display1 = "$ship_meth_name1 - $currency_symbol$ship_total1";
$ship_total1 = sprintf("%.2f", $ship_total1);
$custom_code_result .= <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" >
<TR BGCOLOR="$html_pri_tablerow_color">
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid"
VALUE="$ship_meth_name1\:$ship_total1" CHECKED> <FONT
FACE="$html_base_font_face" SIZE="$html_base_font_size"
COLOR="$html_base_font_color">
$ship_display1
</FONT></TD>
</TR>
</TABLE>
</CENTER>
<BR>
ENDOFTEXT
}
######### Second set of declarations:
#########
#########
#########
#########
#########
#########
my $ship_meth_name2 = "European Delivery";
my $ship_total2 = "0.00";
my $ship_display2 = "";
if ($item_quantity = "1") {
$ship_total2 = "3.00";
}elsif ($item_quantity = "2") {
$ship_total2 = "4.00";
}elsif ($item_quantity = "3") {
$ship_total2 = "5.00";
}elsif ($item_quantity = "4") {
$ship_total2 = "6.00";
}elsif ($item_quantity > "4") {
$ship_total2 = "6.00";
}
if (($fd_trackitem_shipcountry eq
"Ireland")||($fd_trackitem_shipcountry eq
"Cyprus")||($fd_trackitem_shipcountry eq
"Finland")||($fd_trackitem_shipcountry eq
"Gibraltar")||($fd_trackitem_shipcountry eq "Hungary")
||($fd_trackitem_shipcountry eq
"Iceland")||($fd_trackitem_shipcountry eq "Norway")
||($fd_trackitem_shipcountry eq
"Poland")||($fd_trackitem_shipcountry eq "San
Marino")||($fd_trackitem_shipcountry eq "Slovenia")
||($fd_trackitem_shipcountry eq
"Switzerland")||($fd_trackitem_shipcountry eq "Austria")
||($fd_trackitem_shipcountry eq "Belgium")
||($fd_trackitem_shipcountry eq "Denmark")
||($fd_trackitem_shipcountry eq "France") ||($fd_trackitem_shipcountry
eq "Germany") ||($fd_trackitem_shipcountry
eq "Greece") ||($fd_trackitem_shipcountry eq "Italy")
||($fd_trackitem_shipcountry eq "Luxembourg")
||($fd_trackitem_shipcountry eq "Netherlands")
||($fd_trackitem_shipcountry eq "Portugal")
||($fd_trackitem_shipcountry eq "Spain") ||($fd_trackitem_shipcountry
eq "Sweden")){
$ship_display2 = "$ship_meth_name2 - $currency_symbol$ship_total2";
$ship_total2 = sprintf("%.2f", $ship_total2);
$custom_code_result .= <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">
<TR BGCOLOR="$html_pri_tablerow_color">
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid"
VALUE="$ship_meth_name2\:$ship_total2" CHECKED> <FONT
FACE="$html_base_font_face" SIZE="$html_base_font_size"
COLOR="$html_base_font_color">
$ship_display2
</FONT></TD>
</TR>
</TABLE>
</CENTER>
<BR>
ENDOFTEXT
}
######### Third set of desclarations:
#########
#########
#########
#########
#########
#########
my $ship_meth_name3 = "Rest of the World Delivery";
my $ship_total3 = "0.00";
my $ship_display3 = "";
if ($item_quantity = "1") {
$ship_total3 = "4.00";
}elsif ($item_quantity = "2") {
$ship_total3 = "6.00";
}elsif ($item_quantity = "3") {
$ship_total3 = "8.00";
}elsif ($item_quantity = "4") {
$ship_total3 = "9.00";
}elsif ($item_quantity > "4") {
$ship_total3 = "9.00";
}
$ship_display3 = "$ship_meth_name3 - $currency_symbol$ship_total3";
$ship_total3 = sprintf("%.2f", $ship_total3);
$custom_code_result .= <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">
<TR BGCOLOR="$html_pri_tablerow_color">
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid"
VALUE="$ship_meth_name3\:$ship_total3" CHECKED> <FONT
FACE="$html_base_font_face" SIZE="$html_base_font_size"
COLOR="$html_base_font_color">
$ship_display3
</FONT></TD>
</TR>
</TABLE>
</CENTER>
<BR>
ENDOFTEXT
script to be used with ClickCartPro for calculating shipping rates.
Normally this is relatively straightforward but I would like to declare
two conditions at the same time: determine which country to ship to
dependant upon the variable '$fd_trackitem_shipcountry' and then
calculate the shipping in that category based upon the total quantity.
So far I have the script below but it returns the correct country +
'Rest of the World' and the base price for 1 unit.
If anyone has the time to look and possibly verify my script, I would
be very oblidged:
######### My rather poor attempt at
######### re-arranging the order
######### of the statements.
#########
######### First declaration:
#########
#########
$custom_code_result = "";
my $ship_meth_name1 = "UK Delivery";
my $ship_total1 = "0.00";
my $ship_display1 = "";
if ($item_quantity = "1") {
$ship_total1 = "2.00";
}elsif ($item_quantity = "2") {
$ship_total1 = "2.50";
}elsif ($item_quantity = "3") {
$ship_total1 = "3.50";
}elsif ($item_quantity = "4") {
$ship_total1 = "4.00";
}elsif ($item_quantity > "4") {
$ship_total1 = "4.00";
}
if (($fd_trackitem_shipcountry eq "United
Kingdom")||($fd_trackitem_shipcountry eq "Highlands & Islands
Scotland")
||($fd_trackitem_shipcountry eq "Isles Of
Scilly")||($fd_trackitem_shipcountry eq "Isle of
Man")||($fd_trackitem_shipcountry eq "Channel
Islands")||($fd_trackitem_shipcountry eq "Northern Ireland")){
$ship_display1 = "$ship_meth_name1 - $currency_symbol$ship_total1";
$ship_total1 = sprintf("%.2f", $ship_total1);
$custom_code_result .= <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" >
<TR BGCOLOR="$html_pri_tablerow_color">
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid"
VALUE="$ship_meth_name1\:$ship_total1" CHECKED> <FONT
FACE="$html_base_font_face" SIZE="$html_base_font_size"
COLOR="$html_base_font_color">
$ship_display1
</FONT></TD>
</TR>
</TABLE>
</CENTER>
<BR>
ENDOFTEXT
}
######### Second set of declarations:
#########
#########
#########
#########
#########
#########
my $ship_meth_name2 = "European Delivery";
my $ship_total2 = "0.00";
my $ship_display2 = "";
if ($item_quantity = "1") {
$ship_total2 = "3.00";
}elsif ($item_quantity = "2") {
$ship_total2 = "4.00";
}elsif ($item_quantity = "3") {
$ship_total2 = "5.00";
}elsif ($item_quantity = "4") {
$ship_total2 = "6.00";
}elsif ($item_quantity > "4") {
$ship_total2 = "6.00";
}
if (($fd_trackitem_shipcountry eq
"Ireland")||($fd_trackitem_shipcountry eq
"Cyprus")||($fd_trackitem_shipcountry eq
"Finland")||($fd_trackitem_shipcountry eq
"Gibraltar")||($fd_trackitem_shipcountry eq "Hungary")
||($fd_trackitem_shipcountry eq
"Iceland")||($fd_trackitem_shipcountry eq "Norway")
||($fd_trackitem_shipcountry eq
"Poland")||($fd_trackitem_shipcountry eq "San
Marino")||($fd_trackitem_shipcountry eq "Slovenia")
||($fd_trackitem_shipcountry eq
"Switzerland")||($fd_trackitem_shipcountry eq "Austria")
||($fd_trackitem_shipcountry eq "Belgium")
||($fd_trackitem_shipcountry eq "Denmark")
||($fd_trackitem_shipcountry eq "France") ||($fd_trackitem_shipcountry
eq "Germany") ||($fd_trackitem_shipcountry
eq "Greece") ||($fd_trackitem_shipcountry eq "Italy")
||($fd_trackitem_shipcountry eq "Luxembourg")
||($fd_trackitem_shipcountry eq "Netherlands")
||($fd_trackitem_shipcountry eq "Portugal")
||($fd_trackitem_shipcountry eq "Spain") ||($fd_trackitem_shipcountry
eq "Sweden")){
$ship_display2 = "$ship_meth_name2 - $currency_symbol$ship_total2";
$ship_total2 = sprintf("%.2f", $ship_total2);
$custom_code_result .= <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">
<TR BGCOLOR="$html_pri_tablerow_color">
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid"
VALUE="$ship_meth_name2\:$ship_total2" CHECKED> <FONT
FACE="$html_base_font_face" SIZE="$html_base_font_size"
COLOR="$html_base_font_color">
$ship_display2
</FONT></TD>
</TR>
</TABLE>
</CENTER>
<BR>
ENDOFTEXT
}
######### Third set of desclarations:
#########
#########
#########
#########
#########
#########
my $ship_meth_name3 = "Rest of the World Delivery";
my $ship_total3 = "0.00";
my $ship_display3 = "";
if ($item_quantity = "1") {
$ship_total3 = "4.00";
}elsif ($item_quantity = "2") {
$ship_total3 = "6.00";
}elsif ($item_quantity = "3") {
$ship_total3 = "8.00";
}elsif ($item_quantity = "4") {
$ship_total3 = "9.00";
}elsif ($item_quantity > "4") {
$ship_total3 = "9.00";
}
$ship_display3 = "$ship_meth_name3 - $currency_symbol$ship_total3";
$ship_total3 = sprintf("%.2f", $ship_total3);
$custom_code_result .= <<ENDOFTEXT;
<CENTER>
<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">
<TR BGCOLOR="$html_pri_tablerow_color">
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid"
VALUE="$ship_meth_name3\:$ship_total3" CHECKED> <FONT
FACE="$html_base_font_face" SIZE="$html_base_font_size"
COLOR="$html_base_font_color">
$ship_display3
</FONT></TD>
</TR>
</TABLE>
</CENTER>
<BR>
ENDOFTEXT