Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 58 additions & 33 deletions Classes/Controller/Cart/CouponController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
);
}
}
}
3 changes: 3 additions & 0 deletions Classes/Domain/Model/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion Documentation/guides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
interlink-shortcode="extcode/cart"
/>
<project title="Cart"
release="11.4.4"
release="11.4.5"
version="11.4"
copyright="2018 - 2025"
/>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@
<trans-unit id="tx_cart.ok.coupon.added">
<source>Coupon was added.</source>
</trans-unit>
<trans-unit id="tx_cart.error.coupon.added_but_not_usable">
<source>Coupon was added but is not usable.</source>
</trans-unit>
<trans-unit id="tx_cart.error.coupon.not_accepted">
<source>Coupon code was not accepted.</source>
</trans-unit>
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down