Skip to content

Commit ecfb17d

Browse files
authored
ENGCOM-5911: graphQl-907: [Customer] Deprecate customer_id in CustomerAddress #935
2 parents 062924b + 888886d commit ecfb17d

File tree

8 files changed

+15
-9
lines changed

8 files changed

+15
-9
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function execute(AddressInterface $address): array
125125
}
126126
$addressData = array_merge($addressData, $customAttributes);
127127

128+
$addressData['customer_id'] = null;
129+
128130
return $addressData;
129131
}
130132
}

app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public function execute(CustomerInterface $customer): array
104104
//Field is deprecated and should not be exposed on storefront.
105105
$customerData['group_id'] = null;
106106
$customerData['model'] = $customer;
107+
$customerData['id'] = null;
108+
107109
return $customerData;
108110
}
109111
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ type Customer @doc(description: "Customer defines the customer name and address
8989
default_shipping: String @doc(description: "The ID assigned to the shipping address")
9090
dob: String @doc(description: "The customer's date of birth")
9191
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
92-
id: Int @doc(description: "The ID assigned to the customer")
92+
id: Int @doc(description: "The ID assigned to the customer") @deprecated(reason: "id is not needed as part of Customer because on server side it can be identified based on customer token used for authentication. There is no need to know customer ID on the client side.")
9393
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\IsSubscribed")
9494
addresses: [CustomerAddress] @doc(description: "An array containing the customer's shipping and billing addresses") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CustomerAddresses")
9595
gender: Int @doc(description: "The customer's gender(Male - 1, Female - 2)")
9696
}
9797

9898
type CustomerAddress @doc(description: "CustomerAddress contains detailed information about a customer's billing and shipping addresses"){
9999
id: Int @doc(description: "The ID assigned to the address object")
100-
customer_id: Int @doc(description: "The customer ID")
100+
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.")
101101
region: CustomerAddressRegion @doc(description: "An object containing the region name, region code, and region ID")
102102
region_id: Int @doc(description: "A number that uniquely identifies the state, province, or other area")
103103
country_id: String @doc(description: "The customer's country")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ protected function setUp()
4343
*/
4444
public function testCreateCustomerAddress()
4545
{
46-
$customerId = 1;
4746
$newAddress = [
4847
'region' => [
4948
'region' => 'Arizona',
@@ -124,11 +123,12 @@ public function testCreateCustomerAddress()
124123
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
125124
$this->assertArrayHasKey('createCustomerAddress', $response);
126125
$this->assertArrayHasKey('customer_id', $response['createCustomerAddress']);
127-
$this->assertEquals($customerId, $response['createCustomerAddress']['customer_id']);
126+
$this->assertEquals(null, $response['createCustomerAddress']['customer_id']);
128127
$this->assertArrayHasKey('id', $response['createCustomerAddress']);
129128

130129
$address = $this->addressRepository->getById($response['createCustomerAddress']['id']);
131130
$this->assertEquals($address->getId(), $response['createCustomerAddress']['id']);
131+
$address->setCustomerId(null);
132132
$this->assertCustomerAddressesFields($address, $response['createCustomerAddress']);
133133
$this->assertCustomerAddressesFields($address, $newAddress);
134134
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function testCreateCustomerAccountWithPassword()
6868
QUERY;
6969
$response = $this->graphQlMutation($query);
7070

71+
$this->assertEquals(null, $response['createCustomer']['customer']['id']);
7172
$this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']);
7273
$this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']);
7374
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testGetCustomerWithAddresses()
6262
is_array([$response['customer']['addresses']]),
6363
" Addresses field must be of an array type."
6464
);
65-
self::assertEquals($customer->getId(), $response['customer']['id']);
65+
self::assertEquals(null, $response['customer']['id']);
6666
$this->assertCustomerAddressesFields($customer, $response);
6767
}
6868

@@ -105,15 +105,15 @@ public function testGetCustomerAddressIfUserIsNotAuthorized()
105105
* @param CustomerInterface $customer
106106
* @param array $actualResponse
107107
*/
108-
public function assertCustomerAddressesFields($customer, $actualResponse)
108+
private function assertCustomerAddressesFields($customer, $actualResponse)
109109
{
110110
/** @var AddressInterface $addresses */
111111
$addresses = $customer->getAddresses();
112112
foreach ($addresses as $addressKey => $addressValue) {
113113
$this->assertNotEmpty($addressValue);
114114
$assertionMap = [
115115
['response_field' => 'id', 'expected_value' => $addresses[$addressKey]->getId()],
116-
['response_field' => 'customer_id', 'expected_value' => $addresses[$addressKey]->getCustomerId()],
116+
['response_field' => 'customer_id', 'expected_value' => 0],
117117
['response_field' => 'region_id', 'expected_value' => $addresses[$addressKey]->getRegionId()],
118118
['response_field' => 'country_id', 'expected_value' => $addresses[$addressKey]->getCountryId()],
119119
['response_field' => 'telephone', 'expected_value' => $addresses[$addressKey]->getTelephone()],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function testGetCustomer()
5050
$query = <<<QUERY
5151
query {
5252
customer {
53+
id
5354
firstname
5455
lastname
5556
email
@@ -58,6 +59,7 @@ public function testGetCustomer()
5859
QUERY;
5960
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
6061

62+
$this->assertEquals(null, $response['customer']['id']);
6163
$this->assertEquals('John', $response['customer']['firstname']);
6264
$this->assertEquals('Smith', $response['customer']['lastname']);
6365
$this->assertEquals($currentEmail, $response['customer']['email']);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,14 @@ public function testUpdateCustomerAddress()
5959
{
6060
$userName = '[email protected]';
6161
$password = 'password';
62-
$customerId = 1;
6362
$addressId = 1;
6463

6564
$mutation = $this->getMutation($addressId);
6665

6766
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
6867
$this->assertArrayHasKey('updateCustomerAddress', $response);
6968
$this->assertArrayHasKey('customer_id', $response['updateCustomerAddress']);
70-
$this->assertEquals($customerId, $response['updateCustomerAddress']['customer_id']);
69+
$this->assertEquals(null, $response['updateCustomerAddress']['customer_id']);
7170
$this->assertArrayHasKey('id', $response['updateCustomerAddress']);
7271

7372
$address = $this->addressRepository->getById($addressId);

0 commit comments

Comments
 (0)