6 replies [Last post]
VitaLife's picture
Offline
Bug Finder
Joined: 10/29/2007
Juice: 249
Was this information Helpful?

I've noticed some weirdness with my shipping quotes so I thought I'd try to track it down tonight. I was getting very high USPS rates. Here is the situation. Since I ship small items (vitamins), we can normally ship several in a package. First we had our pkg_qty set a 1, and UPS rates were coming up high, becuase if someone ordered 3 bottles of a product, UPS would calculate this as 3 boxes instead of 1, so the UPS rate was high. We decided to up the pkg_qty on all our products, and now USPS rates are very high. If I set pkg_qty to 99, the USPS multiplies 99 x the weight and the .5 lb bottle now weights 50 pounds. I have attached USPS and UPS examples. How can I set my cart to always assume things ship in 1 box regardless of quantity? These examples are for 3 bottles that weight 0.6 lbs each.

With pkg_qty of 1 USPS comes up correct at $5.28 to ship, but UPS is way too high $21.98 ground.

<?php
USPS
<RateV3Response>
  <
Package ID="0">
    <
ZipOrigination>32065</ZipOrigination>
    <
ZipDestination>32068</ZipDestination>
    <
Pounds>0</Pounds>
    <
Ounces>9.6</Ounces>
    <
Size>REGULAR</Size>
    <
Machinable>FALSE</Machinable>
    <
Zone>1, Intra-BMC</Zone>
    <
Postage CLASSID="2">
      <
MailService>Express Mail Hold For Pickup</MailService>
      <
Rate>14.55</Rate>
    </
Postage>
    <
Postage CLASSID="27">
      <
MailService>Express Mail Flat-Rate Envelope Hold For Pickup</MailService>
      <
Rate>16.50</Rate>
    </
Postage>
    <
Postage CLASSID="3">
      <
MailService>Express Mail</MailService>
      <
Rate>14.55</Rate>
    </
Postage>
    <
Postage CLASSID="13">
      <
MailService>Express Mail Flat-Rate Envelope</MailService>
      <
Rate>16.50</Rate>
    </
Postage>
    <
Postage CLASSID="1">
      <
MailService>Priority Mail</MailService>
      <
Rate>4.80</Rate>
    </
Postage>
    <
Postage CLASSID="16">
      <
MailService>Priority Mail Flat-Rate Envelope</MailService>
      <
Rate>4.80</Rate>
    </
Postage>
    <
Postage CLASSID="17">
      <
MailService>Priority Mail Flat-Rate Box</MailService>
      <
Rate>9.80</Rate>
    </
Postage>
    <
Postage CLASSID="22">
      <
MailService>Priority Mail Large Flat-Rate Box</MailService>
      <
Rate>12.95</Rate>
    </
Postage>
    <
Postage CLASSID="0">
      <
MailService>First-Class Mail Flat</MailService>
      <
Rate>2.70</Rate>
    </
Postage>
    <
Postage CLASSID="0">
      <
MailService>First-Class Mail Parcel</MailService>
      <
Rate>2.70</Rate>
    </
Postage>
    <
Postage CLASSID="4">
      <
MailService>Parcel Post</MailService>
      <
Rate>6.75</Rate>
    </
Postage>
    <
Postage CLASSID="5">
      <
MailService>Bound Printed Matter</MailService>
      <
Rate>2.15</Rate>
    </
Postage>
    <
Postage CLASSID="6">
      <
MailService>Media Mail</MailService>
      <
Rate>2.23</Rate>
    </
Postage>
    <
Postage CLASSID="7">
      <
MailService>Library Mail</MailService>
      <
Rate>2.12</Rate>
    </
Postage>
  </
Package>
</
RateV3Response>

UPS
<Package>
  <
PackagingType>
    <
Code>02</Code>
  </
PackagingType>
  <
Dimensions>
    <
UnitOfMeasurement>
      <
Code>IN</Code>
    </
UnitOfMeasurement>
    <
Length>7.00</Length>
    <
Width>7.00</Width>
    <
Height>7.00</Height>
  </
