Skip to content

Commit

Permalink
Merge pull request #469 from Quetzacoalt91/add-cart-id-to-get-price
Browse files Browse the repository at this point in the history
Provide cart ID when getting price of products
  • Loading branch information
Quetzacoalt91 authored Sep 28, 2023
2 parents 2505b7f + b94f914 commit fb8031c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion classes/Provider/EventDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,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,
Expand All @@ -306,7 +308,7 @@ private function getAddToCartEventData()
),
],
'currency' => $this->getCurrency(),
'value' => $this->productRepository->getSalePrice($idProduct, $idProductAttribute),
'value' => $this->productRepository->getSalePrice($idProduct, $idProductAttribute, $cartId),
];

return [
Expand Down
17 changes: 15 additions & 2 deletions classes/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

0 comments on commit fb8031c

Please sign in to comment.