diff --git a/src/Service/Order/OrderTimeService.php b/src/Service/Order/OrderTimeService.php index 0c9666ece..f1bc1c11e 100644 --- a/src/Service/Order/OrderTimeService.php +++ b/src/Service/Order/OrderTimeService.php @@ -23,11 +23,11 @@ public function __construct(?DateTime $now = null) * Checks if the age of the last transaction of the order is greater than the specified number of hours. * * @param OrderEntity $order The order entity to check. - * @param int $hours The number of hours to compare against. + * @param int $minutes The number of minutes to compare against. * * @return bool Returns true if the order is older than the specified number of hours, false otherwise. */ - public function isOrderAgeGreaterThan(OrderEntity $order, int $hours): bool + public function isOrderAgeGreaterThan(OrderEntity $order, int $minutes): bool { $transactions = $order->getTransactions(); @@ -50,7 +50,8 @@ public function isOrderAgeGreaterThan(OrderEntity $order, int $hours): bool $interval = $this->now->diff($transitionDate); $diffInHours = $interval->h + ($interval->days * 24); + $diffInMinutes = $interval->i + ($diffInHours * 60); - return $diffInHours > $hours; + return $diffInMinutes > $minutes; } } diff --git a/src/Subscriber/OrderEditSubscriber.php b/src/Subscriber/OrderEditSubscriber.php index 931fbe20a..29e22039a 100644 --- a/src/Subscriber/OrderEditSubscriber.php +++ b/src/Subscriber/OrderEditSubscriber.php @@ -64,7 +64,9 @@ public function accountOrderDetailPageLoaded(AccountOrderPageLoadedEvent $event) continue; } - $lastTransaction = $transactions->filter(Closure::fromCallable([$this, 'sortTransactionsByDate']))->last(); + $transactions->sort(Closure::fromCallable([$this, 'sortTransactionsByDate'])); + + $lastTransaction = $transactions->last(); $lastStatus = $lastTransaction->getStateMachineState()->getTechnicalName(); @@ -75,13 +77,12 @@ public function accountOrderDetailPageLoaded(AccountOrderPageLoadedEvent $event) $settings = $this->settingsService->getSettings(); $finalizeTransactionTimeInMinutes = $settings->getPaymentFinalizeTransactionTime(); - $finalizeTransactionTimeInHours = (int) ceil($finalizeTransactionTimeInMinutes / 60); if ($this->orderUsesSepaPayment($order)) { - $finalizeTransactionTimeInHours = (int) ceil($settings->getPaymentMethodBankTransferDueDateDays() / 24); + $finalizeTransactionTimeInMinutes = (int) ceil($settings->getPaymentMethodBankTransferDueDateDays() / 24 / 60); } - if ($this->orderTimeService->isOrderAgeGreaterThan($order, $finalizeTransactionTimeInHours) === false) { + if ($this->orderTimeService->isOrderAgeGreaterThan($order, $finalizeTransactionTimeInMinutes) === false) { continue; } diff --git a/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php b/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php index 1221088bd..e09c50c13 100644 --- a/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php +++ b/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php @@ -20,11 +20,11 @@ class OrderTimeServiceTest extends TestCase * * @dataProvider dateComparisonLogicProvider */ - public function testDateComparisonLogic(\DateTime $now, \DateTime $orderDate, bool $expected): void + public function testDateComparisonLogic(\DateTime $now, \DateTime $orderDate, bool $expected, int $compareValueInMinutes = 60): void { $order = $this->orderMockWithLastTransactionTimestamp($orderDate); - $result = (new OrderTimeService($now))->isOrderAgeGreaterThan($order, 1); + $result = (new OrderTimeService($now))->isOrderAgeGreaterThan($order, $compareValueInMinutes); $this->assertSame($expected, $result); } @@ -50,6 +50,18 @@ public function dateComparisonLogicProvider() new \DateTime('2021-01-01 10:00:00'), true ], + 'order is not older than 10 minutes' => [ + new \DateTime('2021-01-01 11:00:00'), + new \DateTime('2021-01-01 11:11:00'), + true, + 10 + ], + 'order is not older than 1 minute' => [ + new \DateTime('2021-01-01 12:00:00'), + new \DateTime('2021-01-01 12:02:00'), + true, + 1 + ], 'order is not older than 1 hour' => [ new \DateTime('2021-01-01 12:00:00'), new \DateTime('2021-01-01 11:00:00'),