Dimensions>
  <
PackageWeight>
    <
UnitOfMeasurement>
      <
Code>LBS</Code>
      <
Description>Pounds</Description>
    </
UnitOfMeasurement>
    <
Weight>1.0</Weight>
  </
PackageWeight>
  <
PackageServiceOptions>
    <
InsuredValue>
      <
CurrencyCode>USD</CurrencyCode>
      <
MonetaryValue>10.95</MonetaryValue>
    </
InsuredValue>
  </
PackageServiceOptions>
</
Package>
<
Package>
  <
PackagingType>
    <
Code>02</Code>
  </
PackagingType>
  <
Dimensions>
    <
UnitOfMeasurement>
      <
Code>IN</Code>
    </
UnitOfMeasurement>
    <
Length>7.00</Length>
    <
Width>7.00</Width>
    <
Height>7.00</Height>
  </
Dimensions>
  <
PackageWeight>
    <
UnitOfMeasurement>
      <
Code>LBS</Code>
      <
Description>Pounds</Description>
    </
UnitOfMeasurement>
    <
Weight>1.0</Weight>
  </
PackageWeight>
  <
PackageServiceOptions>
    <
InsuredValue>
      <
CurrencyCode>USD</CurrencyCode>
      <
MonetaryValue>10.95</MonetaryValue>
    </
InsuredValue>
  </
PackageServiceOptions>
</
Package>
<
Package>
  <
PackagingType>
    <
Code>02</Code>
  </
PackagingType>
  <
Dimensions>
    <
UnitOfMeasurement>
      <
Code>IN</Code>
    </
UnitOfMeasurement>
    <
Length>7.00</Length>
    <
Width>7.00</Width>
    <
Height>7.00</Height>
  </
Dimensions>
  <
PackageWeight>
    <
UnitOfMeasurement>
      <
Code>LBS</Code>
      <
Description>Pounds</Description>
    </
UnitOfMeasurement>
    <
Weight>1.0</Weight>
  </
PackageWeight>
  <
PackageServiceOptions>
    <
InsuredValue>
      <
CurrencyCode>USD</CurrencyCode>
      <
MonetaryValue>10.95</MonetaryValue>
    </
InsuredValue>
  </
PackageServiceOptions>
</
Package>
</
Shipment>
</
RatingServiceSelectionRequestRatingServiceSelectionResponse><Response><TransactionReference><CustomerContext>Complex Rate Request</CustomerContext>
<
XpciVersion>1.0001</XpciVersion>
</
TransactionReference>
<
ResponseStatusCode>1</ResponseStatusCode>
<
ResponseStatusDescription>Success</ResponseStatusDescription>
</
Response>
<
RatedShipment>
<
Service>
<
Code>03</Code>
</
Service>
<
RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
<
BillingWeight>
<
UnitOfMeasurement>
  <
Code>LBS</Code>
</
UnitOfMeasurement>
<
Weight>3.0</Weight>
</
BillingWeight>
<
TransportationCharges>
<
CurrencyCode>USD</CurrencyCode>
<
MonetaryValue>19.98</MonetaryValue>
</
TransportationCharges>
<
ServiceOptionsCharges>
<
CurrencyCode>USD</CurrencyCode>
<
MonetaryValue>0.00</MonetaryValue>
</
ServiceOptionsCharges>
<
TotalCharges>
<
CurrencyCode>USD</CurrencyCode>
<
MonetaryValue>19.98</MonetaryValue>
</
TotalCharges>
<
GuaranteedDaysToDelivery></GuaranteedDaysToDelivery>
<
ScheduledDeliveryTime></ScheduledDeliveryTime>
<
RatedPackage>
<
TransportationCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>6.66</MonetaryValue>
</
TransportationCharges>
<
ServiceOptionsCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>0.00</MonetaryValue>
</
ServiceOptionsCharges>
<
TotalCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>6.66</MonetaryValue>
</
TotalCharges>
<
Weight>1.0</Weight>
<
BillingWeight>
  <
UnitOfMeasurement>
    <
Code>LBS</Code>
  </
