fix(commande) applique le bon montant pour coupon avec montant
This commit is contained in:
parent
b8e697db99
commit
77b51de481
1 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue