diff --git a/Classes/Controller/Cart/CouponController.php b/Classes/Controller/Cart/CouponController.php
index c5081f7f..35aa81af 100644
--- a/Classes/Controller/Cart/CouponController.php
+++ b/Classes/Controller/Cart/CouponController.php
@@ -61,39 +61,7 @@ public function addAction(): ResponseInterface
$couponWasAdded = $this->cart->addCoupon($newCartCoupon);
- if ($couponWasAdded == 1) {
- $this->addFlashMessage(
- LocalizationUtility::translate(
- 'tx_cart.ok.coupon.added',
- 'Cart'
- ),
- '',
- ContextualFeedbackSeverity::OK,
- true
- );
- }
- if ($couponWasAdded == -1) {
- $this->addFlashMessage(
- LocalizationUtility::translate(
- 'tx_cart.error.coupon.already_added',
- 'Cart'
- ),
- '',
- ContextualFeedbackSeverity::WARNING,
- true
- );
- }
- if ($couponWasAdded == -2) {
- $this->addFlashMessage(
- LocalizationUtility::translate(
- 'tx_cart.error.coupon.not_combinable',
- 'Cart'
- ),
- '',
- ContextualFeedbackSeverity::WARNING,
- true
- );
- }
+ $this->addFlashMessageForAddedCoupon($couponWasAdded, $coupon);
} else {
$this->addFlashMessage(
LocalizationUtility::translate(
@@ -158,4 +126,61 @@ public function removeAction(): ResponseInterface
return $this->redirect('show', 'Cart\Cart');
}
+
+ private function addFlashMessageForAddedCoupon(int $couponWasAdded, Coupon $coupon): void
+ {
+ if ($couponWasAdded === 1) {
+ $messageBody = LocalizationUtility::translate(
+ 'tx_cart.ok.coupon.added',
+ 'Cart'
+ );
+
+ foreach ($this->cart->getCoupons() as $cartCoupon) {
+ if ($cartCoupon->getCode() !== $coupon->getCode()) {
+ continue;
+ }
+
+ if ($cartCoupon->isUseable()) {
+ $this->addFlashMessage(
+ $messageBody
+ );
+ } else {
+ $this->addFlashMessage(
+ LocalizationUtility::translate(
+ 'tx_cart.error.coupon.added_but_not_usable',
+ 'Cart'
+ ),
+ '',
+ ContextualFeedbackSeverity::WARNING,
+ );
+ }
+ }
+
+ return;
+ }
+
+ if ($couponWasAdded === -1) {
+ $this->addFlashMessage(
+ LocalizationUtility::translate(
+ 'tx_cart.error.coupon.already_added',
+ 'Cart'
+ ),
+ '',
+ ContextualFeedbackSeverity::WARNING,
+ );
+
+ return;
+ }
+
+ if ($couponWasAdded === -2) {
+ $this->addFlashMessage(
+ LocalizationUtility::translate(
+ 'tx_cart.error.coupon.not_combinable',
+ 'Cart'
+ ),
+ '',
+ ContextualFeedbackSeverity::WARNING,
+ );
+ }
+ }
}
diff --git a/Classes/Domain/Model/Cart/Cart.php b/Classes/Domain/Model/Cart/Cart.php
index baeb300c..e635b3aa 100644
--- a/Classes/Domain/Model/Cart/Cart.php
+++ b/Classes/Domain/Model/Cart/Cart.php
@@ -562,6 +562,9 @@ protected function areCouponsCombinable(): bool
return true;
}
+ /**
+ * @todo replace return type with enum
+ */
public function addCoupon(CartCouponInterface $coupon): int
{
if (!empty($this->coupons) && array_key_exists($coupon->getCode(), $this->coupons)) {
diff --git a/Documentation/guides.xml b/Documentation/guides.xml
index 3fc20416..a3484368 100644
--- a/Documentation/guides.xml
+++ b/Documentation/guides.xml
@@ -11,7 +11,7 @@
interlink-shortcode="extcode/cart"
/>
diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf
index 19a54632..539c03d3 100644
--- a/Resources/Private/Language/locallang.xlf
+++ b/Resources/Private/Language/locallang.xlf
@@ -491,6 +491,9 @@
Coupon was added.
+
+ Coupon was added but is not usable.
+
Coupon code was not accepted.
diff --git a/ext_emconf.php b/ext_emconf.php
index 042ae979..34440c72 100644
--- a/ext_emconf.php
+++ b/ext_emconf.php
@@ -4,7 +4,7 @@
'title' => 'Cart',
'description' => 'Shopping Cart(s) for TYPO3',
'category' => 'plugin',
- 'version' => '11.4.4',
+ 'version' => '11.4.5',
'state' => 'stable',
'author' => 'Daniel Gohlke',
'author_email' => 'ext@extco.de',