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 03-11-2006 17:31:32

JabberWocky
Member
Registered: 02-13-2006
Posts: 36

Help W/ Shipping Script Modification

Hey all!

I need help with modifying the shipping script. Currently, I'm using the custom shipping script that calculates 10% of the cart total for shipping cost.

Somewhere in there, I need to add an if statement that determines if you are shipping to either Alaska or Hawaii, you'll need to tack on an additional fee, say $10.

I know the logic of how to make it work, I just don't know a lick of perl. Can anyone help me out?

Thanks in advance...



The Authorized Online Retailer of RoJaus Wine Decanters and the WineDown Accessories Catalog

Offline

 

#2 03-11-2006 17:50:20

Graham
Member
Registered: 09-30-2004
Posts: 892
Website

Re: Help W/ Shipping Script Modification

Here's the custom shipping module I use. If you look at the way it works I'm sure you can modify it easily enough:

Code:

#########
######### 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.
#########
######### ***********************************************
#########
######### NB This routine has been customised to handle
######### A.L.Products shipping costs, ie 10% for UK or
######### 20% for International.
######### 
######### It checks the country code and if it's not UK
######### or qualifies as UK then it selects International
######### 
######### 
######### ***********************************************
#########
######### 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 $uk_ship_meth_name = "UK Delivery";
my $intl_ship_meth_name = "International Delivery";
my $ship_total = "0.00";
my $ship_display = "";
my $uk_percentage = "10.000";
my $intl_percentage = "20.000";

