Skip to content

Commit

Permalink
PISHPS-294: fixed exception, OrderTimeService now works with minutes …
Browse files Browse the repository at this point in the history
…not hours
  • Loading branch information
m-muxfeld-diw committed Aug 23, 2024
1 parent d89abb6 commit 3d3a450
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/Service/Order/OrderTimeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
}
9 changes: 5 additions & 4 deletions src/Subscriber/OrderEditSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}

Expand Down
16 changes: 14 additions & 2 deletions tests/PHPUnit/Service/Order/OrderTimeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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'),
Expand Down

0 comments on commit 3d3a450

Please sign in to comment.