From b94f91476c78c8db53f69e20ac3f73c9252e67e5 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Wed, 27 Sep 2023 16:18:53 +0000 Subject: [PATCH] Provide cart ID when getting price of products --- classes/Provider/EventDataProvider.php | 4 +++- classes/Repository/ProductRepository.php | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/classes/Provider/EventDataProvider.php b/classes/Provider/EventDataProvider.php index 6941c748a..4fe38f1bf 100644 --- a/classes/Provider/EventDataProvider.php +++ b/classes/Provider/EventDataProvider.php @@ -295,6 +295,8 @@ private function getAddToCartEventData() $productName = Product::getProductName($idProduct, $idProductAttribute); + $cartId = $this->context->cookie->id_cart ?? null; + $customData = [ 'content_name' => pSQL($productName), 'content_type' => self::PRODUCT_TYPE, @@ -305,7 +307,7 @@ private function getAddToCartEventData() ), ], 'currency' => $this->getCurrency(), - 'value' => $this->productRepository->getSalePrice($idProduct, $idProductAttribute), + 'value' => $this->productRepository->getSalePrice($idProduct, $idProductAttribute, $cartId), ]; return [ diff --git a/classes/Repository/ProductRepository.php b/classes/Repository/ProductRepository.php index affc74c60..5fde86fda 100644 --- a/classes/Repository/ProductRepository.php +++ b/classes/Repository/ProductRepository.php @@ -351,11 +351,24 @@ public function getSalePriceTaxExcluded($productId, $attributeId) /** * @param int $productId * @param int $attributeId + * @param int|null $id_cart Needed to avoid a Fatal Error from PrestaShop * * @return float */ - public function getSalePrice($productId, $attributeId) + public function getSalePrice($productId, $attributeId, $id_cart = null) { - return Product::getPriceStatic($productId, true, $attributeId, 6, null, false, true); + return Product::getPriceStatic( + $productId, + true, + $attributeId, + 6, + null, + false, + true, + 1, + false, + null, + $id_cart + ); } }