Skip to content

Commit cc599e5

Browse files
🔃 [Magento Community Engineering] Community Contributions - GraphQL daily delivery
Accepted Community Pull Requests: - magento/graphql-ce#1013: magento graphql-ce#970 Cannot return several errors for one GraphQL request (by @lenaorobei) - magento/graphql-ce#1012: magento/graphql-ce#: Editorial. Fix CustomerOrder.increment_id description (by @atwixfirster) - magento/graphql-ce#996: magento/graphql-ce#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart (by @atwixfirster) - magento/graphql-ce#958: graphQl-914: [Customer] Improve consistency of country field in custo… (by @kisroman) Fixed GitHub Issues: - #970: Product reviews list template paging issue. (reported by @tzyganu) has been fixed in magento/graphql-ce#1013 by @lenaorobei in 2.3-develop branch Related commits: 1. a18b0e1 2. 39042ac - #977: Recurring Install Issue (reported by @mattisbusycom) has been fixed in magento/graphql-ce#996 by @atwixfirster in 2.3-develop branch Related commits: 1. 90557f9 2. 5bf67e5 3. f49fe71
2 parents 4003975 + 2ed4caa commit cc599e5

File tree

13 files changed

+311
-40
lines changed

13 files changed

+311
-40
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/Address/CreateCustomerAddress.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct(
6767
*/
6868
public function execute(int $customerId, array $data): AddressInterface
6969
{
70+
// It is needed because AddressInterface has country_id field.
71+
if (isset($data['country_code'])) {
72+
$data['country_id'] = $data['country_code'];
73+
}
7074
$this->validateData($data);
7175

7276
/** @var AddressInterface $address */

app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public function execute(AddressInterface $address): array
127127

128128
$addressData['customer_id'] = null;
129129

130+
if (isset($addressData['country_id'])) {
131+
$addressData['country_code'] = $addressData['country_id'];
132+
}
133+
130134
return $addressData;
131135
}
132136
}

app/code/Magento/CustomerGraphQl/Model/Customer/Address/UpdateCustomerAddress.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public function __construct(
6666
*/
6767
public function execute(AddressInterface $address, array $data): void
6868
{
69+
if (isset($data['country_code'])) {
70+
$data['country_id'] = $data['country_code'];
71+
}
6972
$this->validateData($data);
7073

7174
$filteredData = array_diff_key($data, array_flip($this->restrictedKeys));

app/code/Magento/CustomerGraphQl/etc/schema.graphqls

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ input CustomerAddressInput {
2828
city: String @doc(description: "The city or town")
2929
region: CustomerAddressRegionInput @doc(description: "An object containing the region name, region code, and region ID")
3030
postcode: String @doc(description: "The customer's ZIP or postal code")
31-
country_id: CountryCodeEnum @doc(description: "The customer's country")
31+
country_id: CountryCodeEnum @doc(description: "Deprecated: use `country_code` instead.")
32+
country_code: CountryCodeEnum @doc(description: "The customer's country")
3233
default_shipping: Boolean @doc(description: "Indicates whether the address is the default shipping address")
3334
default_billing: Boolean @doc(description: "Indicates whether the address is the default billing address")
3435
fax: String @doc(description: "The fax number")
@@ -102,7 +103,8 @@ type CustomerAddress @doc(description: "CustomerAddress contains detailed inform
102103
customer_id: Int @doc(description: "The customer ID") @deprecated(reason: "customer_id is not needed as part of CustomerAddress, address ID (id) is unique identifier for the addresses.")
103104
region: CustomerAddressRegion @doc(description: "An object containing the region name, region code, and region ID")
104105
region_id: Int @deprecated(reason: "Region ID is excessive on storefront and region code should suffice for all scenarios")
105-
country_id: String @doc(description: "The customer's country")
106+
country_id: String @doc(description: "The customer's country") @deprecated(reason: "Use `country_code` instead.")
107+
country_code: CountryCodeEnum @doc(description: "The customer's country")
106108
street: [String] @doc(description: "An array of strings that define the street number and name")
107109
company: String @doc(description: "The customer's company")
108110
telephone: String @doc(description: "The telephone number")

app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Exception\InputException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
@@ -52,7 +52,7 @@ public function execute(
5252
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping);
5353
} catch (NoSuchEntityException $e) {
5454
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
55-
} catch (LocalizedException $e) {
55+
} catch (InputException $e) {
5656
throw new GraphQlInputException(__($e->getMessage()), $e);
5757
}
5858
}

app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Exception\InputException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
@@ -50,7 +50,7 @@ public function execute(
5050
$this->shippingAddressManagement->assign($cart->getId(), $shippingAddress);
5151
} catch (NoSuchEntityException $e) {
5252
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
53-
} catch (LocalizedException $e) {
53+
} catch (InputException $e) {
5454
throw new GraphQlInputException(__($e->getMessage()), $e);
5555
}
5656
}

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Query {
77

88
type CustomerOrder @doc(description: "Order mapping fields") {
99
id: Int
10-
increment_id: String @deprecated(reason: "Use the order_number instaed.")
10+
increment_id: String @deprecated(reason: "Use the order_number instead.")
1111
order_number: String! @doc(description: "The order number")
1212
created_at: String
1313
grand_total: Float

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerAddressTest.php

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testCreateCustomerAddress()
4949
'region_id' => 4,
5050
'region_code' => 'AZ'
5151
],
52-
'country_id' => 'US',
52+
'country_code' => 'US',
5353
'street' => ['Line 1 Street', 'Line 2'],
5454
'company' => 'Company name',
5555
'telephone' => '123456789',
@@ -75,7 +75,7 @@ public function testCreateCustomerAddress()
7575
region_id: {$newAddress['region']['region_id']}
7676
region_code: "{$newAddress['region']['region_code']}"
7777
}
78-
country_id: {$newAddress['country_id']}
78+
country_code: {$newAddress['country_code']}
7979
street: ["{$newAddress['street'][0]}","{$newAddress['street'][1]}"]
8080
company: "{$newAddress['company']}"
8181
telephone: "{$newAddress['telephone']}"
@@ -98,7 +98,7 @@ public function testCreateCustomerAddress()
9898
region_id
9999
region_code
100100
}
101-
country_id
101+
country_code
102102
street
103103
company
104104
telephone
@@ -133,6 +133,75 @@ public function testCreateCustomerAddress()
133133
$this->assertCustomerAddressesFields($address, $newAddress);
134134
}
135135

