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
2 changes: 1 addition & 1 deletion Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 5 additions & 0 deletions Classes/OrderStatus/StatusChangeResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function __construct(
* @var list<string> 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,
) {
}

Expand Down
10 changes: 5 additions & 5 deletions Classes/OrderStatus/StatusChangeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. include:: ../../Includes.rst.txt

======================================================
Feature: #876 - Stored status of a stale status change
======================================================

See `Issue 876 <https://github.com/extcode/cart/issues/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
24 changes: 24 additions & 0 deletions Documentation/Changelog/12.6/Index.rst
Original file line number Diff line number Diff line change
@@ -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 <Feature-876-StoredStatusOfStaleStatusChange>`

.. toctree::
:hidden:
:glob:

*-*
1 change: 1 addition & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ChangeLog
:maxdepth: 5
:titlesonly:

12.6/Index
12.5/Index
12.4/Index
12.3/Index
Expand Down
12 changes: 11 additions & 1 deletion Documentation/Developer/OrderStatus/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
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="12.5.0"
version="12.5"
release="12.6.0"
version="12.6"
copyright="2018 - 2026"
/>
<inventory id="t3tsref" url="https://docs.typo3.org/typo3cms/TyposcriptReference/"/>
Expand Down
4 changes: 4 additions & 0 deletions Tests/Functional/OrderStatus/StatusChangeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down
Loading