From 176a7647f1c59052972be8e73c1248a2936c5297 Mon Sep 17 00:00:00 2001 From: Rostislav Vitek Date: Fri, 19 Apr 2024 15:22:00 +0200 Subject: [PATCH 1/2] FE API: applied promo code is now taken into account in priceByTransportQuery and priceByPaymentQuery --- .../app/config/services_frontend_api.yaml | 4 + .../FrontendApi/Resolver/Price/PriceQuery.php | 133 ++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 project-base/app/src/FrontendApi/Resolver/Price/PriceQuery.php diff --git a/project-base/app/config/services_frontend_api.yaml b/project-base/app/config/services_frontend_api.yaml index d875ec58bff..f7c350ecf7f 100644 --- a/project-base/app/config/services_frontend_api.yaml +++ b/project-base/app/config/services_frontend_api.yaml @@ -135,3 +135,7 @@ services: App\FrontendApi\Component\SessionChecker\SessionChecker: tags: - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse, priority: -999 } # must be run before the session is closed (in Symfony\Component\HttpKernel\EventListener\SessionListener::onKernelResponse) + + Shopsys\FrontendApiBundle\Model\Resolver\Price\PriceQuery: + alias: App\FrontendApi\Resolver\Price\PriceQuery + public: true diff --git a/project-base/app/src/FrontendApi/Resolver/Price/PriceQuery.php b/project-base/app/src/FrontendApi/Resolver/Price/PriceQuery.php new file mode 100644 index 00000000000..0f423a52e20 --- /dev/null +++ b/project-base/app/src/FrontendApi/Resolver/Price/PriceQuery.php @@ -0,0 +1,133 @@ +currentCustomerUser->findCurrentCustomerUser(); + + if ($customerUser === null && $cartUuid === null) { + return $this->calculateIndependentTransportPrice($transport); + } + + /** @var \App\Model\Cart\Cart $cart */ + $cart = $this->cartApiFacade->findCart($customerUser, $cartUuid); + + if ($cart === null) { + return $this->calculateIndependentTransportPrice($transport); + } + + $domainId = $this->domain->getId(); + $currency = $this->currencyFacade->getDomainDefaultCurrencyByDomainId($domainId); + $orderPreview = $this->orderPreviewFactory->create( + $currency, + $domainId, + $cart->getQuantifiedProducts(), + $transport, + null, + $customerUser, + null, + null, + $cart->getFirstAppliedPromoCode(), + ); + + return $this->transportPriceCalculation->calculatePrice( + $transport, + $currency, + $orderPreview->getProductsPrice(), + $domainId, + ); + } + + /** + * @param \App\Model\Payment\Payment $payment + * @param string|null $cartUuid + * @param \ArrayObject|null $context + * @return \Shopsys\FrameworkBundle\Model\Pricing\Price + */ + public function priceByPaymentQuery( + Payment $payment, + ?string $cartUuid = null, + ?ArrayObject $context = null, + ): Price { + $cartUuid = $cartUuid ?? GqlContextHelper::getCartUuid($context); + $orderUuid = GqlContextHelper::getOrderUuid($context); + + if ($cartUuid === null && $orderUuid !== null) { + $order = $this->orderApiFacade->getByUuid($orderUuid); + + return $this->paymentPriceCalculation->calculatePrice( + $payment, + $order->getCurrency(), + $order->getTotalProductsPrice(), + $order->getDomainId(), + ); + } + + $customerUser = $this->currentCustomerUser->findCurrentCustomerUser(); + + if ($customerUser === null && $cartUuid === null) { + return $this->calculateIndependentPaymentPrice($payment); + } + + /** @var \App\Model\Cart\Cart $cart */ + $cart = $this->cartApiFacade->findCart($customerUser, $cartUuid); + + if ($cart === null) { + return $this->calculateIndependentPaymentPrice($payment); + } + + $domainId = $this->domain->getId(); + $currency = $this->currencyFacade->getDomainDefaultCurrencyByDomainId($domainId); + $orderPreview = $this->orderPreviewFactory->create( + $currency, + $domainId, + $cart->getQuantifiedProducts(), + null, + $payment, + $customerUser, + null, + null, + $cart->getFirstAppliedPromoCode(), + ); + + return $this->paymentPriceCalculation->calculatePrice( + $payment, + $currency, + $orderPreview->getProductsPrice(), + $domainId, + ); + } +} From e20539a4f4a563ad3a8987e76425022837862cbb Mon Sep 17 00:00:00 2001 From: Rostislav Vitek Date: Fri, 19 Apr 2024 15:29:51 +0200 Subject: [PATCH 2/2] add upgrade notes --- UPGRADE-14.0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPGRADE-14.0.md b/UPGRADE-14.0.md index 0303527d58c..21bf06c7c2c 100644 --- a/UPGRADE-14.0.md +++ b/UPGRADE-14.0.md @@ -1497,6 +1497,10 @@ Follow the instructions in relevant sections, e.g. `shopsys/coding-standards` or - see #project-base-diff to update your project - fix friendly URLs ([#3115](https://github.com/shopsys/shopsys/pull/3115)) + + - see #project-base-diff to update your project + +- take promo code into account in priceByTransportQuery and priceByPaymentQuery ([#3118](https://github.com/shopsys/shopsys/pull/3118)) - see #project-base-diff to update your project ### Storefront