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
65 changes: 39 additions & 26 deletions Classes/Controller/Cart/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
65 changes: 39 additions & 26 deletions Classes/Controller/Cart/ShippingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 10 additions & 0 deletions Classes/Domain/Model/Cart/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
57 changes: 24 additions & 33 deletions Classes/EventListener/Order/Finish/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions Classes/Service/PaymentMethodsServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions Classes/Service/ShippingMethodsServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions Documentation/guides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
interlink-shortcode="extcode/cart"
/>
<project title="Cart"
release="10.1.0"
version="10.1"
release="10.2.0"
version="10.2"
copyright="2018 - 2024"
/>
<inventory id="t3tsref" url="https://docs.typo3.org/typo3cms/TyposcriptReference/"/>
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' => '10.1.0',
'version' => '10.2.0',
'state' => 'stable',
'author' => 'Daniel Gohlke',
'author_email' => 'ext@extco.de',
Expand Down