diff --git a/Classes/Controller/Cart/PaymentController.php b/Classes/Controller/Cart/PaymentController.php
index 114ddae4..c16ec2dc 100644
--- a/Classes/Controller/Cart/PaymentController.php
+++ b/Classes/Controller/Cart/PaymentController.php
@@ -21,41 +21,54 @@ class PaymentController extends ActionController
public function updateAction(int $paymentId): ResponseInterface
{
- $this->restoreSession();
+ $this->updatePaymentInSession($paymentId);
- $this->payments = $this->paymentMethodsService->getPaymentMethods($this->cart);
-
- $payment = $this->payments[$paymentId];
-
- if ($payment) {
- if ($payment->isAvailable($this->cart->getGross())) {
- $this->cart->setPayment($payment);
- } else {
- $this->addFlashMessage(
- LocalizationUtility::translate(
- 'tx_cart.controller.cart.action.set_payment.not_available',
- 'Cart'
- ),
- '',
- ContextualFeedbackSeverity::ERROR,
- true
- );
- }
+ if ($this->isAjaxRequest()) {
+ return $this->renderHtmlResponse();
}
- $this->sessionHandler->writeCart($this->settings['cart']['pid'], $this->cart);
+ return $this->redirect('show', 'Cart\Cart');
+ }
+ private function isAjaxRequest(): bool
+ {
$pageType = $GLOBALS['TYPO3_REQUEST']->getAttribute('routing')->getPageType();
- if ($pageType === self::AJAX_CART_TYPE_NUM) {
- $this->view->assign('cart', $this->cart);
- $this->parseServicesAndAssignToView();
+ return $pageType === self::AJAX_CART_TYPE_NUM;
+ }
+
+ private function renderHtmlResponse(): ResponseInterface
+ {
+ $this->view->assign('cart', $this->cart);
- $this->dispatchModifyViewEvent();
+ $this->parseServicesAndAssignToView();
+ $this->dispatchModifyViewEvent();
- return $this->htmlResponse();
+ return $this->htmlResponse();
+ }
+
+ private function updatePaymentInSession(int $paymentId): void
+ {
+ $this->restoreSession();
+
+ $payments = $this->paymentMethodsService->getPaymentMethods($this->cart);
+ $payment = $payments[$paymentId] ?? null;
+
+ if (is_null($payment) || $payment->isAvailable() === false) {
+ $this->addFlashMessage(
+ LocalizationUtility::translate(
+ 'tx_cart.controller.cart.action.set_payment.not_available',
+ 'Cart'
+ ),
+ '',
+ ContextualFeedbackSeverity::ERROR,
+ true
+ );
+
+ return;
}
- return $this->redirect('show', 'Cart\Cart');
+ $this->cart->setPayment($payment);
+ $this->sessionHandler->writeCart($this->settings['cart']['pid'], $this->cart);
}
}
diff --git a/Classes/Controller/Cart/ShippingController.php b/Classes/Controller/Cart/ShippingController.php
index 444c62a1..4690a1b7 100644
--- a/Classes/Controller/Cart/ShippingController.php
+++ b/Classes/Controller/Cart/ShippingController.php
@@ -21,41 +21,54 @@ class ShippingController extends ActionController
public function updateAction(int $shippingId): ResponseInterface
{
- $this->restoreSession();
+ $this->updateShippingInSession($shippingId);
- $this->shippings = $this->shippingMethodsService->getShippingMethods($this->cart);
-
- $shipping = $this->shippings[$shippingId];
-
- if ($shipping) {
- if ($shipping->isAvailable($this->cart->getGross())) {
- $this->cart->setShipping($shipping);
- } else {
- $this->addFlashMessage(
- LocalizationUtility::translate(
- 'tx_cart.controller.cart.action.set_shipping.not_available',
- 'Cart'
- ),
- '',
- ContextualFeedbackSeverity::ERROR,
- true
- );
- }
+ if ($this->isAjaxRequest()) {
+ return $this->renderHtmlResponse();
}
- $this->sessionHandler->writeCart($this->settings['cart']['pid'], $this->cart);
+ return $this->redirect('show', 'Cart\Cart');
+ }
+ private function isAjaxRequest(): bool
+ {
$pageType = $GLOBALS['TYPO3_REQUEST']->getAttribute('routing')->getPageType();
- if ($pageType === self::AJAX_CART_TYPE_NUM) {
- $this->view->assign('cart', $this->cart);
- $this->parseServicesAndAssignToView();
+ return $pageType === self::AJAX_CART_TYPE_NUM;
+ }
+
+ private function renderHtmlResponse(): ResponseInterface
+ {
+ $this->view->assign('cart', $this->cart);
- $this->dispatchModifyViewEvent();
+ $this->parseServicesAndAssignToView();
+ $this->dispatchModifyViewEvent();
- return $this->htmlResponse();
+ return $this->htmlResponse();
+ }
+
+ private function updateShippingInSession(int $shippingId): void
+ {
+ $this->restoreSession();
+
+ $shippings = $this->shippingMethodsService->getShippingMethods($this->cart);
+ $shipping = $shippings[$shippingId] ?? null;
+
+ if (is_null($shipping) || $shipping->isAvailable() === false) {
+ $this->addFlashMessage(
+ LocalizationUtility::translate(
+ 'tx_cart.controller.cart.action.set_shipping.not_available',
+ 'Cart'
+ ),
+ '',
+ ContextualFeedbackSeverity::ERROR,
+ true
+ );
+
+ return;
}
- return $this->redirect('show', 'Cart\Cart');
+ $this->cart->setShipping($shipping);
+ $this->sessionHandler->writeCart($this->settings['cart']['pid'], $this->cart);
}
}
diff --git a/Classes/Domain/Model/Cart/Service.php b/Classes/Domain/Model/Cart/Service.php
index 273ddadd..1ad42834 100644
--- a/Classes/Domain/Model/Cart/Service.php
+++ b/Classes/Domain/Model/Cart/Service.php
@@ -238,6 +238,16 @@ public function isFree(): bool
return false;
}
+ public function isBuyerEmailDisabled(): bool
+ {
+ return (int)($this->config['preventBuyerEmail'] ?? 0) === 1;
+ }
+
+ public function isSellerEmailDisabled(): bool
+ {
+ return (int)($this->config['preventSellerEmail'] ?? 0) === 1;
+ }
+
protected function getExtra(): Extra
{
if ($this->isFree()) {
diff --git a/Classes/EventListener/Order/Finish/Email.php b/Classes/EventListener/Order/Finish/Email.php
index e77d1077..8bb2e0f4 100644
--- a/Classes/EventListener/Order/Finish/Email.php
+++ b/Classes/EventListener/Order/Finish/Email.php
@@ -10,60 +10,51 @@
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
+
use Extcode\Cart\Domain\Model\Cart\Cart;
use Extcode\Cart\Domain\Model\Order\Item;
use Extcode\Cart\Event\Order\EventInterface;
use Extcode\Cart\Service\MailHandler;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
+use Extcode\Cart\Service\PaymentMethodsServiceInterface;
class Email
{
- protected Cart $cart;
+ public function __construct(
+ private readonly PaymentMethodsServiceInterface $paymentMethodsService,
+ private readonly MailHandler $mailHandler,
+ ) {}
public function __invoke(EventInterface $event): void
{
- $this->cart = $event->getCart();
$orderItem = $event->getOrderItem();
- $settings = $event->getSettings();
- $paymentCountry = $orderItem->getPayment()->getServiceCountry();
+ $paymentMethods = $this->paymentMethodsService->getPaymentMethods($event->getCart());
$paymentId = $orderItem->getPayment()->getServiceId();
+ $paymentMethod = $paymentMethods[$paymentId] ?? null;
- if ($paymentCountry) {
- $serviceSettings = $settings['payments']['countries'][$paymentCountry]['options'][$paymentId];
- } else {
- $serviceSettings = $settings['payments']['options'][$paymentId];
- }
-
- if ((int)($serviceSettings['preventBuyerEmail'] ?? 0) !== 1) {
- $this->sendBuyerMail($orderItem);
+ if (
+ method_exists($paymentMethod, 'isBuyerEmailDisabled') === false ||
+ (method_exists($paymentMethod, 'isBuyerEmailDisabled') && $paymentMethod->isBuyerEmailDisabled() === false)
+ ) {
+ $this->sendBuyerMail($orderItem, $event->getCart());
}
- if ((int)($serviceSettings['preventSellerEmail'] ?? 0) !== 1) {
- $this->sendSellerMail($orderItem);
+ if (
+ method_exists($paymentMethod, 'isSellerEmailDisabled') === false ||
+ (method_exists($paymentMethod, 'isSellerEmailDisabled') && $paymentMethod->isSellerEmailDisabled() === false)
+ ) {
+ $this->sendSellerMail($orderItem, $event->getCart());
}
}
- /**
- * send an email to buyer
- */
- protected function sendBuyerMail(Item $orderItem): void
+ protected function sendBuyerMail(Item $orderItem, Cart $cart): void
{
- $mailHandler = GeneralUtility::makeInstance(
- MailHandler::class
- );
- $mailHandler->setCart($this->cart);
- $mailHandler->sendBuyerMail($orderItem);
+ $this->mailHandler->setCart($cart);
+ $this->mailHandler->sendBuyerMail($orderItem);
}
- /**
- * send an email to seller
- */
- protected function sendSellerMail(Item $orderItem): void
+ protected function sendSellerMail(Item $orderItem, Cart $cart): void
{
- $mailHandler = GeneralUtility::makeInstance(
- MailHandler::class
- );
- $mailHandler->setCart($this->cart);
- $mailHandler->sendSellerMail($orderItem);
+ $this->mailHandler->setCart($cart);
+ $this->mailHandler->sendSellerMail($orderItem);
}
}
diff --git a/Classes/Service/PaymentMethodsServiceInterface.php b/Classes/Service/PaymentMethodsServiceInterface.php
index d2c1e915..64a59fea 100644
--- a/Classes/Service/PaymentMethodsServiceInterface.php
+++ b/Classes/Service/PaymentMethodsServiceInterface.php
@@ -12,8 +12,12 @@
*/
use Extcode\Cart\Domain\Model\Cart\Cart;
+use Extcode\Cart\Domain\Model\Cart\ServiceInterface;
interface PaymentMethodsServiceInterface
{
+ /**
+ * @return ServiceInterface[]
+ */
public function getPaymentMethods(Cart $cart): array;
}
diff --git a/Classes/Service/ShippingMethodsServiceInterface.php b/Classes/Service/ShippingMethodsServiceInterface.php
index ca4b9b44..882c0b09 100644
--- a/Classes/Service/ShippingMethodsServiceInterface.php
+++ b/Classes/Service/ShippingMethodsServiceInterface.php
@@ -12,8 +12,12 @@
*/
use Extcode\Cart\Domain\Model\Cart\Cart;
+use Extcode\Cart\Domain\Model\Cart\ServiceInterface;
interface ShippingMethodsServiceInterface
{
+ /**
+ * @return ServiceInterface[]
+ */
public function getShippingMethods(Cart $cart): array;
}
diff --git a/Documentation/guides.xml b/Documentation/guides.xml
index 651dd9cc..479a245c 100644
--- a/Documentation/guides.xml
+++ b/Documentation/guides.xml
@@ -11,8 +11,8 @@
interlink-shortcode="extcode/cart"
/>
diff --git a/ext_emconf.php b/ext_emconf.php
index 35f8872d..3901a785 100644
--- a/ext_emconf.php
+++ b/ext_emconf.php
@@ -4,7 +4,7 @@
'title' => 'Cart',
'description' => 'Shopping Cart(s) for TYPO3',
'category' => 'plugin',
- 'version' => '10.1.0',
+ 'version' => '10.2.0',
'state' => 'stable',
'author' => 'Daniel Gohlke',
'author_email' => 'ext@extco.de',