Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 12-19-2007 11:05:06

greytail
Member
Registered: 08-03-2007
Posts: 8

Custom Shipping Script not correct

Hi:
I have a custom shipping script set up under Custom Shipping Methods.- Calculation on Total Item Cost. I want it to add shipping costs according to the order price:
Order Value     Shipping Cost

1.00 -30.00       10.50
30.01- 60.00       15.50
60.01- 90.00        22.50
90.01-120.00      33.75
121.00 150.00    37.25
151.00 - 200.00  40.00

Here is what I have entered, but it doesn't seem to work properly:

#########
######### Custom scripts may apply to a whole
######### order if all of the items ordered
######### use the same shipping method (Custom)
######### and the same script selection.  Scripts
######### are built to handle a group of like
######### items.
#########
######### A listing of available variables:
#########
######### $item_quantity      Total quantity of items
######### $item_subtotal      Subtotal for all items
######### $item_total_weight  Total weight of all items
#########
######### Directly below, enter in the name for this
######### method to be displayed to the user.
#########

$custom_code_result = "";


my $ship_meth_name = "United Parcel Service";
my $ship_total = "10.00";
my $ship_display = "";


if ($item_subtotal >= "0" && $item_subtotal <= "30.00") {

$ship_total = "10.50";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "30.01" && $item_subtotal <= "60.00") {

$ship_total = "15.50";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "60.01" && $item_subtotal <= "90.00") {

$ship_total = "22.50";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "90.01" && $item_subtotal <= "120.00") {

$ship_total = "33.75";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "120.01" && $item_subtotal <= "150.00") {

$ship_total = "37.25";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "150.01" && $item_subtotal <= "200.00") {

$ship_total = "40.00";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";


} elsif ($item_subtotal >= 200.01)  {
  $ship_total = "0.00";
  $ship_display = "Please contact us at $html_site_name for your shipping price.";
}

$ship_total = sprintf("%.2f", $ship_total);

$custom_code_result .= <<ENDOFTEXT;

<CENTER>

<TABLE WIDTH="100\%" CELLPADDING="10" CELLSPACING="3">

<TR BGCOLOR="$html_pri_tablerow_color">

<TD VALIGN="TOP"><FONT FACE="$html_small_font_face" SIZE="$html_small_font_size" COLOR="$html_small_font_color"><B>Shipping Method</B> <FONT COLOR="$html_notnull_font_color"><B>$html_notnull_character</B></FONT><BR><BR></FONT>

<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name\:$ship_total" CHECKED> <FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">

$ship_display

</FONT></TD>

</TR>

</TABLE>

</CENTER>

<BR>

ENDOFTEXT

Offline

 

#2 12-19-2007 11:58:58

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Custom Shipping Script not correct

Try it like this:

Code:

#########
######### This custom script calculates shipping
######### based on total item cost. 
#########
######### Custom scripts may apply to a whole
######### order if all of the items ordered
######### use the same shipping method (Custom)
######### and the same script selection.  Scripts
######### are built to handle a group of like 
######### items.
#########
######### A listing of available variables:
#########
######### $item_quantity      Total quantity of items
######### $item_subtotal      Subtotal for all items
######### $item_total_weight  Total weight of all items
#########
######### Directly below, enter in the name for this
######### method to be displayed to the user.
#########

my $ship_meth_name = "United Parcel Service";
my $ship_total = "0.00";
my $ship_display = "";

#########
######### Figure out what the shipping charge will be by
######### using if statements and less than/greater than
######### logic.
#########

if ($item_subtotal >= "0" && $item_subtotal <= "30.00") {

$ship_total = "10.50";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "30.00" && $item_subtotal <= "60.00") {

$ship_total = "15.50";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "60.00" && $item_subtotal <= "90.00") {

$ship_total = "22.50";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "90.00" && $item_subtotal <= "120.00") {

$ship_total = "33.75";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "120.00" && $item_subtotal <= "150.00") {

$ship_total = "37.25";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "150.00" && $item_subtotal <= "200.00") {

$ship_total = "40.00";
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} else {

$ship_total = "0.00";
$ship_display = "Please contact us at $html_site_name for your shipping price.";

} ######### End of if statement.

#########
######### Format the $ship_total as a price.
#########

$ship_total = sprintf("%.2f", $ship_total);

#########
######### Return the HTML in the variable 
######### $custom_code_result.
#########

$custom_code_result = "";

$custom_code_result .= <<ENDOFTEXT;

<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" CHECKED> <FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color"> $ship_display<BR></FONT>

ENDOFTEXT

Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#3 12-19-2007 13:10:46

greytail
Member
Registered: 08-03-2007
Posts: 8

Re: Custom Shipping Script not correct

thanks!

Offline

 

#4 10-06-2008 08:37:47

heartworks
Member
Registered: 10-06-2008
Posts: 3

Re: Custom Shipping Script not correct

Hi Rachel,

Know it's an old post but could you help, i've quite the same problem with custom shipping.

I want :

France and item subtotal MORE than 75.00 = free shipping
France and item subtotal LESS than 75.00 = 9.00
Rest of the world, no matter item subtotal = 15.00

It must be simple but i'm getting headaches with this :

Code:

#########
######### This custom script calculates shipping
######### based on total item cost. 
#########
######### Custom scripts may apply to a whole
######### order if all of the items ordered
######### use the same shipping method (Custom)
######### and the same script selection.  Scripts
######### are built to handle a group of like 
######### items.
#########
######### A listing of available variables:
#########
######### $item_quantity      Total quantity of items
######### $item_subtotal      Subtotal for all items
######### $item_total_weight  Total weight of all items
#########
######### Directly below, enter in the name for this
######### method to be displayed to the user.
#########

