From a2e939a72306f45ac2400fb0290c38f9a4361a89 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sun, 22 Nov 2026 22:02:01 +0100 Subject: [PATCH 1/2] [FEATURE] Return the stored status of a stale status change If the payment or the shipping has not the expected status anymore, the StatusChangeService returns the outcome Stale. It already reads the stored status to tell Stale from Unchanged; the StatusChangeResult now contains it in storedStatus, so extensions trying the change again do not have to read it from the database themselves. Resolves: #876 Co-Authored-By: Claude Opus 5.5 --- Classes/OrderStatus/StatusChangeResult.php | 5 ++++ Classes/OrderStatus/StatusChangeService.php | 10 +++---- ...re-876-StoredStatusOfStaleStatusChange.rst | 27 +++++++++++++++++++ Documentation/Changelog/12.6/Index.rst | 24 +++++++++++++++++ Documentation/Changelog/Index.rst | 1 + Documentation/Developer/OrderStatus/Index.rst | 12 ++++++++- .../OrderStatus/StatusChangeServiceTest.php | 4 +++ 7 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 Documentation/Changelog/12.6/Feature-876-StoredStatusOfStaleStatusChange.rst create mode 100644 Documentation/Changelog/12.6/Index.rst diff --git a/Classes/OrderStatus/StatusChangeResult.php b/Classes/OrderStatus/StatusChangeResult.php index 4b7b4b33..a7c9c8b6 100644 --- a/Classes/OrderStatus/StatusChangeResult.php +++ b/Classes/OrderStatus/StatusChangeResult.php @@ -32,6 +32,11 @@ public function __construct( * @var list errors of listeners of the AfterStatusChangeEvent, the status is changed anyway */ public array $errors = [], + /** + * The status stored in the database if the order has not the expected + * status anymore (StatusChangeOutcome::Stale), e.g. to try again with it. + */ + public ?string $storedStatus = null, ) { } diff --git a/Classes/OrderStatus/StatusChangeService.php b/Classes/OrderStatus/StatusChangeService.php index 1ba4d1c1..d46588f8 100644 --- a/Classes/OrderStatus/StatusChangeService.php +++ b/Classes/OrderStatus/StatusChangeService.php @@ -139,11 +139,11 @@ function (Connection $connection) use ($table, $serviceUid, $toStatus, $fromStat ); if ($affectedRows === 0) { - return new StatusChangeResult( - $this->getStoredStatus($table, $serviceUid) === $toStatus - ? StatusChangeOutcome::Unchanged - : StatusChangeOutcome::Stale - ); + $storedStatus = $this->getStoredStatus($table, $serviceUid); + + return $storedStatus === $toStatus + ? new StatusChangeResult(StatusChangeOutcome::Unchanged) + : new StatusChangeResult(StatusChangeOutcome::Stale, storedStatus: $storedStatus); } return new StatusChangeResult( diff --git a/Documentation/Changelog/12.6/Feature-876-StoredStatusOfStaleStatusChange.rst b/Documentation/Changelog/12.6/Feature-876-StoredStatusOfStaleStatusChange.rst new file mode 100644 index 00000000..42ce33a5 --- /dev/null +++ b/Documentation/Changelog/12.6/Feature-876-StoredStatusOfStaleStatusChange.rst @@ -0,0 +1,27 @@ +.. include:: ../../Includes.rst.txt + +====================================================== +Feature: #876 - Stored status of a stale status change +====================================================== + +See `Issue 876 `__ + +Description +====================================================== + +If the payment or the shipping of an order has not the expected status +anymore, ``\Extcode\Cart\OrderStatus\StatusChangeService::change()`` returns +the outcome ``Stale``. The ``\Extcode\Cart\OrderStatus\StatusChangeResult`` +now contains the status stored in the database in ``storedStatus``. For all +other outcomes it is ``null``. + +See :ref:`developer-order-status`. + +Impact +====== + +Extensions which try the change again with the stored status, e.g. for +payment providers whose webhook and the return of the customer arrive at the +same time, no longer read the status from the database themselves. + +.. index:: PHP-API diff --git a/Documentation/Changelog/12.6/Index.rst b/Documentation/Changelog/12.6/Index.rst new file mode 100644 index 00000000..5fef90f8 --- /dev/null +++ b/Documentation/Changelog/12.6/Index.rst @@ -0,0 +1,24 @@ +.. include:: ../../Includes.rst.txt + +12.6 Changes +============ + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +12.6.0 +------ + +Features +~~~~~~~~ + +* :doc:`#876 - Stored status of a stale status change ` + +.. toctree:: + :hidden: + :glob: + + *-* diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 33aee134..c666d734 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ ChangeLog :maxdepth: 5 :titlesonly: + 12.6/Index 12.5/Index 12.4/Index 12.3/Index diff --git a/Documentation/Developer/OrderStatus/Index.rst b/Documentation/Developer/OrderStatus/Index.rst index 27975ea6..e7c4ded6 100644 --- a/Documentation/Developer/OrderStatus/Index.rst +++ b/Documentation/Developer/OrderStatus/Index.rst @@ -201,7 +201,17 @@ It returns a ``\Extcode\Cart\OrderStatus\StatusChangeResult`` with the ``outcome``: ``Changed``, ``Unchanged`` (the order has the status already), ``Stale`` (the order has not the expected status anymore), ``UnknownStatus`` or ``Vetoed`` (a listener prevented the change, see ``vetoReason``). After a -change ``orderChange`` contains the stored change. +change ``orderChange`` contains the stored change. If the outcome is ``Stale``, +``storedStatus`` contains the status stored in the database, e.g. to try +again with it: + +.. code-block:: php + + $result = $this->statusChangeService->change($payment, PaymentStatus::PAID, $payment->getStatus()); + if ($result->outcome === StatusChangeOutcome::Stale && $result->storedStatus !== null) { + $payment->setStatus($result->storedStatus); + $result = $this->statusChangeService->change($payment, PaymentStatus::PAID, $result->storedStatus); + } .. _developer-order-status-events: diff --git a/Tests/Functional/OrderStatus/StatusChangeServiceTest.php b/Tests/Functional/OrderStatus/StatusChangeServiceTest.php index 25e5b432..e8e57d79 100644 --- a/Tests/Functional/OrderStatus/StatusChangeServiceTest.php +++ b/Tests/Functional/OrderStatus/StatusChangeServiceTest.php @@ -239,6 +239,7 @@ public function changeDoesNothingIfTheOrderHasNotTheExpectedStatusAnymore(): voi $result = $this->subject->change(self::getPayment(1), PaymentStatus::PAID, PaymentStatus::OPEN); self::assertSame(StatusChangeOutcome::Stale, $result->outcome); + self::assertSame(PaymentStatus::PENDING, $result->storedStatus); self::assertSame(PaymentStatus::PENDING, $this->getStoredStatus('tx_cart_domain_model_order_payment', 1)); self::assertSame([], $this->getStoredOrderChanges()); } @@ -254,6 +255,9 @@ public function changeChangesTheStatusOnlyOnceForTheSameExpectedStatus(): void self::assertSame(StatusChangeOutcome::Changed, $first->outcome); self::assertSame(StatusChangeOutcome::Stale, $second->outcome, 'Another status must not overwrite the changed status.'); self::assertSame(StatusChangeOutcome::Unchanged, $third->outcome, 'The same status again must not be reported as stale.'); + self::assertSame(PaymentStatus::PAID, $second->storedStatus, 'The stale result must name the stored status.'); + self::assertNull($first->storedStatus); + self::assertNull($third->storedStatus); self::assertSame(PaymentStatus::PAID, $this->getStoredStatus('tx_cart_domain_model_order_payment', 1)); self::assertCount(1, $this->getStoredOrderChanges()); } From be80a987eafe833ced6d35191cf12b12a64f723c Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sun, 22 Nov 2026 22:09:32 +0100 Subject: [PATCH 2/2] [TASK] Prepare release 12.6.0 Co-Authored-By: Claude Opus 5.5 --- Build/phpstan.neon | 2 +- Documentation/guides.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 3128b8b0..0ddbff64 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -6,7 +6,7 @@ parameters: # The version being developed, checked by version TODOs like # "TODO: 13.0.0 Remove ...". Bump it in the prepare-release PR and set the # next major as soon as the work on it starts. - referenceVersion: '12.6.0' + referenceVersion: '12.7.0' level: 'max' diff --git a/Documentation/guides.xml b/Documentation/guides.xml index f9ed5536..d7a27578 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,8 +11,8 @@ interlink-shortcode="extcode/cart" />