From 402957c66ef9ba3c6dbcc03ac66b9818531ee093 Mon Sep 17 00:00:00 2001 From: swisschocolate Date: Thu, 27 Feb 2025 20:54:21 +0100 Subject: [PATCH] [BUGFIX] Allow to process stock after payment Configurable switch of stockEvent and PaymentEvent. Resolves: #571 --- Classes/Controller/Cart/OrderController.php | 18 ++++++++++++++---- Configuration/TypoScript/constants.typoscript | 1 + Configuration/TypoScript/setup.typoscript | 1 + .../Administrator/Configuration/Base/Index.rst | 18 ++++++++++++++++++ ext_emconf.php | 2 +- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Classes/Controller/Cart/OrderController.php b/Classes/Controller/Cart/OrderController.php index 2fc22847..70da8ccd 100644 --- a/Classes/Controller/Cart/OrderController.php +++ b/Classes/Controller/Cart/OrderController.php @@ -224,10 +224,12 @@ protected function dispatchOrderCreateEvents(Item $orderItem): bool return true; } - $stockEvent = new StockEvent($this->cart, $orderItem, $this->configurations); - $this->eventDispatcher->dispatch($stockEvent); - if ($stockEvent instanceof StoppableEventInterface && $stockEvent->isPropagationStopped()) { - return true; + if ($this->configurations['settings']['stockEventAfterPaymentEvent'] !== '1') { + $stockEvent = new StockEvent($this->cart, $orderItem, $this->configurations); + $this->eventDispatcher->dispatch($stockEvent); + if ($stockEvent instanceof StoppableEventInterface && $stockEvent->isPropagationStopped()) { + return true; + } } $paymentEvent = new PaymentEvent($this->cart, $orderItem, $this->configurations); @@ -236,6 +238,14 @@ protected function dispatchOrderCreateEvents(Item $orderItem): bool return true; } + if(!isset($stockEvent)) { + $stockEvent = new StockEvent($this->cart, $orderItem, $this->configurations); + $this->eventDispatcher->dispatch($stockEvent); + if ($stockEvent instanceof StoppableEventInterface && $stockEvent->isPropagationStopped()) { + return true; + } + } + $finishEvent = new FinishEvent($this->cart, $orderItem, $this->configurations); $this->eventDispatcher->dispatch($finishEvent); if ($finishEvent instanceof StoppableEventInterface && $finishEvent->isPropagationStopped()) { diff --git a/Configuration/TypoScript/constants.typoscript b/Configuration/TypoScript/constants.typoscript index 9841c4e0..2f5aa2a1 100755 --- a/Configuration/TypoScript/constants.typoscript +++ b/Configuration/TypoScript/constants.typoscript @@ -36,6 +36,7 @@ plugin.tx_cart { settings { addToCartByAjax = 2278001 + stockEventAfterPaymentEvent = format.currency { currencySign = € diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index addd23b0..89b8ec17 100755 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -54,6 +54,7 @@ plugin.tx_cart { autoGenerateNumbers = order settings { + stockEventAfterPaymentEvent = {$plugin.tx_cart.settings.stockEventAfterPaymentEvent} cart { pid = {$plugin.tx_cart.settings.cart.pid} isNetCart = {$plugin.tx_cart.settings.cart.isNetCart} diff --git a/Documentation/Administrator/Configuration/Base/Index.rst b/Documentation/Administrator/Configuration/Base/Index.rst index a119c88f..52ce18ed 100644 --- a/Documentation/Administrator/Configuration/Base/Index.rst +++ b/Documentation/Administrator/Configuration/Base/Index.rst @@ -22,6 +22,7 @@ Base } itemsPerPage = + stockEventAfterPaymentEvent = } } @@ -67,3 +68,20 @@ plugin.tx_cart.settings Defines how many records should be displayed per page in the list action. Also valid: `module.tx_cart.settings.itemsPerPage`. + +.. confval:: stockEventAfterPaymentEvent + + :Required: false + :Type: boolean + :Default: false + + Switch order of PaymentEvent and StockEvent. + + If set to `1`, stock handling is processed after payment. This is useful for + external provider (Paypal, Stripe). In this case, the payment provider extension + is responsable to handle StockEvent and FinishingEvent after successful payment. + This ensures that stock isn't changed on failed or aborted payment. + + Note: Switching the events can lead to understocking if two customers order + the last product at the same time and the first customer is still in the + payment process.. diff --git a/ext_emconf.php b/ext_emconf.php index b9e29680..35f8872d 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.0.0', + 'version' => '10.1.0', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',