Skip to content

Commit 0ab3e54

Browse files
authored
Merge pull request #663 from extcode/662-deliver-a-different-flash-message-for-added-but-not-useabe-coupons_v10
[TASK] Deliver a different flash message for added but not useabe coupons
2 parents 4ff6795 + 9c54143 commit 0ab3e54

4 files changed

Lines changed: 63 additions & 35 deletions

File tree

Classes/Controller/Cart/CouponController.php

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,7 @@ public function addAction(): ResponseInterface
6161

6262
$couponWasAdded = $this->cart->addCoupon($newCartCoupon);
6363

64-
if ($couponWasAdded == 1) {
65-
$this->addFlashMessage(
66-
LocalizationUtility::translate(
67-
'tx_cart.ok.coupon.added',
68-
'Cart'
69-
),
70-
'',
71-
ContextualFeedbackSeverity::OK,
72-
true
73-
);
74-
}
75-
if ($couponWasAdded == -1) {
76-
$this->addFlashMessage(
77-
LocalizationUtility::translate(
78-
'tx_cart.error.coupon.already_added',
79-
'Cart'
80-
),
81-
'',
82-
ContextualFeedbackSeverity::WARNING,
83-
true
84-
);
85-
}
86-
if ($couponWasAdded == -2) {
87-
$this->addFlashMessage(
88-
LocalizationUtility::translate(
89-
'tx_cart.error.coupon.not_combinable',
90-
'Cart'
91-
),
92-
'',
93-
ContextualFeedbackSeverity::WARNING,
94-
true
95-
);
96-
}
64+
$this->addFlashMessageForAddedCoupon($couponWasAdded, $coupon);
9765
} else {
9866
$this->addFlashMessage(
9967
LocalizationUtility::translate(
@@ -158,4 +126,61 @@ public function removeAction(): ResponseInterface
158126

159127
return $this->redirect('show', 'Cart\Cart');
160128
}
129+
130+
private function addFlashMessageForAddedCoupon(int $couponWasAdded, Coupon $coupon): void
131+
{
132+
if ($couponWasAdded === 1) {
133+
$messageBody = LocalizationUtility::translate(
134+
'tx_cart.ok.coupon.added',
135+
'Cart'
136+
);
137+
138+
foreach ($this->cart->getCoupons() as $cartCoupon) {
139+
if ($cartCoupon->getCode() !== $coupon->getCode()) {
140+
continue;
141+
}
142+
143+
if ($cartCoupon->isUseable()) {
144+
$this->addFlashMessage(
145+
$messageBody
146+
);
147+
} else {
148+
$this->addFlashMessage(
149+
LocalizationUtility::translate(
150+
'tx_cart.error.coupon.added_but_not_usable',
151+
'Cart'
152+
),
153+
'',
154+
ContextualFeedbackSeverity::WARNING,
155+
);
156+
}
157+
}
158+
159+
return;
160+
}
161+
162+
if ($couponWasAdded === -1) {
163+
$this->addFlashMessage(
164+
LocalizationUtility::translate(
165+
'tx_cart.error.coupon.already_added',
166+
'Cart'
167+
),
168+
'',
169+
ContextualFeedbackSeverity::WARNING,
170+
);
171+
172+
return;
173+
}
174+
175+
if ($couponWasAdded === -2) {
176+
$this->addFlashMessage(
177+
LocalizationUtility::translate(
178+
'tx_cart.error.coupon.not_combinable',
179+
'Cart'
180+
),
181+
'',
182+
ContextualFeedbackSeverity::WARNING,
183+
);
184+
}
185+
}
161186
}

Documentation/guides.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
interlink-shortcode="extcode/cart"
1212
/>
1313
<project title="Cart"
14-
release="10.2.4"
14+
release="10.2.5"
1515
version="10.2"
1616
copyright="2018 - 2024"
1717
/>

Resources/Private/Language/locallang.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@
491491
<trans-unit id="tx_cart.ok.coupon.added">
492492
<source>Coupon was added.</source>
493493
</trans-unit>
494+
<trans-unit id="tx_cart.error.coupon.added_but_not_usable">
495+
<source>Coupon was added but is not usable.</source>
496+
</trans-unit>
494497
<trans-unit id="tx_cart.error.coupon.not_accepted">
495498
<source>Coupon code was not accepted.</source>
496499
</trans-unit>

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'title' => 'Cart',
55
'description' => 'Shopping Cart(s) for TYPO3',
66
'category' => 'plugin',
7-
'version' => '10.2.4',
7+
'version' => '10.2.5',
88
'state' => 'stable',
99
'author' => 'Daniel Gohlke',
1010
'author_email' => 'ext@extco.de',

0 commit comments

Comments
 (0)