From 77b51de48136f56ea7547274e13e7273d58ca99a Mon Sep 17 00:00:00 2001 From: gcch Date: Wed, 7 Jan 2026 10:15:39 +0100 Subject: [PATCH] fix(commande) applique le bon montant pour coupon avec montant --- web/app/themes/haiku-atelier-2024/page-checkout.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/app/themes/haiku-atelier-2024/page-checkout.php b/web/app/themes/haiku-atelier-2024/page-checkout.php index 1a1f4c58..a8374252 100755 --- a/web/app/themes/haiku-atelier-2024/page-checkout.php +++ b/web/app/themes/haiku-atelier-2024/page-checkout.php @@ -101,14 +101,25 @@ if (empty($methode_livraison['nom'])) { // Sélectionne la clé API Stripe Stripe::setApiKey(Config::get('STRIPE_API_SECRET')); +// TODO: Appliquer le bon calcul pour les montants vs. percentages +function get_discount_amount(WC_Coupon $coupon) { + if ($coupon->get_discount_type() === 'amount_off') { + return $coupon->get_amount() * 100; + } else { + return $coupon->get_amount() * 100; + } +} + + // Met à jour les Codes promos $coupons_stripe = collect(Coupon::all()->data); $coupons_wc = collect(WC()->cart->get_coupons()) ->map(static fn(WC_Coupon $coupon): array => [ + 'currency' => 'EUR', 'duration' => 'forever', + 'fixed_cart' === $coupon->get_discount_type() ? 'amount_off' : 'percent_off' => get_discount_amount($coupon), 'id' => $coupon->get_code(), 'name' => $coupon->get_code(), - 'fixed_cart' === $coupon->get_discount_type() ? 'amount_off' : 'percent_off' => $coupon->get_amount(), ]) ->each(static function (array $item) use ($coupons_stripe): void { // Si le code promo n'existe, le créer