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(checkout): fix mailbox options #844

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions Model/Quote/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@
$this->country = $forAddress['countryId'];
}

$packageType = $this->getPackageType();

$data = [
/* the 'method' string here is actually the carrier_code of the method */
'methods' => explode(',', $this->helper->getGeneralConfig('shipping_methods/methods') ?? ''),
'config' => array_merge(
$this->getGeneralData(),
$this->getDeliveryData(),
['packageType' => $this->getPackageType()]
$this->getDeliveryData($packageType),
['packageType' => $packageType]
),
'strings' => $this->getDeliveryOptionsStrings(),
'forAddress' => $forAddress,
Expand Down Expand Up @@ -163,9 +165,10 @@
/**
* Get delivery data
*
* @param string|null $packageType
* @return array
*/
private function getDeliveryData(): array
private function getDeliveryData(?string $packageType = null): array

Check warning on line 171 in Model/Quote/Checkout.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Model/Quote/Checkout.php#L171

The method getDeliveryData() has a Cyclomatic Complexity of 31. The configured cyclomatic complexity threshold is 12.

Check warning on line 171 in Model/Quote/Checkout.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Model/Quote/Checkout.php#L171

The method getDeliveryData() has an NPath complexity of 18433. The configured NPath complexity threshold is 225.
{
$myParcelConfig = [];
$activeCarriers = $this->getActiveCarriers();
Expand Down Expand Up @@ -221,6 +224,10 @@
$allowDeliveryOptions = ! $this->package->deliveryOptionsDisabled
&& ($allowPickup || $allowStandardDelivery || $allowMorningDelivery || $allowEveningDelivery);

if ($allowDeliveryOptions && $packageType === AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME) {
$allowDeliveryOptions = $this->helper->getBoolConfig($carrierPath, 'mailbox/active');
}

$myParcelConfig['carrierSettings'][$carrier] = [
'allowDeliveryOptions' => $allowDeliveryOptions,
'allowStandardDelivery' => $allowStandardDelivery,
Expand Down
13 changes: 2 additions & 11 deletions view/frontend/web/js/model/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,8 @@ function(

onReFetchDeliveryOptionsConfig: function(response) {
var configuration = response[0].data;
var carrier = Object.keys(configuration.config.carrierSettings)[0];

doRequest(function() {
return Model.calculatePackageType(carrier);
},
{
onSuccess: function(response) {
Model.bestPackageType = response;
Model.setDeliveryOptionsConfig(configuration);
},
});
Model.bestPackageType = configuration.config.packageType;
Model.setDeliveryOptionsConfig(configuration);
},

/**
Expand Down