diff --git a/classes/Cart.php b/classes/Cart.php index e1f24b73c5206..5d4e73babfcc2 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1129,7 +1129,8 @@ private function getOrderPrices( isset($productRow['id_product_attribute']) ? (int) $productRow['id_product_attribute'] : 0, true, false, - true + true, + isset($productRow['id_customization']) ? (int) $productRow['id_customization'] : 0 ); $orderPrices['price_without_reduction_without_tax'] = Product::getPriceFromOrder( @@ -1138,7 +1139,8 @@ private function getOrderPrices( isset($productRow['id_product_attribute']) ? (int) $productRow['id_product_attribute'] : 0, false, false, - true + true, + isset($productRow['id_customization']) ? (int) $productRow['id_customization'] : 0 ); $orderPrices['price_with_reduction'] = Product::getPriceFromOrder( @@ -1147,7 +1149,8 @@ private function getOrderPrices( isset($productRow['id_product_attribute']) ? (int) $productRow['id_product_attribute'] : 0, true, true, - true + true, + isset($productRow['id_customization']) ? (int) $productRow['id_customization'] : 0 ); $orderPrices['price'] = $orderPrices['price_with_reduction_without_tax'] = Product::getPriceFromOrder( @@ -1156,7 +1159,8 @@ private function getOrderPrices( isset($productRow['id_product_attribute']) ? (int) $productRow['id_product_attribute'] : 0, false, true, - true + true, + isset($productRow['id_customization']) ? (int) $productRow['id_customization'] : 0 ); // If the product price was not found in the order, use cart prices as fallback diff --git a/classes/Product.php b/classes/Product.php index e4ff082c35c71..61981bac5e26e 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -4057,7 +4057,8 @@ public static function getPriceFromOrder( int $combinationId, bool $withTaxes, bool $useReduction, - bool $withEcoTax + bool $withEcoTax, + int $customizationId = 0 ): ?float { $sql = new DbQuery(); $sql->select('od.*, t.rate AS tax_rate'); @@ -4067,6 +4068,9 @@ public static function getPriceFromOrder( if (Combination::isFeatureActive()) { $sql->where('od.`product_attribute_id` = ' . $combinationId); } + if (Customization::isFeatureActive()) { + $sql->where('od.`id_customization` = ' . $customizationId); + } $sql->leftJoin('order_detail_tax', 'odt', 'odt.id_order_detail = od.id_order_detail'); $sql->leftJoin('tax', 't', 't.id_tax = odt.id_tax'); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); diff --git a/src/Adapter/Order/CommandHandler/AddProductToOrderHandler.php b/src/Adapter/Order/CommandHandler/AddProductToOrderHandler.php index 6f98efc774207..703d8a712c8f8 100644 --- a/src/Adapter/Order/CommandHandler/AddProductToOrderHandler.php +++ b/src/Adapter/Order/CommandHandler/AddProductToOrderHandler.php @@ -207,7 +207,8 @@ public function handle(AddProductToOrderCommand $command) $command->getProductId()->getValue(), null !== $command->getCombinationId() ? $command->getCombinationId()->getValue() : 0, $command->getProductPriceTaxExcluded(), - $command->getProductPriceTaxIncluded() + $command->getProductPriceTaxIncluded(), + 0 ); StockAvailable::synchronize($product->id); diff --git a/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php b/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php index 4d126f60227b3..e16d3f854fae9 100644 --- a/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php +++ b/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php @@ -119,7 +119,8 @@ public function handle(UpdateProductInOrderCommand $command) (int) $orderDetail->product_id, (int) $orderDetail->product_attribute_id, $command->getPriceTaxExcluded(), - $command->getPriceTaxIncluded() + $command->getPriceTaxIncluded(), + (int) $orderDetail->id_customization ); // Update invoice, quantity and amounts diff --git a/src/Adapter/Order/OrderAmountUpdater.php b/src/Adapter/Order/OrderAmountUpdater.php index b119bb65d7cab..10419d1e3d92b 100644 --- a/src/Adapter/Order/OrderAmountUpdater.php +++ b/src/Adapter/Order/OrderAmountUpdater.php @@ -371,7 +371,7 @@ private function updateOrderDetails(Order $order, Cart $cart): void $cartProducts = $cart->getProducts(true, false, null, true, $this->keepOrderPrices); foreach ($order->getCartProducts() as $orderProduct) { $orderDetail = new OrderDetail($orderProduct['id_order_detail'], null, $this->contextStateManager->getContext()); - $cartProduct = $this->getProductFromCart($cartProducts, (int) $orderDetail->product_id, (int) $orderDetail->product_attribute_id); + $cartProduct = $this->getProductFromCart($cartProducts, (int) $orderDetail->product_id, (int) $orderDetail->product_attribute_id, (int) $orderDetail->id_customization); $this->orderDetailUpdater->updateOrderDetail( $orderDetail, @@ -389,17 +389,18 @@ private function updateOrderDetails(Order $order, Cart $cart): void * * @return array */ - private function getProductFromCart(array $cartProducts, int $productId, int $productAttributeId): array + private function getProductFromCart(array $cartProducts, int $productId, int $productAttributeId, int $customizationId = 0): array { - $cartProduct = array_reduce($cartProducts, function ($carry, $item) use ($productId, $productAttributeId) { + $cartProduct = array_reduce($cartProducts, function ($carry, $item) use ($productId, $productAttributeId, $customizationId) { if (null !== $carry) { return $carry; } $productMatch = $item['id_product'] == $productId; $combinationMatch = $item['id_product_attribute'] == $productAttributeId; + $customizationMatch = $item['id_customization'] == $customizationId; - return $productMatch && $combinationMatch ? $item : null; + return $productMatch && $combinationMatch && $customizationMatch ? $item : null; }); // This shouldn't happen, if it does something was not done before updating the Order (removing an OrderDetail maybe) diff --git a/src/Adapter/Order/OrderDetailUpdater.php b/src/Adapter/Order/OrderDetailUpdater.php index 02d26392af2bb..02525404b9a8e 100644 --- a/src/Adapter/Order/OrderDetailUpdater.php +++ b/src/Adapter/Order/OrderDetailUpdater.php @@ -134,7 +134,8 @@ public function updateOrderDetailsForProduct( int $productId, int $combinationId, DecimalNumber $priceTaxExcluded, - DecimalNumber $priceTaxIncluded + DecimalNumber $priceTaxIncluded, + int $customizationId = 0 ): void { list($roundType, $computingPrecision, $taxAddress) = $this->prepareOrderContext($order); @@ -147,7 +148,8 @@ public function updateOrderDetailsForProduct( $priceTaxIncluded, $roundType, $computingPrecision, - $taxAddress + $taxAddress, + $customizationId ); } finally { $this->contextStateManager->restorePreviousContext(); @@ -314,9 +316,10 @@ private function applyUpdatesForProduct( DecimalNumber $priceTaxIncluded, int $roundType, int $computingPrecision, - Address $taxAddress + Address $taxAddress, + int $customizationId = 0 ): void { - $identicalOrderDetails = $this->getOrderDetailsForProduct($order, $productId, $combinationId); + $identicalOrderDetails = $this->getOrderDetailsForProduct($order, $productId, $combinationId, $customizationId); if (empty($identicalOrderDetails)) { return; } @@ -361,13 +364,15 @@ private function applyUpdatesForProduct( private function getOrderDetailsForProduct( Order $order, int $productId, - int $combinationId + int $combinationId, + int $customizationId = 0 ): array { $identicalOrderDetails = []; $orderDetails = $order->getOrderDetailList(); foreach ($orderDetails as $orderDetail) { if ((int) $orderDetail['product_id'] === $productId - && (int) $orderDetail['product_attribute_id'] === $combinationId) { + && (int) $orderDetail['product_attribute_id'] === $combinationId + && (int) $orderDetail['id_customization'] === $customizationId) { $identicalOrderDetails[] = new OrderDetail($orderDetail['id_order_detail']); } } diff --git a/src/Adapter/Product/PriceCalculator.php b/src/Adapter/Product/PriceCalculator.php index b05e4f0bb7b34..a06281a648b73 100644 --- a/src/Adapter/Product/PriceCalculator.php +++ b/src/Adapter/Product/PriceCalculator.php @@ -198,7 +198,8 @@ public function getOrderPrice( int $combinationId, bool $withTaxes, bool $useReduction, - bool $withEcoTax + bool $withEcoTax, + int $customizationId = 0 ): ?float { return Product::getPriceFromOrder( $orderId, @@ -206,7 +207,8 @@ public function getOrderPrice( $combinationId, $withTaxes, $useReduction, - $withEcoTax + $withEcoTax, + $customizationId ); } } diff --git a/src/Core/Cart/CartRow.php b/src/Core/Cart/CartRow.php index 08fb390b86f31..f5170ee13662c 100644 --- a/src/Core/Cart/CartRow.php +++ b/src/Core/Cart/CartRow.php @@ -362,7 +362,8 @@ protected function getProductPrice(CartCore $cart, $rowData) (int) $rowData['id_product_attribute'], $computationParameters['withTaxes'], true, - $this->useEcotax + $this->useEcotax, + (int) $rowData['id_customization'] ); } if (null === $productPrices[$productPrice]['value']) {