if (($fd_trackitem_shipcountry eq "United Kingdom Main Land")||($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")){

### UK shipping

$ship_meth_name = $uk_ship_meth_name;
$percentage = $uk_percentage;

#########
######### Figure out what the shipping charge will be by
######### multiplying the percentage by the subtotal.
#########

$percentage = ($percentage / 100);

$ship_total = ($item_subtotal * $percentage);

######### 
######### MAXIMUM UK P&P IS 20 POUNDS
######### 

if ($ship_total > 20) {

$ship_total = 20.00;

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

######### 
######### END OF MAXIMUM UK P&P 20 POUNDS CODE
######### 

} else {

### International shipping

$ship_meth_name = $intl_ship_meth_name;
$percentage = $intl_percentage;

#########
######### Figure out what the international shipping 
######### charge will be by multiplying the percentage
######### by the subtotal.
######### 

$percentage = ($percentage / 100);

$ship_total = ($item_subtotal * $percentage);

} 

######### End of if statement

#########
######### Create the display based on the price.
#########

## ship_total line below moved from commented line
## below "end of if statement"

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

if ($ship_total > "0") {

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

} else {

$ship_display = "$ship_meth_name - FREE";

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

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

#########
######### Return the HTML in the variable 
######### $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

 

#3 03-11-2006 18:45:59

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

Re: Help W/ Shipping Script Modification

Try adding this in the right spot... somewhere before the custom code result is created.

Code:

if ($fd_trackitem_shipstateprov =~ /Alaska/ || $fd_trackitem_shipstateprov =~ /Hawaii/) {

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

} ## End of if

Rachael


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#4 03-13-2006 14:07:42

JabberWocky
Member
Registered: 02-13-2006
Posts: 36

Re: Help W/ Shipping Script Modification

OK, I guess my logic isn't cutting it.

Anytime I tried doing anything to my custom shipping script, it defaulted to charging a $15 charge. Ignored the percentage, ignored the state shipping to.

Is it a problem that by adding that if statement there are two of these statements in the code:

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

Regardless, I guess I need more hand-holding than I thought... thanks



The Authorized Online Retailer of RoJaus Wine Decanters and the WineDown Accessories Catalog

Offline

 

#5 03-13-2006 14:38:54

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

Re: Help W/ Shipping Script Modification

I'm hugely sorry.  My code was basically right, but in the very last line I made a typo.  It should be a } instead of a ) right before it says ## End of if.  Fix that and it will work fine.  I'm really sorry about that.  I'll fix the original post so no one else gets confused by it.

Rachael


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#6 03-13-2006 20:24:02

Graham
Member
Registered: 09-30-2004
Posts: 892
Website

Re: Help W/ Shipping Script Modification

JabberWocky,03/13/2006 02:07:42 PM wrote:

Anytime I tried doing anything to my custom shipping script, it defaulted to charging a $15 charge. Ignored the percentage, ignored the state shipping to.

Just to clarify, this "default charge" happens if there's a fault in the shipping calculation, it's what the program uses if it can't get a meaningful result.

Offline

 

#7 03-13-2006 21:17:46

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

Re: Help W/ Shipping Script Modification

Absolutely right, Graham.  The unfortunate thing is that because of that "default" behavior, you get absolutely no feedback about the error that caused it; so a simple typo can turn into a giant pain in the behind.

Rachael


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#8 03-13-2006 21:58:39

JabberWocky
Member
Registered: 02-13-2006
Posts: 36

Re: Help W/ Shipping Script Modification

Wow... you guys rock.

Thanks... works like a charm now. And now I'll know that something is fishy if that $15 ever pops up again.

See, it's an educational show, folks.

Much obliged!  smile 



The Authorized Online Retailer of RoJaus Wine Decanters and the WineDown Accessories Catalog

Offline

 

#9 03-26-2006 23:06:53

JabberWocky
Member
Registered: 02-13-2006
Posts: 36

Re: Help W/ Shipping Script Modification

Me again... wondering if you can help me with another quick modification to the same shipping script (last one is working great, btw!).

I would like to incorporate a shipping minimum, so that the 10% shipping charge will not go below $8.... basically if their product total is less than $80, I would like it to default to a $8 charge.

Thanks again in advance for any help!  :-) 



The Authorized Online Retailer of RoJaus Wine Decanters and the WineDown Accessories Catalog

Offline

 

#10 03-27-2006 09:23:34

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

Re: Help W/ Shipping Script Modification

Try putting this in the script after all the other calcualtions are done or perhaps right before the Alaska/Hawaii add-on:

Code:

if ($ship_total < 8) { $ship_total="8.00" }

I think that should do it.  Just check to make sure it works correctly for various cases, including orders of $90, $100 and $200.

Rachael


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#11 03-27-2006 10:50:28

JabberWocky
Member
Registered: 02-13-2006
Posts: 36

Re: Help W/ Shipping Script Modification

hey thanks! It worked but i had to add the closing quote after 8.00. the correct code is below.

Code:

if ($ship_total < 8) { $ship_total="8.00" }

just so you know, the first time i ran it, i got that default $15 shipping charge, and i knew something was wrong. yay, i feel so empowered!!

thanks again!



The Authorized Online Retailer of RoJaus Wine Decanters and the WineDown Accessories Catalog

Offline

 

#12 03-27-2006 11:28:49

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

Re: Help W/ Shipping Script Modification

Oops... dang fingers!  They just don't keep up with the brain sometimes.  Sorry about the missing quote.  But I'm glad it worked for you in the end - great troubleshooting!

Rachael


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#13 04-18-2009 20:55:45

kgillespie
Member
From: Sandy, Oregon
Registered: 06-10-2004
Posts: 164
Website

Re: Help W/ Shipping Script Modification

I have a very similiar shipping script that you had helped me out with over a year ago. It has been working great but we realized that the Alaska and Hawaii were never treated correctly which is to give them different shipping options than the standard states. Can you look over this code that we are using and see if you can add or implement the proper changes for Alaska and Hawaii? I know nothing about perl and have been using the new cart for every customer since but don't want to have to convert and update the cart to the new unless this script can not be done or at least done cheap enough to not justify the new cart and time it would take to use the php just to be able to make a new custom shipping code etc.. here is my info below and i would pay for your time if nec.

The site is wwwdermalsource.com
The cart is: http://www.dermalsource.com/ccp51/

I am pretty sure they use the “Calculation On Total Item Cost”

Here is the 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_methods = (
{ 'name'=>'Ground Shipping', 'cost_base'=>10.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 3rd-Day Ground', 'cost_base'=>20.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 2nd-Day Air', 'cost_base'=>27.00, 'cost_incr'=>3.00 },
{ 'name'=>'UPS Next Day Air', 'cost_base'=>44.00, 'cost_incr'=>5.00 },
);
my @ca_ship_methods = (
{ 'name'=>'Canada - USPS Priority Mail International
up to four pounds.', 'cost_base'=>20.00, 'cost_incr'=>0.00 },
);
my @int_ship_methods = (
{ 'name'=>'International', 'cost_base'=>40.00, 'cost_incr'=>0.00 },
);
my $def_ship_meth = 0;  # default shipping method (entry 1 above is 0, 2 is 1, etc.)

my $item_divisor = 50;      # set this to the amount of each cost range..
                            # i.e. if for every additional $50 of cost,
                            # the $ship_cost_incr is supposed to go up by
                            # $2.00, then set this to 50

$custom_code_result = "";

# DO NOT CHANGE ANYTHING IN THIS SECTION :: #
my $tmp_subtotal = $item_subtotal - 100;
if ($fd_trackitem_shipcountry =~ /United States/) {
  for (my $i = 0; $i <= $#ship_methods; $i++) {
    my $method = $ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} elsif ($fd_trackitem_shipcountry =~ /Canada/) {
  for (my $i = 0; $i <= $#ca_ship_methods; $i++) {
    my $method = $ca_ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} else {
  for (my $i = 0; $i <= $#int_ship_methods; $i++) {
    my $method = $int_ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} ## endif
# :: DO NOT CHANGE ANYTHING IN THIS SECTION #

What needs to change is Hawaii, Alaska and Puerto Rico CAN NOT HAVE a choice of Ground shipping. Instead only USPS Priority mail or UPS air.

--
Karl

Offline

 

#14 04-19-2009 10:00:07

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

Re: Help W/ Shipping Script Modification

Puerto Rico is treated as a country by USPS and other shippers, as far as I know.  It doesn't even seem to be in the default CCP installation, but if you add it, you should create it as a country rather than a state.  And it will already be covered under your existing script as an "other country".  To add the exception for Alaska and Hawaii, I have added a separate group of rates, for which you will probably need to adjust the prices - it is tagged as the Alaska and Hawaii shipping methods, so you should see where it is.  I then added a bit of code under the US shipping methods section to separate out those two states and use the new rate group for them.  See how this works for you:

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_methods = (
{ 'name'=>'Ground Shipping', 'cost_base'=>10.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 3rd-Day Ground', 'cost_base'=>20.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 2nd-Day Air', 'cost_base'=>27.00, 'cost_incr'=>3.00 },
{ 'name'=>'UPS Next Day Air', 'cost_base'=>44.00, 'cost_incr'=>5.00 },
);
my @ca_ship_methods = (
{ 'name'=>'Canada - USPS Priority Mail International
up to four pounds.', 'cost_base'=>20.00, 'cost_incr'=>0.00 },
);
my @int_ship_methods = (
{ 'name'=>'International', 'cost_base'=>40.00, 'cost_incr'=>0.00 },
);

#### Shipping methods for Alaska and Hawaii

my @alt_ship_methods = (
{ 'name'=>'USPS Priority Mail', 'cost_base'=>10.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 2nd-Day Air', 'cost_base'=>27.00, 'cost_incr'=>3.00 },
{ 'name'=>'UPS Next Day Air', 'cost_base'=>44.00, 'cost_incr'=>5.00 },
);

my $def_ship_meth = 0;  # default shipping method (entry 1 above is 0, 2 is 1, etc.)

my $item_divisor = 50;      # set this to the amount of each cost range..
                            # i.e. if for every additional $50 of cost,
                            # the $ship_cost_incr is supposed to go up by
                            # $2.00, then set this to 50

$custom_code_result = "";

# DO NOT CHANGE ANYTHING IN THIS SECTION :: #
my $tmp_subtotal = $item_subtotal - 100;
if ($fd_trackitem_shipcountry =~ /United States/) {
  if ($fd_trackitem_shipstateprov =~ /alaska/i or $fd_trackitem_shipstateprov =~ /hawaii/i) {
    for (my $i = 0; $i <= $#alt_ship_methods; $i++) {
      my $method = $alt_ship_methods[$i];
      my $ship_meth_name = $method->{'name'};
      my $ship_total = $method->{'cost_base'};
      if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
        $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
      } ## endif
      $ship_total = sprintf("%.2f", $ship_total);
      my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
    $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
    } # end of totaling
  } else {
    for (my $i = 0; $i <= $#ship_methods; $i++) {
      my $method = $ship_methods[$i];
      my $ship_meth_name = $method->{'name'};
      my $ship_total = $method->{'cost_base'};
      if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
        $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
      } ## endif
      $ship_total = sprintf("%.2f", $ship_total);
      my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
    $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
    } # end of totaling
  } ## endif
} elsif ($fd_trackitem_shipcountry =~ /Canada/) {
  for (my $i = 0; $i <= $#ca_ship_methods; $i++) {
    my $method = $ca_ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} else {
  for (my $i = 0; $i <= $#int_ship_methods; $i++) {
    my $method = $int_ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} ## endif
# :: DO NOT CHANGE ANYTHING IN THIS SECTION #

Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#15 04-19-2009 10:22:12

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

Re: Help W/ Shipping Script Modification

Correction to my previous post.  It appears that USPS does treat Puerto Rico as a state, rather than a country.  UPS, FedEx and other couriers will treat it as a country though, just so you are aware.  Here is an updated version of the above that will treat Puerto Rico the same as Alaska and Hawaii:

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_methods = (
{ 'name'=>'Ground Shipping', 'cost_base'=>10.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 3rd-Day Ground', 'cost_base'=>20.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 2nd-Day Air', 'cost_base'=>27.00, 'cost_incr'=>3.00 },
{ 'name'=>'UPS Next Day Air', 'cost_base'=>44.00, 'cost_incr'=>5.00 },
);
my @ca_ship_methods = (
{ 'name'=>'Canada - USPS Priority Mail International
up to four pounds.', 'cost_base'=>20.00, 'cost_incr'=>0.00 },
);
my @int_ship_methods = (
{ 'name'=>'International', 'cost_base'=>40.00, 'cost_incr'=>0.00 },
);

#### Shipping methods for Alaska, Hawaii, and Puerto Rico

my @alt_ship_methods = (
{ 'name'=>'USPS Priority Mail', 'cost_base'=>10.00, 'cost_incr'=>2.00 },
{ 'name'=>'UPS 2nd-Day Air', 'cost_base'=>27.00, 'cost_incr'=>3.00 },
{ 'name'=>'UPS Next Day Air', 'cost_base'=>44.00, 'cost_incr'=>5.00 },
);

my $def_ship_meth = 0;  # default shipping method (entry 1 above is 0, 2 is 1, etc.)

my $item_divisor = 50;      # set this to the amount of each cost range..
                            # i.e. if for every additional $50 of cost,
                            # the $ship_cost_incr is supposed to go up by
                            # $2.00, then set this to 50

$custom_code_result = "";

# DO NOT CHANGE ANYTHING IN THIS SECTION :: #
my $tmp_subtotal = $item_subtotal - 100;
if ($fd_trackitem_shipcountry =~ /United States/) {
  if ($fd_trackitem_shipstateprov =~ /alaska/i or $fd_trackitem_shipstateprov =~ /hawaii/i or $fd_trackitem_shipstateprov =~ /puerto rico/i) {
    for (my $i = 0; $i <= $#alt_ship_methods; $i++) {
      my $method = $alt_ship_methods[$i];
      my $ship_meth_name = $method->{'name'};
      my $ship_total = $method->{'cost_base'};
      if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
        $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
      } ## endif
      $ship_total = sprintf("%.2f", $ship_total);
      my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
    $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
    } # end of totaling
  } else {
    for (my $i = 0; $i <= $#ship_methods; $i++) {
      my $method = $ship_methods[$i];
      my $ship_meth_name = $method->{'name'};
      my $ship_total = $method->{'cost_base'};
      if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
        $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
      } ## endif
      $ship_total = sprintf("%.2f", $ship_total);
      my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
    $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
    } # end of totaling
  } ## endif
} elsif ($fd_trackitem_shipcountry =~ /Canada/) {
  for (my $i = 0; $i <= $#ca_ship_methods; $i++) {
    my $method = $ca_ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} else {
  for (my $i = 0; $i <= $#int_ship_methods; $i++) {
    my $method = $int_ship_methods[$i];
    my $ship_meth_name = $method->{'name'};
    my $ship_total = $method->{'cost_base'};
    if ($item_subtotal >= 100) { # Note that everything BELOW 100 uses default
      $ship_total += (($tmp_subtotal <= 0) ? 1 : (int($tmp_subtotal/$item_divisor)+1)) * $method->{'cost_incr'};
    } ## endif
    $ship_total = sprintf("%.2f", $ship_total);
    my $set_check = ($i == $def_ship_meth) ? ' checked': '/';
  $custom_code_result .= <<"END_OF_TEXT";
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name:$ship_total" $set_check>
<FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color">$ship_meth_name -$currency_symbol$ship_total<BR></FONT>
END_OF_TEXT
  } # end of totaling
} ## endif
# :: DO NOT CHANGE ANYTHING IN THIS SECTION #

In order for this to work correctly, Puerto Rico will need to be added to CCP as a  rather than a country.  It has the abbreviation PR, for the record.


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#16 04-20-2009 22:38:35

kgillespie
Member
From: Sandy, Oregon
Registered: 06-10-2004
Posts: 164
Website

Re: Help W/ Shipping Script Modification

I cut and pasted the code in and then tested it and it looks like it works great. Thank you so much you are the bomb! Let me know if there is anything i can do for you to return the help.

Thanks a million-

Karl G.
wwwdiversitydesign.com

Offline

 

#17 04-20-2009 23:44:45

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

Re: Help W/ Shipping Script Modification

Glad it worked for you, Karl.  You are very welcome!


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#18 04-21-2009 00:52:36

kgillespie
Member
From: Sandy, Oregon
Registered: 06-10-2004
Posts: 164
Website

Re: Help W/ Shipping Script Modification

The note you had about adding the Puerto Rico - "In order for this to work correctly, Puerto Rico will need to be added to CCP as a state rather than a country.  It has the abbreviation PR, for the record."

I thought i would be able to do that as well easy enough but not sure where in the admin control panel to do that? Or do i manually update the software by going into to a file on the server ccp51 folder somewhere?

It is always something extra with us guys.

Karl -

Offline

 

#19 04-21-2009 05:43:28

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

Re: Help W/ Shipping Script Modification

It's in the CCP admin menu under Orders & Payment -> Manage States/Provinces.  The add link to create a new one should be just below the question mark on the upper left, iirc.


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

Board footer