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.
I hope I'm not being too dense, but I cannot figure out how to calculate USPS insurance for an order total. I'm using the USPS Webtools API and it works fine, but I cannot find a way to calculate and add the insurance to the shipping total. In fact, I can't even find a place in CCP51 for shipping insurance. Any suggestions?
Offline
Karl,
I got this mod from Nick.
This mod is to calculate a shipping insurance price to charge the customer based on 5% of the purchase price. I am not sure if this will work for you or not.
### if ($checked eq "N") { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement. ### Add in: ### $service_name .= "$service_name (Insured)"; $insurance = ($tracking_subtotal * .05); $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; ###
Offline
I modified the code a bit more to calculate the actual USPS domestic insurance charges.
Replace the code below (from the 'ste_chkout_meth_realtime_proc' routine
in ste_chkout.pl) :
if ($checked eq "N") { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement.
if ($checked eq "N") { ## USPS 1st Class & Priority Mail insurance costs if ($tracking_subtotal < 50.01) { $insurance = 1.30; } elsif ($tracking_subtotal < 100.01) { $insurance = 2.20; } elsif ($tracking_subtotal > int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 2.20; } elsif ($sub_price = int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 1.20; }; $service_name .= "$service_name (Insured)"; $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement.
This only works for USPS domestic mail (First Class and Priority)
Offline
Oops, I just discovered that for multiple shipping options, you need to set the variables:
## USPS 1st Class & Priority Mail insurance costs if ($tracking_subtotal < 50.01) { $insurance = 1.30; } elsif ($tracking_subtotal < 100.01) { $insurance = 2.20; } elsif ($tracking_subtotal > int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 2.20; } elsif ($sub_price = int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 1.20; }; $service_name .= "$service_name (Insured)"; $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate);
before the if statement:
if ($checked eq "N") {
NOW it works fine.
Offline
One more bit of debugging. It turns out the line
$service_name .= "$service_name (Insured)";
does not print "(Insured)" after the shipping method. Replace it with this line:
$service_name_display .= " (Insured)";
Now you will see a shipping option that looks like this:
I think that should do it.
Offline
I've used the mod that Karleil posted above. After I made the changes and uploaded the new code I checked my store.
On the checkout pages instead of the nice, clean form to enter your billing and shipping info, I have my code showing.
See here:
Here's the code I used:
## USPS 1st Class & Priority Mail insurance costs if ($tracking_subtotal < 50.01) { $insurance = 1.30; } elsif ($tracking_subtotal < 100.01) { $insurance = 2.20; } elsif ($tracking_subtotal > int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 2.20; } elsif ($sub_price = int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 1.20; }; $service_name_display .= " (Insured)"; $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); if ($checked eq "N") { ## USPS 1st Class & Priority Mail insurance costs if ($tracking_subtotal < 50.01) { $insurance = 1.30; } elsif ($tracking_subtotal < 100.01) { $insurance = 2.20; } elsif ($tracking_subtotal > int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 2.20; } elsif ($sub_price = int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 1.20; }; $service_name_display .= " (Insured)"; $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement.
I've been over this and it's been driving me nuts trying to sort it out.
I uploaded it in ascii format.
What did I do wrong?
Thanks in advance for your help!
Offline
it's not the code, it's the html.
TD VALIGN="TOP"><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="1" COLOR="000000"><B>First Name <FONT COLOR="FF0000">*</FONT></B></FONT><BR><BR>
should be:
<TD VALIGN="TOP"><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="1" COLOR="000000"><B>First Name <FONT COLOR="FF0000">*</FONT></B></FONT><BR><BR>
Offline
Anyone know how to make this work with only USPS?
Im using the mod that allows the customer to pick either UPS or USPS and this insurance mod works great, but it calculates in on both carriers.
Thanks
Offline
Try this for USPS-only insurance. I don't have my store configured for UPS, so I can't test compatibility with UPS realtime. But it should add the insurance only to USPS and skip it for UPS.
# USPS insurance costs my $ship_ident = (); $ship_ident = substr($service_name, 1, 4); if ($ship_ident = "USPS") { if ($tracking_subtotal < 50.01) { $insurance = 1.30; } elsif ($tracking_subtotal < 100.01) { $insurance = 2.20; } elsif ($tracking_subtotal > int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 2.20; } elsif ($sub_price = int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 1.20; }; $service_name_display .= " (Insured)"; $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); };
Offline
Hi,
I added the following
## ADD UPS Insurance $service_name_display .= " (Insured)"; $insurance = ($tracking_subtotal * .05); $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); ## END HACK
Right below
if ($checked eq "N") {
as explained above.
My question is when I test this it is displaying ups ground (insured) but the 2nd and 3rd day ups selections do not offer the insured feature nor is the user able to select ups ground without the insurance.
Anyway of tweaking this to give the user the option to select a radio button with the additional insuance displayed??
Offline
Let me just do that hack again. It's all too hard to read. In ./cgi-bin/library/modules/ste_chkout.pl in the routine 'ste_chkout_meth_realtime_proc' you'll see:
if ($checked eq "N") { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement.
Immediately below that, you will want to add:
if ($shiptype eq "USPS") { $service_name .= "$service_name (Insured)"; $insurance = ($tracking_subtotal * .05); $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } ######### End of if statement.
That does 5% on USPS only - adjust the calculation to do more/less.
Offline
Nick, a straight percentage does not work for accurate USPS domestic insurance. USPS uses a set of increments:
-- up to $50 = $1.30
-- $50.01 to $100 = $2.20
-- Over $100 = $2.20 for the first $100, plus $1.00 for each break over $x00.00 (i.e., $3.20 insurance for $100.01 to $200, $4.20 insur for $200.01 to $300, etc.)
Offline
The insurance charges would need to be modified to use UPS I suppose. The key is to change the line:
if ($shiptype eq "USPS") {
To read:
if ($shiptype =~ /^UPS/) {
To use UPS. As far as variable insurance charges, the code is here in this post for figuring them out. Just replace:
$insurance = ($tracking_subtotal * .05);
With whatever logic you need to calculate the insurance.
Offline
Hi Nick,
It is actually this
if ($shiptype =~ /^UPS/) { $service_name_display .= " (Insured)"; $insurance = ($tracking_subtotal * .05); $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } ######### End of if statement.
Note the correction to the Insured string. Now the only problem I see is it doesn't send any type of notice in the order email.
It did list both ups ground and ups 2nd day with the insured rate just below but no sign of it in the order or throughout the rest of the checkout process.
Offline
this works fine now..
if ($shiptype =~ /^UPS/) {
$service_name_display .= " (Insured)";
$insurance = ($tracking_subtotal * .05);
$service_rate = ($service_rate + $insurance);
$service_rate = sprintf("%.2f", $service_rate);
$return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name_display\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n";
$checked = "Y";
} ######### End of if statement.
Offline
Could I use the mod for UPS insurance for FedEx insurance? Just substitute FedEx for UPS?
Offline
I add the USPS/UPS hack for FEDEX. It does work, however, when the shipping comes up half of the Radio buttons are checked. Also, this mod displays both shipping with and without insurance. There should only be shipping with insurance and the choices are ground, standard, etc. Any suggestions of what to do with the mod.
Thanks,
Edgar
Offline
This code was modified a lot in this post. Make sure your implementation checks the '$checked' variable to make sure whether ' CHECKED' is printed or not in the radio buttons.
Offline
Okay, now only one Radio button is selected. I haven't a clue what I did that changed it but today it has only one button checked. What I really need to know is how to have only insured choices show up. Here is what I am getting:
FedEx Ground Service® - $10.61
FedEx Ground Service® (Insured) - $13.98
FedEx Express Saver® - $29.64
FedEx Express Saver® (Insured) - $33.01
FedEx 2 Day® - $34.06
FedEx 2 Day® (Insured) - $37.43
FedEx Priority® - $62.22
FedEx Priority® (Insured) - $65.59
What I want is this:
FedEx Ground Service® (Insured) - $13.98
FedEx Express Saver® (Insured) - $33.01
FedEx 2 Day® (Insured) - $37.43
FedEx Priority® (Insured) - $65.59
Any suggestions?
Thanks,
Edgar
Offline
OK... with all the changes in this thread I got completely lost.
Can someone please post the process to get the following in ONE post please?
FedEx Ground Service® - $10.61
FedEx Ground Service® (Insured) - $13.98
FedEx Express Saver® - $29.64
FedEx Express Saver® (Insured) - $33.01
FedEx 2 Day® - $34.06
FedEx 2 Day® (Insured) - $37.43
FedEx Priority® - $62.22
FedEx Priority® (Insured) - $65.59
Thank you a thousand times.
Offline
Replace the code below (from the 'ste_chkout_meth_realtime_proc' routine
in ste_chkout.pl) :
if ($checked eq "N") { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement.
With this:
if ($checked eq "N") { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement. if ($tracking_subtotal < 50.01) { $insurance = 1.30; } elsif ($tracking_subtotal < 100.01) { $insurance = 2.20; } elsif ($tracking_subtotal > int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 2.20; } elsif ($sub_price = int($tracking_subtotal/100) * 100) { $insurance = int($tracking_subtotal/100) + 1.20; }; $service_name .= "$service_name (Insured)"; $service_rate = ($service_rate + $insurance); $service_rate = sprintf("%.2f", $service_rate); if ($checked eq "N") { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\" CHECKED> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; $checked = "Y"; } else { $return_value .= "<INPUT TYPE=\"RADIO\" NAME=\"shipinfo-$shipid\" VALUE=\"$service_name\:$service_rate\"> <FONT FACE=\"$html_base_font_face\" SIZE=\"$html_base_font_size\" COLOR=\"$html_base_font_color\"> $service_name_display - $currency$service_rate<BR></FONT>\n"; } ######### End of if statement.
Offline
Got this hack but how do I go about putting the option they chose onto the invoice? Wheater USPS First Class Mail or USPS First Class Mail (Insured) is chosen, it still only says USPS First Class Mail. Will not put the (Insured) on the order nor invoice.
Thanks!
Offline