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 02-13-2007 11:26:37

logos
Member
Registered: 02-13-2007
Posts: 17

Cost Based and Percentage Based Shipping

I need to charge per cost and percentage rates:
Here are my shipping rates:
Product Total    Shipping Charge
Up to $20                  $7.50
$20.01 to $50.00      $9.00
$50.01 to $100.00    18% of product total
$100.01 and up      15% of product total

How do I do that?

I tried combining the code for percentage and cost based: but I don't think I have it correct:
#########
######### This custom script calculates shipping
######### based on total item cost. Items
######### and percentage over 50.00.
#########
######### 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 = "UPS Ground: 4-6 Days";
my $percentage = "10.000";
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 <= "20.00") {

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

} elsif ($item_subtotal > "20.00" && $item_subtotal <= "50.00") {

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

######## Percentage Based Shipping Here
$percentage = ($percentage / 100);

} elsif ($item_subtotal > "50.01" && $item_subtotal <= "100.00") {

$ship_total = ($item_subtotal * .18);
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} elsif ($item_subtotal > "100.01" ) {

$ship_total = ($item_subtotal * .15);
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";

} ######### 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

Last edited by logos (02-13-2007 11:30:05)

Offline

 

#2 02-13-2007 11:33:46

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

Re: Cost Based and Percentage Based Shipping

Looks pretty close... try this one:

Code:

my $ship_meth_name = "UPS Ground 4-6 Days";
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 <= "20.00") {

$ship_total = "7.50";

} elsif ($item_subtotal > "20.00" && $item_subtotal <= "50.00") {

$ship_total = "9.00";

} elsif ($item_subtotal > "50.00" && $item_subtotal <= "100.00") {

$ship_total = $item_subtotal * .18;

} elsif ($item_subtotal > "100.00" ) {

$ship_total = $item_subtotal * .15;

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

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

$ship_total = sprintf("%.2f", $ship_total);
$ship_display = "$ship_meth_name - $currency_symbol$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

EDIT: Removed problematic colon in shipping method name.

Last edited by rachaelseven (11-19-2008 09:43:56)


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#3 02-13-2007 12:23:17

logos
Member
Registered: 02-13-2007
Posts: 17

Re: Cost Based and Percentage Based Shipping

Thanks -- You are quick -- you have helped me so much!
what you sent is working fine: On the same note:
If I have multiple shipping options (custom) how do I add those to it? Here is what my client gave me to put in for him... if you could get me started I can do it....

Next Day Air: 1-2 business days
Product Total    Shipping Charge
Up to $20    $15.00
$20.01 to $50.00    $17.00
$50.01 to $100.00    34% of product total
$100.01 and up    30% of product total
________________________________________________
Alaska & Hawaii
UPS 2nd Day Air:  2-3 business days
Product Total    Shipping Charge
Up to $20                    $13.00
$20.01 to $50.00    $13.00
$50.01 to $100.00    22% of product total
$100.01 and up    18% of product total

Offline

 

#4 02-13-2007 12:42:10

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

Re: Cost Based and Percentage Based Shipping

You're welcome.  Adding in a second method is not tough - it is basically just duplicating all the variables and adding another radio button.  In other words, you'll add $ship_total1 with the second value and $ship_meth_name1 for the second method's name, $ship_display1, etc.  The second radio button should keep the same name as the first one (shipinfo-$shipid).  Where it gets a bit tougher is making the second choice different for different states.  It's certainly possible, it just takes a few more if statements.  The destination state is available in the variable $fd_trackitem_shipstateprov - that's the key piece of information.  Good luck!


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#5 02-13-2007 15:25:02

logos
Member
Registered: 02-13-2007
Posts: 17

Re: Cost Based and Percentage Based Shipping

Could you put in for me a second shipping method so I can see where you put your duplicate information (Sorry, I am not a "coder" and am feeling my way through this...).  Then I can go on that sample and add the other options that I have.

Offline

 

#6 02-13-2007 18:52:51

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

Re: Cost Based and Percentage Based Shipping

Code:

my $ship_meth_name = "UPS Ground 4-6 Days";
my $ship_total = "0.00";
my $ship_display = "";

my $ship_meth_name1 = "New Ship Method";
my $ship_total1 = "0.00";
my $ship_display1 = "";

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

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

$ship_total = "7.50";
$ship_total1 = "123.45";

} elsif ($item_subtotal > "20.00" && $item_subtotal <= "50.00") {

$ship_total = "9.00";
$ship_total1 = "123.45";

} elsif ($item_subtotal > "50.00" && $item_subtotal <= "100.00") {

$ship_total = $item_subtotal * .18;
$ship_total1 = $item_subtotal * .123;


} elsif ($item_subtotal > "100.00" ) {

$ship_total = $item_subtotal * .15;
$ship_total1 = $item_subtotal * .123;

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

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

$ship_total = sprintf("%.2f", $ship_total);
$ship_total1 = sprintf("%.2f", $ship_total1);
$ship_display = "$ship_meth_name - $currency_symbol$ship_total";
$ship_display1 = "$ship_meth_name1 - $currency_symbol$ship_total1";

#########
######### 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>
<INPUT TYPE="RADIO" NAME="shipinfo-$shipid" VALUE="$ship_meth_name1:$ship_total1"> <FONT FACE="$html_base_font_face" SIZE="$html_base_font_size" COLOR="$html_base_font_color"> $ship_display1<BR></FONT>

ENDOFTEXT

A helpful PERL reference: http://www.tizag.com/perlT/
A useful PERL syntax checker: http://www.ult-tex.net/tools/ultra/line_count.pl

EDIT: Removed problematic colon in shipping method name.

Last edited by rachaelseven (11-19-2008 09:43:22)


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#7 11-16-2008 05:01:40

KimbofromKS
Member
Registered: 01-11-2002
Posts: 17

Re: Cost Based and Percentage Based Shipping

If I need to use this hack, where  would I place the code?

Offline

 

#8 11-16-2008 12:55:07

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

Re: Cost Based and Percentage Based Shipping

This is not a hack, it is just a custom shipping method.  The code would be placed in the 'Perl Scripting' section of a custom shipping method configuration page in the CCP admin.


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#9 11-16-2008 20:48:16

KimbofromKS
Member
Registered: 01-11-2002
Posts: 17

Re: Cost Based and Percentage Based Shipping

Thanks.  I never liked that word "hack".  What's a hack?

Offline

 

#10 11-17-2008 04:23:32

KimbofromKS
Member
Registered: 01-11-2002
Posts: 17

Re: Cost Based and Percentage Based Shipping

Ok.  I found what your talking about and created a new custom shipping method and dropped your programming into it.  I went into the product and picked custom and picked my new custom script.  That product 159.95

I placed that item in shopping cart and began checkout process.  On second screen it had one option to pick for shipping method:  UPS Ground: 4-6 Days - $23.99.  The box was checked and I proceeded to next screen.

Here it says Item subtotal 159.95 Shipping $4.00  Total 163.95  Where did I go wrong?  Thanks.

Offline

 

#11 11-17-2008 13:52:39

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

Re: Cost Based and Percentage Based Shipping

A 'hack' is generally thought of as an unauthorized or unsanctioned code modification... at least in these parts.  Of course, there is also the nefarious usage of the term meaning to break into or take over a system, but it is the former (not criminal) usage of the word that you will find around here.  I have written quite a few hacks and take no offense to the term... this just wasn't one of them, that's all :-)

