Skip to content

Commit

Permalink
fix 13 : update pse in cartItem route, fix json format (#95)
Browse files Browse the repository at this point in the history
* fix 13 : update pse in cartItem route, fix json format

* increment version

---------

Co-authored-by: ArthurLashermes <alashermes@openstudio.fr>
  • Loading branch information
ArthurLashermes and ArthurLashermes authored Sep 19, 2024
1 parent 7327191 commit bd0e732
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.2.27</version>
<version>2.2.28</version>
<authors>
<author>
<name>Vincent Lopes-Vicente</name>
Expand Down
12 changes: 10 additions & 2 deletions Controller/Front/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion Controller/Front/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bd0e732

Please sign in to comment.