Skip to content

Commit b98d464

Browse files
committed
Merge remote-tracking branch 'origin/AC-14431' into spartans_pr_04082025
2 parents e77c4e4 + b30aac8 commit b98d464

File tree

3 files changed

+144
-3
lines changed

3 files changed

+144
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function format(OrderInterface $orderModel): array
4949
'increment_id' => $orderModel->getIncrementId(),
5050
'number' => $orderModel->getIncrementId(),
5151
'order_date' => $this->timezone->date($orderModel->getCreatedAt())
52-
->format(DateTime::DATETIME_PHP_FORMAT),
52+
->format('d/m/Y H:i:s'),
5353
'order_number' => $orderModel->getIncrementId(),
5454
'status' => $orderModel->getStatusLabel(),
5555
'email' => $orderModel->getCustomerEmail(),
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2025 Adobe
5+
* All Rights Reserved.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\GraphQl\Sales;
10+
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
12+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
13+
use Magento\Checkout\Test\Fixture\SetBillingAddress;
14+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
15+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
16+
use Magento\Checkout\Test\Fixture\SetShippingAddress;
17+
use Magento\Customer\Test\Fixture\Customer;
18+
use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
19+
use Magento\Integration\Api\CustomerTokenServiceInterface;
20+
use Magento\Quote\Test\Fixture\AddProductToCart;
21+
use Magento\Quote\Test\Fixture\CustomerCart;
22+
use Magento\Store\Test\Fixture\Store;
23+
use Magento\TestFramework\Helper\Bootstrap;
24+
use Magento\TestFramework\TestCase\GraphQlAbstract;
25+
use Magento\TestFramework\Fixture\DataFixture;
26+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
27+
28+
class OrderDateFormattingTest extends GraphQlAbstract
29+
{
30+
/**
31+
* @var CustomerTokenServiceInterface
32+
*/
33+
private $customerTokenService;
34+
35+
/**
36+
* @var LocaleResolver
37+
*/
38+
private $localeResolver;
39+
40+
protected function setUp(): void
41+
{
42+
$objectManager = Bootstrap::getObjectManager();
43+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
44+
$this->localeResolver = $objectManager->get(LocaleResolver::class);
45+
}
46+
47+
/**
48+
* Test order_date with null/empty created_at
49+
*/
50+
#[
51+
DataFixture(Store::class),
52+
DataFixture(ProductFixture::class, as: 'product1'),
53+
DataFixture(Customer::class, as: 'customer'),
54+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote'),
55+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product1.id$', 'qty' => 2]),
56+
DataFixture(SetBillingAddress::class, ['cart_id' => '$quote.id$']),
57+
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote.id$']),
58+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
59+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
60+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order'),
61+
]
62+
public function testOrderDateWithInvalidCreatedAt()
63+
{
64+
$customer = DataFixtureStorageManager::getStorage()->get('customer');
65+
$customerEmail = $customer->getEmail();
66+
$password = 'password';
67+
$customerToken = $this->customerTokenService
68+
->createCustomerAccessToken($customerEmail, $password);
69+
70+
$query = <<<QUERY
71+
{
72+
customer {
73+
orders {
74+
items {
75+
order_date
76+
created_at
77+
}
78+
}
79+
}
80+
}
81+
QUERY;
82+
83+
$response = $this->graphQlQuery($query, [], '', ['Authorization' => 'Bearer ' . $customerToken]);
84+
85+
$this->assertArrayHasKey('customer', $response);
86+
$this->assertArrayHasKey('orders', $response['customer']);
87+
$expectedFormat = 'd/m/Y H:i:s';
88+
$dateString = $response['customer']['orders']['items'][0]['order_date'];
89+
$date = \DateTime::createFromFormat($expectedFormat, $dateString);
90+
$isValid = $date && $date->format($expectedFormat) === $dateString;
91+
$this->assertTrue($isValid, "Date format is not valid: $dateString");
92+
}
93+
94+
/**
95+
* Test order_date formatting performance with multiple locales
96+
*/
97+
#[
98+
DataFixture(Store::class),
99+
DataFixture(ProductFixture::class, as: 'product1'),
100+
DataFixture(Customer::class, as: 'customer'),
101+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote'),
102+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product1.id$', 'qty' => 2]),
103+
DataFixture(SetBillingAddress::class, ['cart_id' => '$quote.id$']),
104+
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote.id$']),
105+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
106+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
107+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order'),
108+
]
109+
public function testOrderDateFormattingPerformance()
110+
{
111+
$locales = ['en_US', 'fr_FR', 'de_DE', 'es_ES', 'it_IT'];
112+
113+
$customer = DataFixtureStorageManager::getStorage()->get('customer');
114+
$customerEmail = $customer->getEmail();
115+
$password = 'password';
116+
$customerToken = $this->customerTokenService->createCustomerAccessToken($customerEmail, $password);
117+
118+
$query = <<<QUERY
119+
{
120+
customer {
121+
orders {
122+
items {
123+
order_date
124+
}
125+
}
126+
}
127+
}
128+
QUERY;
129+
130+
foreach ($locales as $locale) {
131+
$this->localeResolver->setLocale($locale);
132+
$response = $this->graphQlQuery($query, [], '', ['Authorization' => 'Bearer ' . $customerToken]);
133+
$this->assertArrayHasKey('customer', $response);
134+
$this->assertArrayHasKey('orders', $response['customer']);
135+
$expectedFormat = 'd/m/Y H:i:s';
136+
$dateString = $response['customer']['orders']['items'][0]['order_date'];
137+
$date = \DateTime::createFromFormat($expectedFormat, $dateString);
138+
$isValid = $date && $date->format($expectedFormat) === $dateString;
139+
$this->assertTrue($isValid, "Date format is not valid: $dateString");
140+
}
141+
}
142+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\Api\SearchCriteriaBuilder;
1212
use Magento\Framework\Exception\AuthenticationException;
1313
use Magento\Framework\Registry;
14-
use Magento\Framework\Stdlib\DateTime;
1514
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1615
use Magento\GraphQl\GetCustomerAuthenticationHeader;
1716
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -509,7 +508,7 @@ public function testGetCustomerDescendingSortedOrders()
509508
for ($i = 1; $i <= 3; $i++) {
510509
$orderNumber = $this->fixtures->get('or' . $i)->getIncrementId();
511510
$orderCreatedAt = $this->timezone->date($this->fixtures->get('or' . $i)->getCreatedAt())
512-
->format(DateTime::DATETIME_PHP_FORMAT);
511+
->format('d/m/Y H:i:s');
513512
$orderNumberCreatedAtExpected[$orderNumber] = $orderCreatedAt;
514513
}
515514

0 commit comments

Comments
 (0)