UnitOfMeasurement>
  <
Weight>1.0</Weight>
</
BillingWeight>
</
RatedPackage>
<
RatedPackage>
<
TransportationCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>6.66</MonetaryValue>
</
TransportationCharges>
<
ServiceOptionsCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>0.00</MonetaryValue>
</
ServiceOptionsCharges>
<
TotalCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>6.66</MonetaryValue>
</
TotalCharges>
<
Weight>1.0</Weight>
<
BillingWeight>
  <
UnitOfMeasurement>
    <
Code>LBS</Code>
  </
UnitOfMeasurement>
  <
Weight>1.0</Weight>
</
BillingWeight>
</
RatedPackage>
<
RatedPackage>
<
TransportationCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>6.66</MonetaryValue>
</
TransportationCharges>
<
ServiceOptionsCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>0.00</MonetaryValue>
</
ServiceOptionsCharges>
<
TotalCharges>
  <
CurrencyCode>USD</CurrencyCode>
  <
MonetaryValue>6.66</MonetaryValue>
</
TotalCharges>
<
Weight>1.0</Weight>
<
BillingWeight>
  <
UnitOfMeasurement>
    <
Code>LBS</Code>
  </
UnitOfMeasurement>
  <
Weight>1.0</Weight>
</
BillingWeight>
</
RatedPackage>
</
RatedShipment>
</
RatingServiceSelectionResponse>
?>

Same order with wiht pkg_qty set at 99 - USPS is now $36.52, but UPS is correct at $7.40

<?php
USPS
<RateV3Response>
  <
Package ID="0">
    <
ZipOrigination>32065</ZipOrigination>
    <
ZipDestination>32068</ZipDestination>
    <
Pounds>59</Pounds>
    <
Ounces>6.4</Ounces>
    <
Size>REGULAR</Size>
    <
Machinable>FALSE</Machinable>
    <
Zone>1, Intra-BMC</Zone>
    <
Postage CLASSID="2">
      <
MailService>Express Mail Hold For Pickup</MailService>
      <
Rate>106.00</Rate>
    </
Postage>
    <
Postage CLASSID="27">
      <
MailService>Express Mail Flat-Rate Envelope Hold For Pickup</MailService>
      <
Rate>16.50</Rate>
    </
Postage>
    <
Postage CLASSID="3">
      <
MailService>Express Mail</MailService>
      <
Rate>106.00</Rate>
    </
Postage>
    <
Postage CLASSID="13">
      <
MailService>Express Mail Flat-Rate Envelope</MailService>
      <
Rate>16.50</Rate>
    </
Postage>
    <
Postage CLASSID="1">
      <
MailService>Priority Mail</MailService>
      <
Rate>28.40</Rate>
    </
Postage>
    <
Postage CLASSID="16">
      <
MailService>Priority Mail Flat-Rate Envelope</MailService>
      <
Rate>4.80</Rate>
    </
Postage>
    <
Postage CLASSID="17">
      <
MailService>Priority Mail Flat-Rate Box</MailService>
      <
Rate>9.80</Rate>
    </
Postage>
    <
Postage CLASSID="22">
      <
MailService>Priority Mail Large Flat-Rate Box</MailService>
      <
Rate>12.95</Rate>
    </
Postage>
    <
Postage CLASSID="4">
      <
MailService>Parcel Post</MailService>
      <
Rate>17.19</Rate>
    </
Postage>
    <
Postage CLASSID="6">
      <
MailService>Media Mail</MailService>
      <
Rate>22.88</Rate>
    </
Postage>
    <
Postage CLASSID="7">
      <
MailService>Library Mail</MailService>
      <
Rate>21.59</Rate>
    </
Postage>
  </
Package>
  <
Package ID="1">
    <
ZipOrigination>32065</ZipOrigination>
    <
ZipDestination>32068</ZipDestination>
    <
Pounds>1</Pounds>
    <
Ounces>12.8</Ounces>
    <
Size>REGULAR</Size>
    <
Machinable>FALSE</Machinable>
    <
Zone>1, Intra-BMC</Zone>
    <
