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.
We are using the realtime shipping method, customized for an upcharge as follows:
<?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
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
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.
Offline
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
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.
Offline
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
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....
<?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); ?>
Offline
I think you'll want to use something like this:
<?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); ?>
Offline
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..
<?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); ?>
Offline
Your code was just plain incorrect and had a syntax error in it to boot. Try this:
<?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); ?>
Offline
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
Offline
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.
Offline
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...
$usps_weight_cutoff = 10;
and
} 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.
Offline
This one does USPS rates under the cutoff and UPS at and above the cutoff:
<?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); ?>
Offline
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
Offline
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)
Offline
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/
Offline
Thanks Nick! We upgraded to the latest version and are now seeing USPS rates. Thank you for all of your help
Last edited by polarize (01-29-2015 09:56:31)
Offline