As for your problem with the script, sounds like maybe you modified the price in the wrong place.  If you post the contents of your script here, I'd be happy to help you debug it.


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#12 11-18-2008 22:11:57

Kimbo
Member
Registered: 11-18-2008
Posts: 6

Re: Cost Based and Percentage Based Shipping

This should be the same as above (first one), as that is where it was copied from:

Code:

my $ship_meth_name = "UPS Ground: 4-6 Days";
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 <= "20.00") {

$ship_total = "7.50";

} elsif ($item_subtotal > "20.00" && $item_subtotal <= "50.00") {

$ship_total = "9.00";

} elsif ($item_subtotal > "50.00" && $item_subtotal <= "100.00") {

$ship_total = $item_subtotal * .18;

} elsif ($item_subtotal > "100.00" ) {

$ship_total = $item_subtotal * .15;

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

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

$ship_total = sprintf("%.2f", $ship_total);
$ship_display = "$ship_meth_name - $currency_symbol$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

 

#13 11-19-2008 09:42:26

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

Re: Cost Based and Percentage Based Shipping

The problem is partially my fault here - I apologize.  When I corrected the other person's script, I never changed the name of the shipping method (nor looked at it closely) and the shipping method names in CCP shipping scripts cannot have the colon character (:) in them.  Change the name to something like "UPS Ground (4-6 Days)" or anything else without a colon, and it will work fine.  I will update the original posts so that they don't cause problems for anyone else.


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#14 11-19-2008 20:25:54

Kimbo
Member
Registered: 11-18-2008
Posts: 6

Re: Cost Based and Percentage Based Shipping

That worked!  Your the best!

Offline

 

Board footer