Postage CLASSID="2">
      <
MailService>Express Mail Hold For Pickup</MailService>
      <
Rate>15.70</Rate>
    </
Postage>
    <
Postage CLASSID="27">
      <
MailService>Express Mail Flat-Rate Envelope Hold For Pickup</MailService>
      <
Rate>16.50</Rate>
    </
Postage>
    <
Postage CLASSID="3">
      <
MailService>Express Mail</MailService>
      <
Rate>15.70</Rate>
    </
Postage>
    <
Postage CLASSID="13">
      <
MailService>Express Mail Flat-Rate Envelope</MailService>
      <
Rate>16.50</Rate>
    </
Postage>
    <
Postage CLASSID="1">
      <
MailService>Priority Mail</MailService>
      <
Rate>4.80</Rate>
    </
Postage>
    <
Postage CLASSID="16">
      <
MailService>Priority Mail Flat-Rate Envelope</MailService>
      <
Rate>4.80</Rate>
    </
Postage>
    <
Postage CLASSID="17">
      <
MailService>Priority Mail Flat-Rate Box</MailService>
      <
Rate>9.80</Rate>
    </
Postage>
    <
Postage CLASSID="22">
      <
MailService>Priority Mail Large Flat-Rate Box</MailService>
      <
Rate>12.95</Rate>
    </
Postage>
    <
Postage CLASSID="4">
      <
MailService>Parcel Post</MailService>
      <
Rate>7.23</Rate>
    </
Postage>
    <
Postage CLASSID="5">
      <
MailService>Bound Printed Matter</MailService>
      <
Rate>2.24</Rate>
    </
Postage>
    <
Postage CLASSID="6">
      <
MailService>Media Mail</MailService>
      <
Rate>2.58</Rate>
    </
Postage>
    <
Postage CLASSID="7">
      <
MailService>Library Mail</MailService>
      <
Rate>2.45</Rate>
    </
Postage>
  </
Package>
</
RateV3Response>

UPS

<RatingServiceSelectionRequest xml:lang="en-US">
  <
Request>
    <
TransactionReference>
      <
CustomerContext>Complex Rate Request</CustomerContext>
      <
XpciVersion>1.0001</XpciVersion>
    </
TransactionReference>
    <
RequestAction>Rate</RequestAction>
    <
RequestOption>rate</RequestOption>
  </
Request>
  <
PickupType>
    <
Code>01</Code>
  </
PickupType>
  <
CustomerClassification>
    <
Code>01</Code>
  </
CustomerClassification>
  <
Shipment>
    <
Shipper>
      <
ShipperNumber>X31787</ShipperNumber>
      <
Address>
        <
City>Orange Park</City>
        <
StateProvinceCode>FL</StateProvinceCode>
        <
PostalCode>32065</PostalCode>
        <
CountryCode>US</CountryCode>
      </
Address>
    </
Shipper>
    <
ShipTo>
      <
Address>
        <
StateProvinceCode>FL</StateProvinceCode>
        <
PostalCode>32068</PostalCode>
        <
CountryCode>US</CountryCode>
        <
ResidentialAddressIndicator/>
      </
Address>
    </
ShipTo>
    <
ShipFrom>
      <
Address>
        <
StateProvinceCode>FL</StateProvinceCode>
        <
PostalCode>32065</PostalCode>
        <
CountryCode>US</CountryCode>
      </
Address>
    </
ShipFrom>
    <
ShipmentWeight>
      <
UnitOfMeasurement>
        <
Code>LBS</Code>
      </
UnitOfMeasurement>
      <
Weight>1.8</Weight>
    </
ShipmentWeight>
    <
Service>
      <
Code>03</Code>
      <
Description>UPS Ground</Description>
    </
Service>
    <
Package>
      <
PackagingType>
        <
Code>02</Code>
      </
PackagingType>
      <
Dimensions>
        <
UnitOfMeasurement>
          <
Code>IN</Code>
        </
UnitOfMeasurement>
        <
Length>7.00</Length>
        <
Width>7.00</Width>
        <
