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

set fallback id when the value from the basket is not available in th… #1197

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Changes from 2 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
21 changes: 19 additions & 2 deletions src/Services/CheckoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use IO\Events\Checkout\CheckoutReadonlyChanged;
use IO\Helper\ArrayHelper;
use IO\Helper\MemoryCache;
use IO\Helper\Utils;
use Plenty\Modules\Accounting\Contracts\AccountingLocationRepositoryContract;
use Plenty\Modules\Basket\Contracts\BasketRepositoryContract;
use Plenty\Modules\Basket\Events\Basket\AfterBasketChanged;
Expand All @@ -29,7 +30,6 @@
use Plenty\Plugin\Events\Dispatcher;
use Plenty\Plugin\Log\Loggable;
use Plenty\Plugin\Translation\Translator;
use IO\Helper\Utils;

/**
* Class CheckoutService
Expand Down Expand Up @@ -665,6 +665,24 @@ function () {
if (!is_null($order)) {
$isNet = $order->isNet;
}
$basket = $this->basketService->getBasket();
$fallbackShippingProfileId = null;
$exists = false;
if (is_array($list)) {
foreach ($list as $key => $shippingProfile) {
if (is_null($fallbackShippingProfileId)) {
$fallbackShippingProfileId = $shippingProfile['parcelServicePresetId'];
}
if ($basket->shippingProfileId == $shippingProfile['parcelServicePresetId']) {
$exists = true;
break;
}
}
}
if ($exists === false && !is_null($fallbackShippingProfileId)) {
$this->setShippingProfileId($fallbackShippingProfileId, true);
}

if (($isNet && !(bool)$accountSettings->showShippingVat) || (!$isNet && $showNetPrice)) {
$maxVatValue = $this->basketService->getMaxVatValue();

Expand All @@ -677,7 +695,6 @@ function () {
}
}

$basket = $this->basketService->getBasket();
if ($basket->currency !== $this->currencyExchangeRepo->getDefaultCurrency()) {
if (is_array($list)) {
foreach ($list as $key => $shippingProfile) {
Expand Down
Loading