marcopolo:
Has anyone integrated this module with Shipping Boxes Manager?
Coming back to this, looking at the changes that were needed for the most recent Shipping Boxes Manager and the changes made in that usps.php: there's not much for me to do.
The only changes made to work with USPS' WebTools and Shipping Boxes Manager is that the following:
// shipping boxes manager
if (MODULE_SHIPPING_BOXES_MANAGER_STATUS == 'true') {
global $packed_boxes, $total_weight;
if (is_array($packed_boxes) && sizeof($packed_boxes) && $total_weight > 0) {
//$shipping_num_boxes = sizeof($packed_boxes);
//$shipping_weight = round(($total_weight / $shipping_num_boxes), 2); // use our number of packages rather than Zen Cart's calculation, package weight will still have to be an average since we don't know which products are in the box.
$width = $height = $length = 0;
foreach ($packed_boxes as $packed_box) {
if ($packed_box['width'] > $width) $this->dimensions['width'] = $packed_box['width'];
if ($packed_box['height'] > $height) $this->dimensions['height'] = $packed_box['height'];
if ($packed_box['length'] > $length) $this->dimensions['length'] = $packed_box['length'];
}
$usps_shipping_weight = $shipping_weight;
}
}
The two commented out lines changes the "number of boxes" to the total size of the array of packed boxes. Additionally, the module would loop through each "box" and set each dimension to the largest of each box and send that out to the quote request. (Looking at this line... I'm not sure how that came up... but anyway.)
The next blocks: called for the calculation of "girth" but the USPS API seems to remove that. Specifically blocks like this:
if (MODULE_SHIPPING_BOXES_MANAGER_STATUS == 'true' && $this->dimensions['width'] > 0 && $this->dimensions['length'] > 0 && $this->dimensions['height' > 0]) {
$width = $this->dimensions['width'];
$length = $this->dimensions['length'];
$height = $this->dimensions['height'];
$girth = 0;
$SBM_additonal_size = '<Size>REGULAR</Size>';
if($width >= 12){
$SBM_additonal_size = '<Size>LARGE</Size>';
$girth = $width + $width + $length + $length;
$ground_servs = '<GroundOnly>true</GroundOnly>';
}
$SBM_additonal_dem = '';
$SBM_additonal_dem = '<Width>' . $width . '</Width>' .
'<Length>' . $length . '</Length>' .
'<Height>' . $height . '</Height>' .
'<Girth>' . $girth . '</Girth>';
} else {
$SBM_additonal_dem = '';
$SBM_additonal_size = '<Size>REGULAR</Size>';
}
The USPS REST API doesn't allow for the girth field to be used. (I'm assuming it's calculated on the API side and not so much locally.) So this is kind of moot.
Instead of forcing this, I'm going to expand the notifier/observer for NOTIFY_SHIPPING_USPS_BEFORE_GETQUOTE to include a way to modify the dimensions (which are now stored in an array). Additionally that same notifier/observer will also allow you to modify the number of shipping boxes and the weight of the package as well by this:
$this->notify('NOTIFY_SHIPPING_USPS_BEFORE_GETQUOTE', [], $order, $this->quote_weight, $shipping_num_boxes, $this->dimensions);
Using that notifier, it will be triggered immediately before the quote log is started and the quote is dispatched to the USPS server. If there's something I'm missing, by all means, let me know.