Skip to content

Commit

Permalink
Update getTotalWidth and getTotalLength function to assume multip…
Browse files Browse the repository at this point in the history
…le boxes will be stacked for better rate handling
  • Loading branch information
engram-design committed Oct 3, 2024
1 parent 862e651 commit 944ff99
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/models/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,34 +197,49 @@ public function getTotalWeight(CarrierInterface $carrier, int $decimals = 2): in
return $total;
}

public function getTotalWidth(CarrierInterface $carrier, int $decimals = 2): int
public function getTotalWidth(CarrierInterface $carrier, int $decimals = 2, bool $stacked = true): int
{
$total = 0;

foreach ($this->getPackagesForCarrier($carrier) as $package) {
$total += $package->getWidth($decimals);
// Even when dealing with totals, we assume a "stacked" approach for multiple boxes
if ($stacked) {
$total = max($total, $package->getWidth($decimals));
} else {
$total += $package->getWidth($decimals);
}
}

return $total;
}

public function getTotalHeight(CarrierInterface $carrier, int $decimals = 2): int
public function getTotalHeight(CarrierInterface $carrier, int $decimals = 2, bool $stacked = false): int
{
$total = 0;

foreach ($this->getPackagesForCarrier($carrier) as $package) {
$total += $package->getHeight($decimals);
// Even when dealing with totals, we assume a "stacked" approach for multiple boxes
if ($stacked) {
$total = max($total, $package->getHeight($decimals));
} else {
$total += $package->getHeight($decimals);
}
}

return $total;
}

public function getTotalLength(CarrierInterface $carrier, int $decimals = 2): int
public function getTotalLength(CarrierInterface $carrier, int $decimals = 2, bool $stacked = true): int
{
$total = 0;

foreach ($this->getPackagesForCarrier($carrier) as $package) {
$total += $package->getLength($decimals);
// Even when dealing with totals, we assume a "stacked" approach for multiple boxes
if ($stacked) {
$total = max($total, $package->getLength($decimals));
} else {
$total += $package->getLength($decimals);
}
}

return $total;
Expand Down

0 comments on commit 944ff99

Please sign in to comment.