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 01-11-2013 14:29:28

geraldz
Member
Registered: 09-27-2011
Posts: 251

Strange USPS Realtime Shipping Behavior

We are using the realtime shipping method, customized for an upcharge as follows:

Code:

<?php 
// +--
// | All custom shipping scripts work in the same way.  A global
// | variable named 'ecom.customship' contains the following PHP
// | array.  Array keys with value info:
// |
// | weight        => Total weight of items being shipped.
// | total         => Subtotal of items being shipped.
// | quantity      => Quantity of items being shipped.
// | stateprov     => Ship to state/province.
// | country       => Ship to country.
// | postalcode    => Ship to postal code.
// | rescom        => Ship to residential/commercial status.
// | shipstateprov => Ship origin state/province.
// | shipcountry   => Ship origin country.
// | shipzip       => Ship origin postal code.
// | packages      => An array containing all packages with
// |                  each package defined in it's own array
// |                  with keys: length, width, height, weight.
// | delinfo       => Delivery information array.
// | delitems      => An array containing all items with
// |                  each item id as a key and the item quantity 
// |                  as a value.
// |
// | This script must set a global variable named 
// | 'ecom.customship_response' which is an array in the 
// | following format:
// |
// | method name => amount
// |
// | NOTE: Do not print anything within custom shipping
// | scripts.  They are designed only to return names and 
// | prices for custom shipping methods.
// |
// +--

// +--
// | This script adds a handling charge to realtime USPS and UPS rates 
// +--

// +--
// | Get realtime rates & add handling
// +--

$info   = $this->globals('ecom.customship');

// USPS rates are calculated at 90% using the upcharge factor
$usps_upcharge = 0.90;
// Add $5 to UPS rates for scheduled pickup fee
$ups_upcharge = 5.00;

// USPS

$handling = $ups_upcharge;

if ($info['country'] == 'United States') {

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'USPS',
                 'shiptype'      => 'R');

} else {

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'USPS',
                 'shiptype'      => 'R');
}

$result = $this->include_namespace('ecom','shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

// foreach ($result as $num => $service) {
//     $custom[$service['name']] = $service['amount'] + $usps_upcharge;
//     }

foreach ($result as $num => $service) {
     $custom[$service['name']] = ($service['amount'] * $usps_upcharge);
     }

// UPS

if ($info['country'] == 'United States') {

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'UPSTOOLS',
                 'shiptype'      => 'R');

} else {

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'UPSTOOLS',
                 'shiptype'      => 'R');
}

$result = $this->include_namespace('ecom','shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     $custom[$service['name']] = $service['amount'] + $ups_upcharge;
     }

// Adds flat rate box shipping options:
// $custom['USPS Flat Rate Box'] = '10.50';

$this->globals('ecom.customship_response',$custom);

?>

This is the shipping estimate we get for USPS Priority Mail based on the number of units in the cart:

1/$8.28
2/11.48
3/16.34
4/19.62
5/23.00
6/25.38
7/27.41
8/30.02
9/32.94
10/35.24
11/36.72
12/38.52
13/39.83
14/40.91
15/42.26
16/43.16
17/43.92
18/not available
19/not available
20/not available
21/8.28
22/11.48
23/16.34
36/43.16

We had a customer order 36 units and we will take a beating on the freight!  What happened here?

I have set up for the box L 16, W 13, H 3, weight 3.35 lb, and "group with other items."

Thanks for the assistance.

Offline

 

#2 01-14-2013 09:03:09

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

What was your expected result for 36?


Nick Hendler

Offline

 

#3 01-14-2013 11:03:13

geraldz
Member
Registered: 09-27-2011
Posts: 251

Re: Strange USPS Realtime Shipping Behavior

Hi Nick -

17 appears to be the last reasonable quote so I would expect 36 units to be about double that or somewhere in the $80 range.

Something went wrong at 18 units and then bad data obviously appears starting at 21 units.

Offline

 

#4 01-15-2013 08:43:07

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

Take a look in your Shipping Settings under System | Component | Settings to see what your maximum USPS box weight is and adjust, if necessary.  I think you might not be hitting that limit, but are expecting to.


Nick Hendler

Offline

 

#5 01-17-2013 12:45:54

geraldz
Member
Registered: 09-27-2011
Posts: 251

Re: Strange USPS Realtime Shipping Behavior

Hi Nick -

I found the shipping settings here:  System Dashboard > Store > Component > Settings > Shipping Settings.  I changed the max from 70 lbs. to 500 lbs.

That got rid of the "not available" and bogus quotes after 17 units.  After 17 units the USPS pricing disappears completely.  Does USPS have a weight limit?  This product weighs 3.35 lbs. so 17 units = 56.95 lbs.

I never really understood the "Maximum Combined Package Weight" concept.  The shopping cart doesn't know the size of the items, so what does this setting actually do?

