Skip to content

Commit 468b290

Browse files
committed
GraphQL-57: Curate address data on customerDataProvider
1 parent 71d242c commit 468b290

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/Address/AddressDataProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ public function __construct(
6464
*
6565
* @param array $address
6666
* @param AddressInterface $addressObject
67-
* @return null
67+
* @return array
6868
*/
6969
private function curateAddressDefaultValues(array $address, AddressInterface $addressObject) : array
7070
{
7171
$customerModel = $this->customerFactory->create();
7272
$this->customerResourceModel->load($customerModel, $addressObject->getCustomerId());
7373
$address[CustomerInterface::DEFAULT_BILLING] =
74-
($addressObject->getId() == $customerModel->getDefaultBillingAddress()->getId()) ? true : false;
74+
($customerModel->getDefaultBillingAddress()
75+
&& $addressObject->getId() == $customerModel->getDefaultBillingAddress()->getId()) ? true : false;
7576
$address[CustomerInterface::DEFAULT_SHIPPING] =
76-
($addressObject->getId() == $customerModel->getDefaultShippingAddress()->getId()) ? true : false;
77+
($customerModel->getDefaultShippingAddress()
78+
&& $addressObject->getId() == $customerModel->getDefaultShippingAddress()->getId()) ? true : false;
7779
return $address;
7880
}
7981

app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/CustomerDataProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ public function getCustomerById(int $customerId) : array
6767
return $this->processCustomer($customerObject);
6868
}
6969

70+
/**
71+
* Curate default shipping and default billing keys
72+
*
73+
* @param array $arrayAddress
74+
* @return array
75+
*/
76+
private function curateAddressData(array $arrayAddress) : array
77+
{
78+
foreach ($arrayAddress as $key => $address) {
79+
if (!isset($address['default_shipping'])) {
80+
$arrayAddress[$key]['default_shipping'] = false;
81+
}
82+
if (!isset($address['default_billing'])) {
83+
$arrayAddress[$key]['default_billing'] = false;
84+
}
85+
}
86+
return $arrayAddress;
87+
}
88+
7089
/**
7190
* Transform single customer data from object to in array format
7291
*
@@ -80,6 +99,7 @@ private function processCustomer(CustomerInterface $customerObject) : array
8099
CustomerRepositoryInterface::class,
81100
'get'
82101
);
102+
$customer['addresses'] = $this->curateAddressData($customer['addresses']);
83103
if (isset($customer['extension_attributes'])) {
84104
$customer = array_merge($customer, $customer['extension_attributes']);
85105
}

0 commit comments

Comments
 (0)