From 3b5ca52df597d9d86107d78cde01ffe1a51d8cc8 Mon Sep 17 00:00:00 2001 From: mbonnot Date: Wed, 16 Apr 2025 15:32:04 +0200 Subject: [PATCH] [PHP] - Add promotion to basket --- php/BasketInformations.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/php/BasketInformations.php b/php/BasketInformations.php index 0963e22..02ae38e 100644 --- a/php/BasketInformations.php +++ b/php/BasketInformations.php @@ -9,20 +9,32 @@ class BasketInformations // The product of the basket private static array $map = []; - public function addProductToBasket(string $product, int $price): void + // The fact that the basket has promo code + private static bool $codeDePromotion = false; + + public function addProductToBasket(string $product, int $price, bool $isPromoCode): void { - self::$map[$product] = $price; + if ($isPromoCode) { + self::$codeDePromotion = true; + } else { + self::$map[$product] = $price; + } } public function getBasketPrice(bool $inCents): int { $v = array_sum(self::$map); + + if (self::$codeDePromotion) { + $v -= 100; + } return $inCents ? $v * 100 : $v; } public function resetBasket(): void { $this->buyBasket(); + self::$codeDePromotion = false; } public function buyBasket(): void