diff --git a/Classes/Domain/Model/Order/Payment.php b/Classes/Domain/Model/Order/Payment.php index eabff708..a21d5cd3 100644 --- a/Classes/Domain/Model/Order/Payment.php +++ b/Classes/Domain/Model/Order/Payment.php @@ -38,6 +38,26 @@ public function toArray(): array return $payment; } + public function isOpen(): bool + { + return $this->getStatus() === 'open'; + } + + public function isPending(): bool + { + return $this->getStatus() === 'pending'; + } + + public function isPaid(): bool + { + return $this->getStatus() === 'paid'; + } + + public function isCanceled(): bool + { + return $this->getStatus() === 'canceled'; + } + public function getProvider(): ?string { return $this->provider; diff --git a/Classes/Domain/Model/Order/Shipping.php b/Classes/Domain/Model/Order/Shipping.php index 39eadc9a..792fbf22 100644 --- a/Classes/Domain/Model/Order/Shipping.php +++ b/Classes/Domain/Model/Order/Shipping.php @@ -11,4 +11,25 @@ * LICENSE file that was distributed with this source code. */ -class Shipping extends AbstractService {} +class Shipping extends AbstractService +{ + public function isOpen(): bool + { + return $this->getStatus() === 'open'; + } + + public function isOnHold(): bool + { + return $this->getStatus() === 'on_hold'; + } + + public function isInProcess(): bool + { + return $this->getStatus() === 'in_process'; + } + + public function isShipped(): bool + { + return $this->getStatus() === 'shipped'; + } +} diff --git a/Documentation/Changelog/11.10/Feature-866-OrderStatusMethods.rst b/Documentation/Changelog/11.10/Feature-866-OrderStatusMethods.rst new file mode 100644 index 00000000..6d540d6d --- /dev/null +++ b/Documentation/Changelog/11.10/Feature-866-OrderStatusMethods.rst @@ -0,0 +1,32 @@ +.. include:: ../../Includes.rst.txt + +========================================================================== +Feature: #866 - Status methods of the payment and the shipping of an order +========================================================================== + +See `Issue 866 `__ + +Description +=========== + +The payment (``\Extcode\Cart\Domain\Model\Order\Payment``) and the shipping +(``\Extcode\Cart\Domain\Model\Order\Shipping``) of an order have new methods +for the status of EXT:cart: + +========= ================================================================== +Service Methods +========= ================================================================== +payment ``isOpen()``, ``isPending()``, ``isPaid()``, ``isCanceled()`` +shipping ``isOpen()``, ``isOnHold()``, ``isInProcess()``, ``isShipped()`` +========= ================================================================== + +Further status added by other extensions have no method, compare them with +``getStatus()``. + +Impact +====== + +Extensions, e.g. for payment providers, use the methods instead of comparing +the status with strings themselves. + +.. index:: PHP-API diff --git a/Documentation/Changelog/11.10/Index.rst b/Documentation/Changelog/11.10/Index.rst new file mode 100644 index 00000000..6dd3d0a3 --- /dev/null +++ b/Documentation/Changelog/11.10/Index.rst @@ -0,0 +1,24 @@ +.. include:: ../../Includes.rst.txt + +11.10 Changes +============= + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +11.10.0 +------- + +Features +~~~~~~~~ + +* :doc:`#866 - Status methods of the payment and the shipping of an order ` + +.. toctree:: + :hidden: + :glob: + + *-* diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index d6f85265..a2446f17 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ ChangeLog :maxdepth: 5 :titlesonly: + 11.10/Index 11.9/Index 11.8/Index 11.7/Index diff --git a/Tests/Unit/Domain/Model/Order/PaymentTest.php b/Tests/Unit/Domain/Model/Order/PaymentTest.php index f8079898..cb09ebe5 100644 --- a/Tests/Unit/Domain/Model/Order/PaymentTest.php +++ b/Tests/Unit/Domain/Model/Order/PaymentTest.php @@ -12,6 +12,7 @@ use Extcode\Cart\Domain\Model\Order\Payment; use Extcode\Cart\Domain\Model\Order\Transaction; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Extbase\Persistence\ObjectStorage; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -28,6 +29,35 @@ public function setUp(): void parent::setUp(); } + #[DataProvider('statusDataProvider')] + #[Test] + public function statusMethodsReturnWhetherThePaymentHasTheStatus( + string $status, + bool $isOpen, + bool $isPending, + bool $isPaid, + bool $isCanceled, + ): void { + $this->payment->setStatus($status); + + self::assertSame($isOpen, $this->payment->isOpen()); + self::assertSame($isPending, $this->payment->isPending()); + self::assertSame($isPaid, $this->payment->isPaid()); + self::assertSame($isCanceled, $this->payment->isCanceled()); + } + + /** + * @return iterable + */ + public static function statusDataProvider(): iterable + { + yield 'open' => ['open', true, false, false, false]; + yield 'pending' => ['pending', false, true, false, false]; + yield 'paid' => ['paid', false, false, true, false]; + yield 'canceled' => ['canceled', false, false, false, true]; + yield 'status of another extension' => ['refunded', false, false, false, false]; + } + #[Test] public function toArrayReturnsArray(): void { diff --git a/Tests/Unit/Domain/Model/Order/ShippingTest.php b/Tests/Unit/Domain/Model/Order/ShippingTest.php index 0deb9db5..b348d70e 100644 --- a/Tests/Unit/Domain/Model/Order/ShippingTest.php +++ b/Tests/Unit/Domain/Model/Order/ShippingTest.php @@ -11,6 +11,7 @@ use Extcode\Cart\Domain\Model\Order\Shipping; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -26,6 +27,35 @@ public function setUp(): void parent::setUp(); } + #[DataProvider('statusDataProvider')] + #[Test] + public function statusMethodsReturnWhetherTheShippingHasTheStatus( + string $status, + bool $isOpen, + bool $isOnHold, + bool $isInProcess, + bool $isShipped, + ): void { + $this->shipping->setStatus($status); + + self::assertSame($isOpen, $this->shipping->isOpen()); + self::assertSame($isOnHold, $this->shipping->isOnHold()); + self::assertSame($isInProcess, $this->shipping->isInProcess()); + self::assertSame($isShipped, $this->shipping->isShipped()); + } + + /** + * @return iterable + */ + public static function statusDataProvider(): iterable + { + yield 'open' => ['open', true, false, false, false]; + yield 'on hold' => ['on_hold', false, true, false, false]; + yield 'in process' => ['in_process', false, false, true, false]; + yield 'shipped' => ['shipped', false, false, false, true]; + yield 'status of another extension' => ['delivered', false, false, false, false]; + } + #[Test] public function getNameInitiallyReturnsEmptyString(): void {