my $ship_meth_name1 = "Colissimo Suivi";
my $ship_meth_name2 = "Livraison Offerte";
my $ship_meth_name3 = "Frais de livraison";
my $ship_total = "0.00";
my $ship_display = "";

#########
######### Figure out what the shipping charge will be by
######### using if statements and less than/greater than
######### logic.
#########

if ($item_subtotal >= "0" && $item_subtotal <= "75.00" && $tracking_country = "FR") {

$ship_total = "9.00";
$ship_display = "$ship_meth_name1 - $currency_symbol$ship_total";

} elsif ($item_subtotal >= "75.00" && $tracking_country = "FR") {

$ship_total = "0.00";
$ship_display = "$ship_meth_name2 - $currency_symbol$ship_total";

} elsif ($item_subtotal >= "0.00" && $tracking_country ne "FR") {

$ship_total = "15.00";
$ship_display = "$ship_meth_name3 - $currency_symbol$ship_total";

} else {

$ship_total = "15.00";
$ship_display = "$ship_meth_name3";

} ######### End of if statement.

#########
######### Format the $ship_total as a price.
#########

$ship_total = sprintf("%.2f", $ship_total);

#########
######### Return the HTML in the variable 
######### $custom_code_result.
#########

$custom_code_result = "";

$custom_code_result .= <<ENDOFTEXT;

<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" CHECKED> <FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color"> $ship_display<BR></FONT>

ENDOFTEXT

Offline

 

#5 10-06-2008 09:39:06

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Custom Shipping Script not correct

Hi there,

You have a good handful of problems that I see.  In two places, you have something like this:

Code:

&& $tracking_country = "FR"

That syntax is incorrect.  When using the "equal to" comparison, you need to use either the operator  or you can use .  When you use a single equal sign in PERL, that is an assignment and not a comparison - it sets the variable equal to the value rather than comparing it.  That's your first problem and fixing that (in each place it occurs) will at least allow the script to run.

The other problem is that I think CCP stores the full country name, rather than the abbreviation, unless something is different with the EU/UK version (I've never used it, so I don't know).  In other words, your if statement should read:

Code:

&& $tracking_country eq "France"

Another possible problem is that you are using the variable $tracking_country.  I am not sure if that variable is actually available - I always use $fd_tracking_country.  Also, $tracking_country is the bill-to country, which might not be the same as the ship-to country, depending on if you have separate billing and shipping addresses allowed in your cart.  To be on the safe side, and to make the script work even if you change cart settings in the future, I would use the variable $fd_trackitem_shipcountry, which is the ship-to country.

And finally, you have some extra logic in your if statement.  Once you've covered French shipments under 75 and French shipments over 75, there is only one other option left for everything else.  So I would remove the unnecessary 2nd elsif branch and just let the rest of the world go to the else portion of the statement (after completing the $ship_display variable in that section).

Good luck!


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#6 10-06-2008 10:02:49

heartworks
Member
Registered: 10-06-2008
Posts: 3

Re: Custom Shipping Script not correct

Hi Rachel,

Seems you just sent me a magic charm !

I followed your explanations and this code finally work the way I want !

Code:

#########
######### This custom script calculates shipping
######### based on total item cost. 
#########
######### Custom scripts may apply to a whole
######### order if all of the items ordered
######### use the same shipping method (Custom)
######### and the same script selection.  Scripts
######### are built to handle a group of like 
######### items.
#########
######### A listing of available variables:
#########
######### $item_quantity      Total quantity of items
######### $item_subtotal      Subtotal for all items
######### $item_total_weight  Total weight of all items
#########
######### Directly below, enter in the name for this
######### method to be displayed to the user.
#########

my $ship_meth_name1 = "Colissimo Suivi";
my $ship_meth_name2 = "Le total de votre commande dépassant les 75 €, nous avons le plaisir de vous offrir les frais d'expédition en Colissimo Suivi !";
my $ship_meth_name3 = "Frais de livraison";
my $ship_total = "0.00";
my $ship_display = "";

#########
######### Figure out what the shipping charge will be by
######### using if statements and less than/greater than
######### logic.
#########

if (($item_subtotal >= "0") && ($item_subtotal <= "75.00") && ($fd_trackitem_shipcountry eq "France")) {

$ship_total = "9.00";
$ship_display = "$ship_meth_name1 - $ship_total $currency_symbol";

} elsif (($item_subtotal >= "75.00") && ($fd_trackitem_shipcountry eq "France")) {

$ship_total = "0.00";
$ship_display = "$ship_meth_name2 - $ship_total $currency_symbol";

} elsif (($item_subtotal >= "0.00") && ($fd_trackitem_shipcountry ne "France")) {

$ship_total = "15.00";
$ship_display = "$ship_meth_name3 - $ship_total $currency_symbol";

} else {

$ship_total = "15.00";
$ship_display = "$ship_meth_name3 - $ship_total $currency_symbol";

} ######### End of if statement.

#########
######### Format the $ship_total as a price.
#########

$ship_total = sprintf("%.2f", $ship_total);

#########
######### Return the HTML in the variable 
######### $custom_code_result.
#########

$custom_code_result = "";

$custom_code_result .= <<ENDOFTEXT;

<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" CHECKED> <FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color"> $ship_display<BR></FONT>

ENDOFTEXT

THANK YOU :-)

Offline

 

#7 10-06-2008 10:05:06

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Custom Shipping Script not correct

Rachael strikes again smile

Offline

 

Board footer