Page 1 of 1
USPS Shipping Rates are to high
Posted: Sat Dec 05, 2009 2:32 am
by matt6805
I'm having an issue with the USPS module. When I ship something that weights just a touch over a pound Priority mail, the module returns a value of $12.40. I'm shipping it to my home town, so it's as close as possible. I called USPS and they said that's way to high. It should be around 4 dollars.
When i adjust the weight of a product in the admin section to 1 ounce, the price shows as correct $4.95 cents. What could account for the weight measurements being so off? I'm running OpenCart v1.3.4. Has anyone else seen this issue?
Regards,
Matt
Re: USPS Shipping Rates are to high
Posted: Sat Dec 05, 2009 4:23 am
by Daniel
check your weight classes.
Re: USPS Shipping Rates are to high
Posted: Tue Dec 08, 2009 12:00 am
by matt6805
Thanks for the reply Daniel. My weight classes are the default that come with OpenCart. I haven't touched them. All products are set to use ounces, so I'm not sure why the rate is so high.
I've left the dimensions and the girth fields in the USPS shipping module blank. Do you suppose that would be the reason for the high shipping?
Regards,
Matt
Re: USPS Shipping Rates are to high
Posted: Tue Dec 08, 2009 12:18 am
by Qphoria
The weight calculation is bugged.
Code: Select all
$weight = $this->cart->getWeight();
$weight = ($weight < 0.1 ? 0.1 : $weight);
$pounds = floor($weight);
$ounces = round(16 * ($weight - floor($weight)));
The way this reads, if you have a product set 16oz, that should be 1lb
But the code assumes lbs is the default weight. So it is making 16lbs.
It needs to do a weight conversion to lbs first, then do the floor & round calls.
1. EDIT: catalog/model/shipping/usps.php
2. FIND:
Code: Select all
$weight = $this->cart->getWeight();
3. REPLACE WITH:
Code: Select all
$lb = $this->db->query("SELECT DISTINCT weight_class_id FROM " . DB_PREFIX . "weight_class WHERE unit = 'lb'");
$weight = $this->weight->convert($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $lb->row['weight_class_id']);
Re: USPS Shipping Rates are to high
Posted: Tue Dec 08, 2009 3:46 am
by matt6805
You have just fixed days of frustration. Thank you so much! Love the cart, can't wait till more people contribute to it and the community grows.
Regards,
Matt
Re: USPS Shipping Rates are to high
Posted: Thu Dec 31, 2009 2:49 am
by JNeuhoff
The USPS code line
Code: Select all
$weight = $this->cart->getWeight();
should be replaced with
Code: Select all
$defaultWeightClassId = $this->config->get('config_weight_class_id');
$query = $this->db->query("SELECT wc.weight_class_id FROM `".DB_PREFIX."weight_class` wc LEFT JOIN `".DB_PREFIX."language` l ON l.language_id=wc.language_id WHERE l.code='en' AND wc.unit='lb';");
$poundWeightClassId = $query->row['weight_class_id'];
$weight = $this->weight->convert($this->cart->getWeight(),$defaultWeightClassId,$poundWeightClassId);
As regards the other 'weight' shipping module: Make sure the weights are specified in the default weight units. The latter was set at Opencart's admin backend at
Admin > Configuration > Setting > Local > Weight Class
Re: USPS Shipping Rates are to high
Posted: Thu Dec 31, 2009 10:11 am
by Qphoria
JNeuhoff wrote:The USPS code line
Code: Select all
$weight = $this->cart->getWeight();
should be replaced with
Code: Select all
$defaultWeightClassId = $this->config->get('config_weight_class_id');
$query = $this->db->query("SELECT wc.weight_class_id FROM `".DB_PREFIX."weight_class` wc LEFT JOIN `".DB_PREFIX."language` l ON l.language_id=wc.language_id WHERE l.code='en' AND wc.unit='lb';");
$poundWeightClassId = $query->row['weight_class_id'];
$weight = $this->weight->convert($this->cart->getWeight(),$defaultWeightClassId,$poundWeightClassId);
As regards the other 'weight' shipping module: Make sure the weights are specified in the default weight units. The latter was set at Opencart's admin backend at
Admin > Configuration > Setting > Local > Weight Class
Didn't I address this above already?
Re: USPS Shipping Rates are to high
Posted: Thu Dec 31, 2009 9:14 pm
by JNeuhoff
Didn't I address this above already?
Yes, except that my SQL query also makes sure that is uses the weight_class_id for the right language as well as the right weight unit.
Re: USPS Shipping Rates are to high
Posted: Fri Jan 01, 2010 8:27 am
by Qphoria
I see.... tho is it likely that an english "lb" would be different than the value of a spanish "lb"? There really is no way to have a separate language for lb as that is the code and languages are dependencies of the code, not the code dependent on the language.
the "lb" is the deciding factor.
Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 12:10 am
by flyfishingcolorado
I have adjusted the code Juergen has suggested. That fixed some of the error that I was getting. Now I get
Notice: Undefined variable: shipping_address in catalog/model/shipping/usps.php on line 358
Notice: Undefined index: IntlRateResponse in catalog/model/shipping/usps.php on line 373
I know my usps user and password are working on the USPS production server because I have tested them in another shopping cart script test.
Any ideas on this.
Any help would be appreciated
Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 1:08 am
by JNeuhoff
I think the line near 358:
Code: Select all
if ($shipping_address['iso_code_2'] == 'US') {
should be replaced with:
Code: Select all
if ($country_info['iso_code_2'] == 'US') {
The other error should then disappear, too. Looks like this shipping module wasn't well tested. But we are getting there

Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 4:07 am
by flyfishingcolorado
1/1/10
Thanks Juergen, This fixed the errors and my choices selected on the USPS extension setup show up just fine in cart checkout.
Now everything for USPS is controlled by the individual product data setup which is as it should be.
To all who may read this reply. You do need to use the dimensions in each product data setup. I suggest using the dimensions of the normal shipping container you will use to ship the product. Also the weight should be the shipping weight.
Finally when J. Nuehoff speaks on Open Cart, pay attention. He knows this product. Same goes for Qphoria.
Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 8:22 am
by Qphoria
JNeuhoff wrote:I think the line near 358:
Code: Select all
if ($shipping_address['iso_code_2'] == 'US') {
should be replaced with:
Code: Select all
if ($country_info['iso_code_2'] == 'US') {
The other error should then disappear, too. Looks like this shipping module wasn't well tested. But we are getting there

All the usps bugs with php errors were fixed here:
http://forum.opencart.com/viewtopic.php ... sps#p39586
it does not, however, include the getweight fix to use only products that have required shipping set.
Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 9:47 pm
by flyfishingcolorado
This is a general observation.
If you are using PayPal as the payment module, PayPal forces you to use their shipping calculations even if you think every shipping method you set up on PayPal is inactive.
Unfortunately OpenCart does not allow us to disable the shipping methods when using PayPal for payment.
I tested this 1/2 with extensive transactions on the live paypal server and everytime Paypal would add their shipping to my USPS calculated shipping.
Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 9:51 pm
by flyfishingcolorado
read my reply about using PayPal and USPS rates to high in the usps thread.
OpenCart needs to allow us to turn off all shipping modules when using PayPal as a payment method. PayPal forces you to use their shipping calculations even if you think they are inactive. I know because I tested 10 transactions tonight to confirm that shipping will be added to the total of the Open Cart amount which already includes shipping.
Re: USPS Shipping Rates are to high
Posted: Sat Jan 02, 2010 10:01 pm
by Qphoria
flyfishingcolorado wrote:
OpenCart needs to allow us to turn off all shipping modules when using PayPal as a payment method. PayPal forces you to use their shipping calculations even if you think they are inactive. I know because I tested 10 transactions tonight to confirm that shipping will be added to the total of the Open Cart amount which already includes shipping.
I sell all digital downloads on my site and have require shipping off.. when people checkout with paypal there is no forced shipping. You must have some other settings set on your paypal account. There is no code in the paypal module that is forcing paypal shipping rates