Offline

 

#6 01-18-2013 09:47:48

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

USPS cannot ship anything over 50lbs (if I remember correctly).  'Maximum Combined Package Weight' helps the software determine the maximum weight each box could be before you go into a scenario where your shippers can't ship it, or you use oversize pricing.  It's basically a hard cutoff what is necessary to limit box weights so you get rates back.  If you're shipping items that heavy, you might want to consider a custom freight scenario.


Nick Hendler

Offline

 

#7 01-18-2013 12:27:40

geraldz
Member
Registered: 09-27-2011
Posts: 251

Re: Strange USPS Realtime Shipping Behavior

OK, well I'm satisfied with this result.  After 56 lbs. the USPS pricing no longer shows and the customer has to select the UPS option.

Thank for your help.

Offline

 

#8 03-02-2013 02:35:16

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

What setting did you have to use for USPS rates to drop off leaving only UPS as the carrier option? We would like to reserve USPS option only for small lightweight orders.

We are currently using a custom shipping script as shown below....

Code:

<?php 

$info = $this->globals('ecom.customship');

$delinfo = array('stateprov'     => $info

['stateprov'],
                 'country'       => $info

['country'],
                 'postalcode'    => $info

['postalcode'],
                 'rescom'        => $info

['rescom'],
                 'shipstateprov' => $info

['shipstateprov'],
                 'shipcountry'   => $info

['shipcountry'],
                 'shipzip'       => $info

['shipzip'],
                 'shipmethods'   => 'UPSTOOLS',
                 'shiptype'      => 'R');

$result = $this->include_namespace

('ecom','shiprealtime',array('delinfo'  => 

$delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     $custom[$service['name']] = $service

['amount'] + ($service['amount'] * 0.05);
}

$this->globals

('ecom.customship_response',$custom);

?>

<?php 

$info = $this->globals('ecom.customship');

$delinfo = array('stateprov'     => $info

['stateprov'],
                 'country'       => $info

['country'],
                 'postalcode'    => $info

['postalcode'],
                 'rescom'        => $info

['rescom'],
                 'shipstateprov' => $info

['shipstateprov'],
                 'shipcountry'   => $info

['shipcountry'],
                 'shipzip'       => $info

['shipzip'],
                 'shipmethods'   => 'USPS',
                 'shiptype'      => 'R');

$result = $this->include_namespace

('ecom','shiprealtime',array('delinfo'  => 

$delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     $custom[$service['name']] = $service

['amount'] + ($service['amount'] * 0.45);
}

$this->globals

('ecom.customship_response',$custom);

?>

Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#9 03-04-2013 08:41:13

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

I think you'll want to use something like this:

Code:

<?php 

$info = $this->globals('ecom.customship');

$usps_weight_cutoff = 10;

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'UPSTOOLS, USPS',
                 'shiptype'      => 'R');

$result = $this->include_namespace('ecom','shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {

     if (preg_match('/UPS/',$service['name'])) {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.05);

     } elseif ($info[weight'] <= $usps_weight_cutoff) {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.45);

     } // End of if statement.

} // End of if statement.

$this->globals('ecom.customship_response',$custom);

?>

Nick Hendler

Offline

 

#10 07-18-2013 02:09:06

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

I tried the code as written above and got a shipping error message. Below is my entire custom shipping code.  It may be a bit sloppy but I hope to see how it cleans up and adds in a drop off weight where it doesn't query USPS anymore.  Any help is appreciated..

Code:

<?php 

$info = $this->globals('ecom.customship');

$delinfo = array('stateprov'     => $info

['stateprov'],
                 'country'       => $info

['country'],
                 'postalcode'    => $info

['postalcode'],
                 'rescom'        => $info

['rescom'],
                 'shipstateprov' => $info

['shipstateprov'],
                 'shipcountry'   => $info

['shipcountry'],
                 'shipzip'       => $info

['shipzip'],
                 'shipmethods'   => 'UPSTOOLS',
                 'shiptype'      => 'R');

$result = $this->include_namespace

('ecom','shiprealtime',array('delinfo'  => 

$delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     $custom[$service['name']] = $service

['amount'] + ($service['amount'] * 0.05);
}

$this->globals

('ecom.customship_response',$custom);

?>

<?php 

$info = $this->globals('ecom.customship');

$delinfo = array('stateprov'     => $info

['stateprov'],
                 'country'       => $info

['country'],
                 'postalcode'    => $info

['postalcode'],
                 'rescom'        => $info

['rescom'],
                 'shipstateprov' => $info

['shipstateprov'],
                 'shipcountry'   => $info

['shipcountry'],
                 'shipzip'       => $info

['shipzip'],
                 'shipmethods'   => 'USPS',
                 'shiptype'      => 'R');

$result = $this->include_namespace

('ecom','shiprealtime',array('delinfo'  => 

$delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     $custom[$service['name']] = $service

['amount'] + ($service['amount'] * 0.45);
}

$this->globals

('ecom.customship_response',$custom);

?>

Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#11 07-18-2013 07:51:49

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

Your code was just plain incorrect and had a syntax error in it to boot.  Try this:

Code:

<?php 

$info = $this->globals('ecom.customship');

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'UPSTOOLS, USPS',
                 'shiptype'      => 'R');

$result = $this->include_namespace('ecom','shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

if ((!(empty($result))) && (!($this->IsError($result)))) {

     foreach ($result as $num => $service) {

          $multiplier = .05; if (preg_match('/USPS/',$service['name'])) {$multiplier = .45;}

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * $multiplier);

     } // End of foreach statement.

} // End of if statement.

$this->globals('ecom.customship_response',$custom);

?>

Nick Hendler

Offline

 

#12 07-18-2013 08:03:49

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

Thank you for this Nick! Where would the code go to have it drop out USPS after a certain amount of weight since we only want the postal service as an option with lightweight packages.  Thanks again smile


Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#13 07-19-2013 09:17:40

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

You don't need to do that.  USPS will be polled and result in an error, but as UPS options will be returned, the shipping  module will ignore the USPS error and return UPS results only.


Nick Hendler

Offline

 

#14 07-19-2013 13:52:00

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

Thanks Nick!  The shipping script works well but USPS is not dropping out after the 50 lbs max setting we have set in the Shipping settings.  A previous script you posted above included lines...

Code:

$usps_weight_cutoff = 10;

and

Code:

} elseif ($info[weight'] <= $usps_weight_cutoff) {

I tried using it in your recent script but it results in an error.  We want our box maximum weight to 50 lbs for the benefit of UPS but want a lighter weight such as 10 lbs to be the cut off for USPS options.  Any help is appreciated.


Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#15 07-20-2013 10:09:34

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

This one does USPS rates under the cutoff and UPS at and above the cutoff:

Code:

<?php 

$info               = $this->globals('ecom.customship');
$usps_weight_cutoff = 50;
$shipmethod         = 'USPS';

if ($info['weight'] >= $usps_weight_cutoff) {$shipmethod = 'UPSTOOLS';}

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => $shipmethod,
                 'shiptype'      => 'R');

$result = $this->include_namespace('ecom','shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {

     if (preg_match('/UPS/',$service['name'])) {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.05);

     } else {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.45);

     } // End of if statement.

} // End of if statement.

