From bd0e73287b21a36c3f856a62cd744e71e3715f39 Mon Sep 17 00:00:00 2001 From: ArthurLashermes <76913541+ArthurLashermes@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:44:33 +0200 Subject: [PATCH] fix 13 : update pse in cartItem route, fix json format (#95) * fix 13 : update pse in cartItem route, fix json format * increment version --------- Co-authored-by: ArthurLashermes --- Config/module.xml | 2 +- Controller/Front/CartController.php | 12 ++++++++++-- Controller/Front/CheckoutController.php | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Config/module.xml b/Config/module.xml index 889f635..35a9d18 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -19,7 +19,7 @@ en_US fr_FR - 2.2.27 + 2.2.28 Vincent Lopes-Vicente diff --git a/Controller/Front/CartController.php b/Controller/Front/CartController.php index f2da530..7c68877 100644 --- a/Controller/Front/CartController.php +++ b/Controller/Front/CartController.php @@ -407,14 +407,22 @@ protected function updateCartEventFromJson($data, CartEvent $event): void throw new \Exception(Translator::getInstance()->trans('A quantity is needed in the POST request to add an item to the cart.')); } - /* If the function was called from the PATCH route, we just update the quantity and return */ + /* If the function was called from the PATCH route, we just update the quantity,pse,product id and return */ if ($cartItemId = $event->getCartItemId()) { $cartItem = CartItemQuery::create()->filterById($cartItemId)->findOne(); if ($this->checkAvailableStock($cartItem->getProductSaleElements(), $data['quantity'])) { throw new \Exception(Translator::getInstance()->trans('Desired quantity exceed available stock')); } $event->setQuantity($data['quantity']); - + if (!isset($data['pseId'])) { + return; + } + $cartItem = CartItemQuery::create()->filterById($cartItemId)->findOne(); + $pse = ProductSaleElementsQuery::create()->findPk($data['pseId']); + $cartItem + ->setProductId($pse->getProductId()) + ->setProductSaleElementsId($data['pseId']) + ->save(); return; } diff --git a/Controller/Front/CheckoutController.php b/Controller/Front/CheckoutController.php index ca07b79..f40745b 100644 --- a/Controller/Front/CheckoutController.php +++ b/Controller/Front/CheckoutController.php @@ -161,7 +161,11 @@ public function getCheckout( $checkout = ($modelFactory->buildModel('Checkout')) ->createFromOrder($order); - $checkout->setPickupAddress($request->getSession()->get(OpenApi::PICKUP_ADDRESS_SESSION_KEY)); + $pickupAddress = $modelFactory->buildModel('Address'); + $pickupAddress?->createOrUpdateFromData($request->getSession()?->get(OpenApi::PICKUP_ADDRESS_SESSION_KEY)); + $checkout->setPickupAddress( + $pickupAddress + ); $checkout->setPaymentOptionChoices( $request->getSession()->get(self::PAYMENT_MODULE_OPTION_CHOICES_SESSION_KEY)