Skip to content

Commit 9a698ee

Browse files
authored
LYNX-536:orders/date_of_first_order always returning null
1 parent 0fbfc39 commit 9a698ee

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4646
if ($context->getExtensionAttributes()->getIsCustomer() === false) {
4747
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
4848
}
49-
$storeIds = $value['store_ids'] ?? [$context->getExtensionAttributes()->getStore()->getId()];
49+
$storeIds = $value['store_ids'] ?: [$context->getExtensionAttributes()->getStore()->getId()];
5050
return $this->getDateOfFirstOrder($context->getUserId(), $storeIds);
5151
}
5252

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,68 @@ public function testGetCustomerOrdersStoreScope()
194194
self::assertArrayHasKey('date_of_first_order', $response['customer']['orders']);
195195
}
196196

197+
/**
198+
* Test the date_of_first_order data for customerOrders query without any scope
199+
*
200+
* @throws AuthenticationException
201+
* @throws Exception
202+
*/
203+
public function testGetCustomerOrdersWithoutScope()
204+
{
205+
$store2 = $this->fixtures->get('store2');
206+
$customerEmail = $this->fixtures->get('customer')->getEmail();
207+
$generateToken = $this->generateCustomerToken($customerEmail, 'password');
208+
$tokenResponse = $this->graphQlMutationWithResponseHeaders(
209+
$generateToken,
210+
[],
211+
'',
212+
['Store' => $store2->getCode()]
213+
);
214+
$token = $tokenResponse['body']['generateCustomerToken']['token'];
215+
$customerAuthHeaders = $this->getCustomerHeaders($token, $store2->getCode());
216+
217+
$query = $this->getCustomerOrdersQueryWithFilters();
218+
$response = $this->graphQlQuery($query, [], '', $customerAuthHeaders);
219+
self::assertArrayHasKey('date_of_first_order', $response['customer']['orders']);
220+
self::assertNotNull($response['customer']['orders']['date_of_first_order']);
221+
}
222+
223+
/**
224+
* Test the date_of_first_order data for customerOrders query without
225+
* any scope and store header
226+
*
227+
* @throws AuthenticationException
228+
* @throws Exception
229+
*/
230+
#[
231+
DataFixture(ProductFixture::class, as: 'product'),
232+
DataFixture(CustomerFixture::class, as: 'customer'),
233+
DataFixture(CustomerCartFixture::class, ['customer_id' => '$customer.id$'], as: 'quote'),
234+
DataFixture(AddProductToCartFixture::class, [
235+
'cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1
236+
]),
237+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$quote.id$']),
238+
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$quote.id$']),
239+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
240+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
241+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order')
242+
]
243+
public function testGetCustomerOrdersWithoutScopeAndStoreHeader()
244+
{
245+
$customerEmail = $this->fixtures->get('customer')->getEmail();
246+
$generateToken = $this->generateCustomerToken($customerEmail, 'password');
247+
$tokenResponse = $this->graphQlMutationWithResponseHeaders(
248+
$generateToken
249+
);
250+
$token = $tokenResponse['body']['generateCustomerToken']['token'];
251+
$customerAuthHeaders = $this->getCustomerHeaders($token, null);
252+
253+
$query = $this->getCustomerOrdersQueryWithFilters();
254+
$response = $this->graphQlQuery($query, [], '', $customerAuthHeaders);
255+
self::assertArrayHasKey('date_of_first_order', $response['customer']['orders']);
256+
self::assertNotNull($response['customer']['orders']['date_of_first_order']);
257+
}
258+
197259
/**
198260
* Get Customer Orders query
199261
*

0 commit comments

Comments
 (0)