$this->globals('ecom.customship_response',$custom);

?>

Nick Hendler

Offline

 

#16 01-13-2015 16:12:01

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

Hello,

Is there a way to modify the script above to include both UPS and USPS rates below the cut off and UPS rates only above the cut off?

Thanks smile


Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#17 01-14-2015 08:13:02

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

Change:

Code:

$shipmethod         = 'USPS';

To:

Code:

$shipmethod         = 'USPS, UPSTOOLS';

Nick Hendler

Offline

 

#18 01-28-2015 18:18:24

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

Hello Nick,

I pasted below the script modified to your sugggestions...

<?php

$info               = $this->globals('ecom.customship');
$usps_weight_cutoff = 50;
$shipmethod         = 'USPS, UPSTOOLS';

if ($info['weight'] >= $usps_weight_cutoff) {$shipmethod = 'UPSTOOLS';}

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => $shipmethod,
                 'shiptype'      => 'R');

$result = $this->include_namespace('ecom','shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {

     if (preg_match('/UPS/',$service['name'])) {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.00);

     } else {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.30);

     } // End of if statement.

} // End of if statement.

$this->globals('ecom.customship_response',$custom);

?>

We are still having problems trying to get USPS rates to show on any level as well as UPS rates which are the only rates showing.  Our test item is an 8.5 lbs item which should trigger USPS alongside UPS rates since the item is under 50 lbs.  Please advise what we should look for.

Last edited by polarize (01-28-2015 18:20:56)


Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#19 01-29-2015 09:01:41

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Strange USPS Realtime Shipping Behavior

Are you updated to version 8.0.8?  Not sure if you're aware, but USPS switched over to RateV4 Sept 30, 2014, but didn't drop RateV3 until this past December.  If you're not using 8.0.8, you're not getting rates because you're still attaching to RateV3.  Here's info on the update:

https://kryptronic.com/blog/2014/09/sof … e-updates/


Nick Hendler

Offline

 

#20 01-29-2015 09:46:34

polarize
Member
Registered: 11-15-2004
Posts: 295

Re: Strange USPS Realtime Shipping Behavior

Thanks Nick!  We upgraded to the latest version and are now seeing USPS rates.  Thank you for all of your help smile

Last edited by polarize (01-29-2015 09:56:31)


Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

Board footer