In trying to figure out why my quotes were severely off what I thought they should be, I came across a few things in the uc_ucps.module code:
$package->container = $product->usps['container'];
$length_conversion = uc_length_conversion($product->length_units, 'in');
$package->length = max($product->length, $product->width) * $length_conversion;
$package->width = min($product->length, $product->width) * $length_conversion;
$package->height = $product->height * $length_conversion;
if ($package->length < $package->width) {
list($package->length, $package->width) = array($package->width, $package->length);
}
$package->girth = 2 * $package->width + 2 * $package->height;
$package->size = $package->length + $package->girth;
It appears as though its setting the girth off of the height and width, however its never checking that the height is the longest side. Since the length is first set to be the longer of the width and length via the min/max stuff, it seems redundant to have the following:
if ($package->length < $package->width) {
list($package->length, $package->width) = array($package->width, $package->length);
}
My hypothesis is that this is actually supposed to be
if ($package->length < $package->height) {
list($package->length, $package->height) = array($package->height, $package->length);
}
So that the longest side actually ends up being the length. As it is if I have a package for a wine bottle and I enter L=4in, W=4in, H=12In, I will end up with dimentional width of 36", when I should actually have 28". This is probably not a problem unless you are mailing something near the limit, but, well its inaccurate nonetheless. Length is supposed to be the longest side.
Secondly, and probably not that important except in edge cases:
switch ($product->weight_units) {
case 'g':
$weight = $weight / 1000;
case 'kg':
$weight = $weight * 2.2;
case 'lb':
$package->pounds = floor($weight);
$package->ounces = 16 * ($weight - $package->pounds);
break;
case 'oz':
$package->pounds = floor($weight / 16);
$package->ounces = $weight - $package->pounds * 16;
break;
}
I think the end result is supposed to be pounds and ounces, and it works for 'lb', and for 'oz', but it looks like 'g' is simply converting to kg, and 'kg' is simply converting to decimal lbs. So, well, if you have a store in the us, but you prefer g/kg for weight (maybe you sell chemistry supplies?? Edge case for sure)..
Its not going to convert all that well. It almost looks like its supposed to cascade through, converting grams to kg, then kg to decimal pounds, then decimal pounds to lbs and oz's.
Comments
Comment #1
tr commentedThanks. I fixed the length/width/height issue in 6.x-2.x and 7.x-3.x. The weight calculation is correct however. The point is to get package weight in pounds and ounces, which is what USPS requires. I replaced the conversion factors with constants which we already have defined and documented the cases where the break has been intentionally omitted.