Skip to content

Commit 5c92841

Browse files
Merge remote-tracking branch '38264/bugfix/36947_orders_graphql_date_timezone' into commprs_dec
2 parents 81c0007 + 6f63a4e commit 5c92841

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

app/code/Magento/SalesGraphQl/Model/Formatter/Order.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\SalesGraphQl\Model\Formatter;
99

10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Stdlib\DateTime;
12+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1013
use Magento\Framework\Exception\LocalizedException;
1114
use Magento\Sales\Api\Data\OrderInterface;
1215
use Magento\SalesGraphQl\Model\Order\OrderAddress;
@@ -20,11 +23,14 @@ class Order
2023
/**
2124
* @param OrderAddress $orderAddress
2225
* @param OrderPayments $orderPayments
26+
* @param TimezoneInterface|null $timezone
2327
*/
2428
public function __construct(
2529
private readonly OrderAddress $orderAddress,
26-
private readonly OrderPayments $orderPayments
30+
private readonly OrderPayments $orderPayments,
31+
private ?TimezoneInterface $timezone = null
2732
) {
33+
$this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
2834
}
2935

3036
/**
@@ -42,7 +48,8 @@ public function format(OrderInterface $orderModel): array
4248
'id' => base64_encode((string)$orderModel->getEntityId()),
4349
'increment_id' => $orderModel->getIncrementId(),
4450
'number' => $orderModel->getIncrementId(),
45-
'order_date' => $orderModel->getCreatedAt(),
51+
'order_date' => $this->timezone->date($orderModel->getCreatedAt())
52+
->format(DateTime::DATETIME_PHP_FORMAT),
4653
'order_number' => $orderModel->getIncrementId(),
4754
'status' => $orderModel->getStatusLabel(),
4855
'email' => $orderModel->getCustomerEmail(),

app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoComments.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\SalesGraphQl\Model\Resolver\CreditMemo;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Framework\Stdlib\DateTime;
16+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1417
use Magento\Sales\Api\Data\CreditmemoInterface;
1518

1619
/**
1720
* Resolve credit memo comments
1821
*/
1922
class CreditMemoComments implements ResolverInterface
2023
{
24+
/**
25+
* @param TimezoneInterface|null $timezone
26+
*/
27+
public function __construct(
28+
private ?TimezoneInterface $timezone = null
29+
) {
30+
$this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
31+
}
32+
2133
/**
2234
* @inheritDoc
2335
*/
@@ -40,7 +52,8 @@ public function resolve(
4052
if ($comment->getIsVisibleOnFront()) {
4153
$comments[] = [
4254
'message' => $comment->getComment(),
43-
'timestamp' => $comment->getCreatedAt()
55+
'timestamp' => $this->timezone->date($comment->getCreatedAt())
56+
->format(DateTime::DATETIME_PHP_FORMAT)
4457
];
4558
}
4659
}

app/code/Magento/SalesGraphQl/Model/Resolver/Invoices.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\SalesGraphQl\Model\Resolver;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Framework\Stdlib\DateTime;
16+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1417
use Magento\Sales\Api\Data\OrderInterface;
1518
use Magento\Sales\Api\Data\InvoiceInterface;
1619

@@ -19,6 +22,15 @@
1922
*/
2023
class Invoices implements ResolverInterface
2124
{
25+
/**
26+
* @param TimezoneInterface|null $timezone
27+
*/
28+
public function __construct(
29+
private ?TimezoneInterface $timezone = null
30+
) {
31+
$this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
32+
}
33+
2234
/**
2335
* @inheritDoc
2436
*/
@@ -61,7 +73,8 @@ private function getInvoiceComments(InvoiceInterface $invoice): array
6173
foreach ($invoice->getComments() as $comment) {
6274
if ($comment->getIsVisibleOnFront()) {
6375
$comments[] = [
64-
'timestamp' => $comment->getCreatedAt(),
76+
'timestamp' => $this->timezone->date($comment->getCreatedAt())
77+
->format(DateTime::DATETIME_PHP_FORMAT),
6578
'message' => $comment->getComment()
6679
];
6780
}

app/code/Magento/SalesGraphQl/Model/Resolver/Shipments.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\SalesGraphQl\Model\Resolver;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Framework\Stdlib\DateTime;
16+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1417
use Magento\Sales\Api\Data\ShipmentInterface;
1518
use Magento\Sales\Model\Order;
1619

@@ -19,6 +22,15 @@
1922
*/
2023
class Shipments implements ResolverInterface
2124
{
25+
/**
26+
* @param TimezoneInterface|null $timezone
27+
*/
28+
public function __construct(
29+
private ?TimezoneInterface $timezone = null
30+
) {
31+
$this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
32+
}
33+
2234
/**
2335
* @inheritDoc
2436
*/
@@ -62,7 +74,8 @@ private function getShipmentComments(ShipmentInterface $shipment): array
6274
foreach ($shipment->getComments() as $comment) {
6375
if ($comment->getIsVisibleOnFront()) {
6476
$comments[] = [
65-
'timestamp' => $comment->getCreatedAt(),
77+
'timestamp' => $this->timezone->date($comment->getCreatedAt())
78+
->format(DateTime::DATETIME_PHP_FORMAT),
6679
'message' => $comment->getComment()
6780
];
6881
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/RetrieveOrdersByOrderNumberTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -11,6 +11,8 @@
1111
use Magento\Framework\Api\SearchCriteriaBuilder;
1212
use Magento\Framework\Exception\AuthenticationException;
1313
use Magento\Framework\Registry;
14+
use Magento\Framework\Stdlib\DateTime;
15+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1416
use Magento\GraphQl\GetCustomerAuthenticationHeader;
1517
use Magento\Sales\Api\OrderRepositoryInterface;
1618
use Magento\Sales\Model\ResourceModel\Order\Collection;
@@ -33,6 +35,8 @@
3335

3436
/**
3537
* Class RetrieveOrdersTest
38+
*
39+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3640
*/
3741
class RetrieveOrdersByOrderNumberTest extends GraphQlAbstract
3842
{
@@ -48,6 +52,9 @@ class RetrieveOrdersByOrderNumberTest extends GraphQlAbstract
4852
/** @var ProductRepositoryInterface */
4953
private $productRepository;
5054

55+
/** @var TimezoneInterface */
56+
private $timezone;
57+
5158
/**
5259
* @var DataFixtureStorage
5360
*/
@@ -61,6 +68,7 @@ protected function setUp():void
6168
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
6269
$this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
6370
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
71+
$this->timezone = $objectManager->get(TimezoneInterface::class);
6472
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
6573
}
6674

@@ -500,7 +508,8 @@ public function testGetCustomerDescendingSortedOrders()
500508
$orderNumberCreatedAtExpected = [];
501509
for ($i = 1; $i <= 3; $i++) {
502510
$orderNumber = $this->fixtures->get('or' . $i)->getIncrementId();
503-
$orderCreatedAt = $this->fixtures->get('or' . $i)->getCreatedAt();
511+
$orderCreatedAt = $this->timezone->date($this->fixtures->get('or' . $i)->getCreatedAt())
512+
->format(DateTime::DATETIME_PHP_FORMAT);
504513
$orderNumberCreatedAtExpected[$orderNumber] = $orderCreatedAt;
505514
}
506515

0 commit comments

Comments
 (0)