136+
/**
137+
* Test case for deprecated `country_id` field.
138+
*
139+
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
140+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
141+
*/
142+
public function testCreateCustomerAddressWithCountryId()
143+
{
144+
$newAddress = [
145+
'region' => [
146+
'region' => 'Arizona',
147+
'region_id' => 4,
148+
'region_code' => 'AZ'
149+
],
150+
'country_id' => 'US',
151+
'street' => ['Line 1 Street', 'Line 2'],
152+
'company' => 'Company name',
153+
'telephone' => '123456789',
154+
'fax' => '123123123',
155+
'postcode' => '7777',
156+
'city' => 'City Name',
157+
'firstname' => 'Adam',
158+
'lastname' => 'Phillis',
159+
'middlename' => 'A',
160+
'prefix' => 'Mr.',
161+
'suffix' => 'Jr.',
162+
'vat_id' => '1',
163+
'default_shipping' => true,
164+
'default_billing' => false
165+
];
166+
167+
$mutation
168+
= <<<MUTATION
169+
mutation {
170+
createCustomerAddress(input: {
171+
region: {
172+
region: "{$newAddress['region']['region']}"
173+
region_id: {$newAddress['region']['region_id']}
174+
region_code: "{$newAddress['region']['region_code']}"
175+
}
176+
country_id: {$newAddress['country_id']}
177+
street: ["{$newAddress['street'][0]}","{$newAddress['street'][1]}"]
178+
company: "{$newAddress['company']}"
179+
telephone: "{$newAddress['telephone']}"
180+
fax: "{$newAddress['fax']}"
181+
postcode: "{$newAddress['postcode']}"
182+
city: "{$newAddress['city']}"
183+
firstname: "{$newAddress['firstname']}"
184+
lastname: "{$newAddress['lastname']}"
185+
middlename: "{$newAddress['middlename']}"
186+
prefix: "{$newAddress['prefix']}"
187+
suffix: "{$newAddress['suffix']}"
188+
vat_id: "{$newAddress['vat_id']}"
189+
default_shipping: true
190+
default_billing: false
191+
}) {
192+
country_id
193+
}
194+
}
195+
MUTATION;
196+
197+
$userName = 'customer@example.com';
198+
$password = 'password';
199+
200+
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
201+
$this->assertArrayHasKey('createCustomerAddress', $response);
202+
$this->assertEquals($newAddress['country_id'], $response['createCustomerAddress']['country_id']);
203+
}
204+
136205
/**
137206
* @expectedException Exception
138207
* @expectedExceptionMessage The current customer isn't authorized.
@@ -153,7 +222,7 @@ public function testCreateCustomerAddressIfUserIsNotAuthorized()
153222
region: {
154223
region_id: 1
155224
}
156-
country_id: US
225+
country_code: US
157226
postcode: "9999"
158227
default_shipping: true
159228
default_billing: false
@@ -182,7 +251,7 @@ public function testCreateCustomerAddressWithMissingAttribute()
182251
region: {
183252
region_id: 1
184253
}
185-
country_id: US
254+
country_code: US
186255
street: ["Line 1 Street","Line 2"]
187256
company: "Company name"
188257
telephone: "123456789"
@@ -235,7 +304,7 @@ public function testCreateCustomerAddressWithRedundantStreetLine()
235304
'region_id' => 4,
236305
'region_code' => 'AZ'
237306
],
238-
'country_id' => 'US',
307+
'country_code' => 'US',
239308
'street' => ['Line 1 Street', 'Line 2', 'Line 3'],
240309
'company' => 'Company name',
241310
'telephone' => '123456789',
@@ -261,7 +330,7 @@ public function testCreateCustomerAddressWithRedundantStreetLine()
261330
region_id: {$newAddress['region']['region_id']}
262331
region_code: "{$newAddress['region']['region_code']}"
263332
}
264-
country_id: {$newAddress['country_id']}
333+
country_code: {$newAddress['country_code']}
265334
street: ["{$newAddress['street'][0]}","{$newAddress['street'][1]}","{$newAddress['street'][2]}"]
266335
company: "{$newAddress['company']}"
267336
telephone: "{$newAddress['telephone']}"
@@ -334,12 +403,15 @@ public function invalidInputDataProvider()
334403
*
335404
* @param AddressInterface $address
336405
* @param array $actualResponse
406+
* @param string $countryFieldName
337407
*/
338-
private function assertCustomerAddressesFields(AddressInterface $address, array $actualResponse): void
339-
{
408+
private function assertCustomerAddressesFields(
409+
AddressInterface $address,
410+
array $actualResponse
411+
): void {
340412
/** @var $addresses */
341413
$assertionMap = [
342-
['response_field' => 'country_id', 'expected_value' => $address->getCountryId()],
414+
['response_field' => 'country_code', 'expected_value' => $address->getCountryId()],
343415
['response_field' => 'street', 'expected_value' => $address->getStreet()],
344416
['response_field' => 'company', 'expected_value' => $address->getCompany()],
345417
['response_field' => 'telephone', 'expected_value' => $address->getTelephone()],

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,56 @@ public function testUpdateCustomerAddress()
7676
$this->assertCustomerAddressesFields($address, $updateAddress);
7777
}
7878

79+
/**
80+
* Test case for deprecated `country_id` field.
81+
*
82+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
83+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
84+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
85+
*/
86+
public function testUpdateCustomerAddressWithCountryId()
87+
{
88+
$userName = 'customer@example.com';
89+
$password = 'password';
90+
$addressId = 1;
91+
92+
$updateAddress = $this->getAddressData();
93+
94+
$mutation = $mutation
95+
= <<<MUTATION
96+
mutation {
97+
updateCustomerAddress(id: {$addressId}, input: {
98+
region: {
99+
region: "{$updateAddress['region']['region']}"
100+
region_id: {$updateAddress['region']['region_id']}
101+
region_code: "{$updateAddress['region']['region_code']}"
102+
}
103+
country_id: {$updateAddress['country_code']}
104+
street: ["{$updateAddress['street'][0]}","{$updateAddress['street'][1]}"]
105+
company: "{$updateAddress['company']}"
106+
telephone: "{$updateAddress['telephone']}"
107+
fax: "{$updateAddress['fax']}"
108+
postcode: "{$updateAddress['postcode']}"
109+
city: "{$updateAddress['city']}"
110+
firstname: "{$updateAddress['firstname']}"
111+
lastname: "{$updateAddress['lastname']}"
112+
middlename: "{$updateAddress['middlename']}"
113+
prefix: "{$updateAddress['prefix']}"
114+
suffix: "{$updateAddress['suffix']}"
115+
vat_id: "{$updateAddress['vat_id']}"
116+
default_shipping: true
117+
default_billing: true
118+
}) {
119+
country_id
120+
}
121+
}
122+
MUTATION;
123+
124+
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
125+
$this->assertArrayHasKey('updateCustomerAddress', $response);
126+
$this->assertEquals($updateAddress['country_code'], $response['updateCustomerAddress']['country_id']);
127+
}
128+
79129
/**
80130
* @expectedException Exception
81131
* @expectedExceptionMessage The current customer isn't authorized.
@@ -131,12 +181,15 @@ public function testUpdateCustomerAddressWithMissingAttribute()
131181
*
132182
* @param AddressInterface $address
133183
* @param array $actualResponse
184+
* @param string $countryFieldName
134185
*/
135-
private function assertCustomerAddressesFields(AddressInterface $address, $actualResponse): void
136-
{
186+
private function assertCustomerAddressesFields(
187+
AddressInterface $address,
188+
$actualResponse
189+
): void {
137190
/** @var $addresses */
138191
$assertionMap = [
139-
['response_field' => 'country_id', 'expected_value' => $address->getCountryId()],
192+
['response_field' => 'country_code', 'expected_value' => $address->getCountryId()],
140193
['response_field' => 'street', 'expected_value' => $address->getStreet()],
141194
['response_field' => 'company', 'expected_value' => $address->getCompany()],
142195
['response_field' => 'telephone', 'expected_value' => $address->getTelephone()],
@@ -187,7 +240,7 @@ public function testUpdateCustomerAddressWithMissingId()
187240
region_id: {$updateAddress['region']['region_id']}
188241
region_code: "{$updateAddress['region']['region_code']}"
189242
}
190-
country_id: {$updateAddress['country_id']}
243+
country_code: {$updateAddress['country_code']}
191244
street: ["{$updateAddress['street'][0]}","{$updateAddress['street'][1]}"]
192245
company: "{$updateAddress['company']}"
193246
telephone: "{$updateAddress['telephone']}"
@@ -243,7 +296,7 @@ public function testUpdateCustomerAddressWithInvalidIdType()
243296
region_id: {$updateAddress['region']['region_id']}
244297
region_code: "{$updateAddress['region']['region_code']}"
245298
}
246-
country_id: {$updateAddress['country_id']}
299+
country_code: {$updateAddress['country_code']}
247300
street: ["{$updateAddress['street'][0]}","{$updateAddress['street'][1]}"]
248301
company: "{$updateAddress['company']}"
249302
telephone: "{$updateAddress['telephone']}"
@@ -382,11 +435,11 @@ private function getAddressData(): array
382435
{
383436
return [
384437
'region' => [
385-
'region' => 'Alaska',
386-
'region_id' => 2,
387-
'region_code' => 'AK'
438+
'region' => 'Alberta',
439+
'region_id' => 66,
440+
'region_code' => 'AB'
388441
],
389-
'country_id' => 'US',
442+
'country_code' => 'CA',
390443
'street' => ['Line 1 Street', 'Line 2'],
391444
'company' => 'Company Name',
392445
'telephone' => '123456789',
@@ -423,7 +476,7 @@ private function getMutation(int $addressId): string
423476
region_id: {$updateAddress['region']['region_id']}
424477
region_code: "{$updateAddress['region']['region_code']}"
425478
}
426-
country_id: {$updateAddress['country_id']}
479+
country_code: {$updateAddress['country_code']}
427480
street: ["{$updateAddress['street'][0]}","{$updateAddress['street'][1]}"]
428481
company: "{$updateAddress['company']}"
429482
telephone: "{$updateAddress['telephone']}"
@@ -446,7 +499,7 @@ private function getMutation(int $addressId): string
446499
region_id
447500
region_code
448501
}
449-
country_id
502+
country_code
450503
street
451504
company
452505
telephone

0 commit comments

Comments
 (0)