Height>7.00</Height>
      </
Dimensions>
      <
PackageWeight>
        <
UnitOfMeasurement>
          <
Code>LBS</Code>
          <
Description>Pounds</Description>
        </
UnitOfMeasurement>
        <
Weight>1.8</Weight>
      </
PackageWeight>
      <
PackageServiceOptions>
        <
InsuredValue>
          <
CurrencyCode>USD</CurrencyCode>
          <
MonetaryValue>32.85</MonetaryValue>
        </
InsuredValue>
      </
PackageServiceOptions>
    </
Package>
  </
Shipment>
</
RatingServiceSelectionRequest
?>

Please Help.

Jim

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: UPS and USPS use pkg_qty differently

OK, fixed the layout for you.

First, I think I should make sure that you're on the latest version. There are a few lines in _uc_usps_package_products() that should look like

<?php
     
if (!$product->pkg_qty) {
       
$product->pkg_qty = 1;
      }
     
$num_of_pkgs = (int)($product->qty / $product->pkg_qty);
      if (
$num_of_pkgs) {
?>

What's supposed to happen is that the $product->qty (3) is divided by the $product->pkg_qty (99) and rounded down to get the number of full packages (should be 0). At the end of the if ($num_of_pkgs) block, it handles the remainder of the products in an extra package (which would contain 3).

If this all looks the same, try changing the line to

<?php
  $num_of_pkgs
= floor($product->qty / $product->pkg_qty);
?>

(int) is supposed to round it down on its own, but maybe for some reason it's rounding up. floor() always rounds down, regardless of how close the value is to the next number.

VitaLife's picture
Offline
Bug Finder
Joined: 10/29/2007
Juice: 249
I have the latest version

I made the change to line 580 above but to no avail. The problem is that the weight is getting calcuated by taking pkg_qty * wt

<?php
<Pounds>59</Pounds><Ounces>6.4</Ounces>
?>

U.S.P.S. Priority Mail: $36.52

I think this has to do with this line
$weight = $product->weight * $product->pkg_qty;

VitaLife's picture
Offline
Bug Finder
Joined: 10/29/2007
Juice: 249
More Info

Been looking at the code and thinking about this. Is this the correct assumption.

1. pkg_qty - should be set to the number of items you could fit in a single box, so if someone orders multiple quantities of a product, then it creates 1 box for them instead of many, if pkg_qty is 1 then it will create seperate packages in the UPS quote. So if I could put 20 bottles in a box, then I should be setting pkg_qty to 20.

2. This issue only arises when someone pick multiples of a single item, not multiple items, becuase the shipping config has an option to select all in one box.

3. I ship all my orders in a single box 98% of the time, and I assume that 95% of shippers are the same. (I'm thinking about the packages that I buy personally, most orders come in 1 box.) So this should be probably be the default option if not overriden.

4.In USPS module -> $weight = $product->weight * $product->pkg_qty; This seens to negate with info in #1 above. It seems to be like it should be inside of an if statement like it is on the ups module.

$num_of_pkgs = (int)($product->qty / $product->pkg_qty);
if ($num_of_pkgs) {
$package = drupal_clone($product);
$package->weight = $product->weight * $product->pkg_qty;

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: I have the latest version

No, that part makes sense if you have more than 99 products in your order. In that case you do want the package to weigh as much as 99 products, and not any more, because that's how many are going to be put in it.

The real problem is to figure out why the USPS module thinks you need a full package in addition to the not quite so full package that you really have. The bizarre thing is that that particular logic is exactly the same in the UPS module.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: I have the latest version

OK, I didn't see your latest post. It sounds like you understand correctly. However, if your uc_usps module doesn't have

<?php
 
if ($num_of_pkgs) {
?>

then you need to get the latest code, because it should definitely be there. I just tested this on the livetest, and didn't have any problems with high package quantities.

VitaLife's picture
Offline
Bug Finder
Joined: 10/29/2007
Juice: 249
That file was old

The latest usps module worked fine, now I just need to figure how I did upgrade w/o replacing that file. thanks, and sorry for the post.