Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: honor package type choice from admin #862

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions Model/Sales/TrackTraceHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options)
$this->dataHelper->setOrderStatus($magentoTrack->getOrderId(), Order::STATE_NEW);
}

if (isset($deliveryOptions['packageType'])) {
$options['package_type'] = $deliveryOptions['packageType'];
}
$packageType = $this->getPackageType($options, $magentoTrack, $address);
$packageType = $this->getPackageType($magentoTrack, $address, $options, $deliveryOptions);
$dropOffPoint = $this->dataHelper->getDropOffPoint(
CarrierFactory::createFromName($deliveryOptionsAdapter->getCarrier())
);
Expand Down Expand Up @@ -502,24 +499,24 @@ private function getCarrierFromOptions(array $options): ?string
}

/**
* @param array $options
* @param string $packageType
* @param Order\Shipment\Track $magentoTrack
* @param object $address
* @param array $options
* @param array $deliveryOptions
*
* @return int
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getPackageType(array $options, Track $magentoTrack, $address): int
private function getPackageType(Track $magentoTrack, $address, array $options, array $deliveryOptions): int
{
if ($this->getAgeCheck($magentoTrack, $address, $options)) {
return AbstractConsignment::PACKAGE_TYPE_PACKAGE;
}

// get package type from selected radio buttons and check if package type is set
// get package type from selected radio buttons, try to get from delivery options when default or not set
$packageType = $options['package_type'] ?? 'default';
if ('default' === $packageType) {
$packageType = self::$defaultOptions->getPackageType();
$packageType = $deliveryOptions['packageType'] ?? self::$defaultOptions->getPackageType();
}

if (! is_numeric($packageType)) {
Expand Down