|
| 1 | +diff --git a/vendor/magento/module-multicoupon/Model/CouponManagement.php b/vendor/magento/module-multicoupon/Model/CouponManagement.php |
| 2 | +index 7f37d005afaf..a290965f52a3 100644 |
| 3 | +--- a/vendor/magento/module-multicoupon/Model/CouponManagement.php |
| 4 | ++++ b/vendor/magento/module-multicoupon/Model/CouponManagement.php |
| 5 | +@@ -58,10 +58,10 @@ public function get(int $cartId): array |
| 6 | + { |
| 7 | + $quote = $this->quoteRepository->get($cartId); |
| 8 | + $coupons = $quote->getExtensionAttributes()->getCouponCodes() ?? []; |
| 9 | +- if ($quote->getCouponCode() && !in_array($quote->getCouponCode(), $coupons)) { |
| 10 | ++ if ($quote->getCouponCode() && !$this->couponsInList([$quote->getCouponCode()], $coupons)) { |
| 11 | + array_unshift($coupons, $quote->getCouponCode()); |
| 12 | + } |
| 13 | +- return $coupons; |
| 14 | ++ return array_unique($coupons); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | +@@ -74,10 +74,11 @@ public function append(int $cartId, array $couponCodes): void |
| 19 | + } |
| 20 | + $quote = $this->quoteRepository->get($cartId); |
| 21 | + $appliedCouponCodes = $quote->getExtensionAttributes()->getCouponCodes() ?? []; |
| 22 | +- if ($quote->getCouponCode() && !in_array($quote->getCouponCode(), $appliedCouponCodes)) { |
| 23 | +- array_unshift($appliedCouponCodes, $quote->getCouponCode()); |
| 24 | ++ $appliedCouponCodes = array_map('strtolower', $appliedCouponCodes); |
| 25 | ++ if ($quote->getCouponCode() && !in_array(strtolower($quote->getCouponCode()), $appliedCouponCodes)) { |
| 26 | ++ array_unshift($appliedCouponCodes, strtolower($quote->getCouponCode())); |
| 27 | + } |
| 28 | +- if (empty(array_diff($couponCodes, $appliedCouponCodes))) { |
| 29 | ++ if (!$this->couponsInList($couponCodes, $appliedCouponCodes)) { |
| 30 | + return; |
| 31 | + } |
| 32 | + $allCouponCodes = array_unique(array_merge($appliedCouponCodes, $couponCodes)); |
| 33 | +@@ -150,10 +151,13 @@ private function validateCouponCodes(CartInterface $quote, array $couponCodes): |
| 34 | + $customerId = (int)$quote->getCustomer()->getId(); |
| 35 | + } |
| 36 | + |
| 37 | +- $invalidCouponCodes = array_diff( |
| 38 | +- $couponCodes, |
| 39 | +- array_values($this->validateCouponCode->execute($couponCodes, $customerId)) |
| 40 | +- ); |
| 41 | ++ $invalidCouponCodes = []; |
| 42 | ++ $validCoupons = $this->validateCouponCode->execute($couponCodes, $customerId); |
| 43 | ++ foreach ($couponCodes as $code) { |
| 44 | ++ if (!in_array(strtolower($code), array_map('strtolower', $validCoupons))) { |
| 45 | ++ $invalidCouponCodes[] = $code; |
| 46 | ++ } |
| 47 | ++ } |
| 48 | + |
| 49 | + if (!empty($invalidCouponCodes)) { |
| 50 | + throw new InputException( |
| 51 | +@@ -197,7 +201,13 @@ private function getNotAppliedCoupons(CartInterface $quote, array $couponCodes): |
| 52 | + $quote->setCouponCode(''); |
| 53 | + } |
| 54 | + |
| 55 | +- return array_diff($couponCodes, $appliedCoupons); |
| 56 | ++ $notAppliedCoupons = []; |
| 57 | ++ foreach ($couponCodes as $couponCode) { |
| 58 | ++ if (!in_array(strtolower($couponCode), array_map('strtolower', $appliedCoupons))) { |
| 59 | ++ $notAppliedCoupons[] = $couponCode; |
| 60 | ++ } |
| 61 | ++ } |
| 62 | ++ return $notAppliedCoupons; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | +@@ -229,4 +239,21 @@ public function remove(int $cartId, array $couponCodes = []): void |
| 67 | + |
| 68 | + $this->quoteRepository->save($quote->collectTotals()); |
| 69 | + } |
| 70 | ++ |
| 71 | ++ /** |
| 72 | ++ * Check if the coupon codes are in the list |
| 73 | ++ * |
| 74 | ++ * @param array $couponCodes |
| 75 | ++ * @param array $couponList |
| 76 | ++ * @return bool |
| 77 | ++ */ |
| 78 | ++ private function couponsInList(array $couponCodes, array $couponList): bool |
| 79 | ++ { |
| 80 | ++ return !empty( |
| 81 | ++ array_diff( |
| 82 | ++ array_map('strtolower', $couponCodes), |
| 83 | ++ array_map('strtolower', $couponList) |
| 84 | ++ ) |
| 85 | ++ ); |
| 86 | ++ } |
| 87 | + } |
| 88 | +diff --git a/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderApplyCoupons.php b/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderApplyCoupons.php |
| 89 | +index dfe3eda9d4e6..dfe583bcd0a9 100644 |
| 90 | +--- a/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderApplyCoupons.php |
| 91 | ++++ b/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderApplyCoupons.php |
| 92 | +@@ -163,8 +163,8 @@ private function isValidCouponCode(Quote $quote, string $appendCouponCode): bool |
| 93 | + } |
| 94 | + |
| 95 | + $invalidCouponCodes = array_diff( |
| 96 | +- [$appendCouponCode], |
| 97 | +- array_values($this->validateCouponCode->execute([$appendCouponCode], $customerId)) |
| 98 | ++ [strtolower($appendCouponCode)], |
| 99 | ++ array_map('strtolower', array_values($this->validateCouponCode->execute([$appendCouponCode], $customerId))) |
| 100 | + ); |
| 101 | + if (!empty($invalidCouponCodes)) { |
| 102 | + return false; |
| 103 | +diff --git a/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderValidateCoupon.php b/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderValidateCoupon.php |
| 104 | +index 9aaceb9179db..9eb13fd4929c 100644 |
| 105 | +--- a/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderValidateCoupon.php |
| 106 | ++++ b/vendor/magento/module-multicoupon-ui/Plugin/AdminCreateOrderValidateCoupon.php |
| 107 | +@@ -73,7 +73,7 @@ public function aroundExecute(ValidateCoupon $subject, \Closure $proceed, CartIn |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | +- if (in_array($code, $quote->getExtensionAttributes()->getCouponCodes())) { |
| 112 | ++ if (in_array(strtolower($code), array_map('strtolower', $quote->getExtensionAttributes()->getCouponCodes()))) { |
| 113 | + $this->messageManager->addSuccessMessage(__('The coupon code has been accepted.')); |
| 114 | + return; |
| 115 | + } |
0 commit comments