fix issue with coupons with same code

This commit is contained in:
Steffen Mahler 2020-05-12 16:43:56 +02:00
parent 3f160c8fe6
commit 15320934b4
1 changed files with 15 additions and 10 deletions

View File

@ -124,7 +124,9 @@ class CartRule
$this->processFreeShippingDiscount($cart);
$this->validateCouponCode();
if (! $this->checkCouponCode()) {
cart()->removeCouponCode();
}
}
/**
@ -516,23 +518,26 @@ class CartRule
}
/**
* Check if coupon code is valid or not, if not remove from cart
* Check if coupon code is applied or not
*
* @return void
* @return bool
*/
public function validateCouponCode()
public function checkCouponCode(): bool
{
$cart = Cart::getCart();
$cart = cart()->getCart();
if (! $cart->coupon_code) {
return;
return true;
}
$coupon = $this->cartRuleCouponRepository->findOneByField('code', $cart->coupon_code);
if (! $coupon || ! in_array($coupon->cart_rule_id, explode(',', $cart->applied_cart_rule_ids))) {
Cart::removeCouponCode();
$coupons = $this->cartRuleCouponRepository->where(['code' => $cart->coupon_code])->get();
foreach ($coupons as $coupon) {
if (in_array($coupon->cart_rule_id, explode(',', $cart->applied_cart_rule_ids))) {
return true;
}
}
return false;
}
/**