serviceOutputProcessor = $serviceOutputProcessor; $this->jsonSerializer = $jsonSerializer; $this->customerResourceModel = $customerResourceModel; $this->customerFactory = $customerFactory; } /** * Curate shipping and billing default options * * @param array $address * @param AddressInterface $addressObject * @return array */ private function curateAddressDefaultValues(array $address, AddressInterface $addressObject) : array { $customerModel = $this->customerFactory->create(); $this->customerResourceModel->load($customerModel, $addressObject->getCustomerId()); $address[CustomerInterface::DEFAULT_BILLING] = ($customerModel->getDefaultBillingAddress() && $addressObject->getId() == $customerModel->getDefaultBillingAddress()->getId()); $address[CustomerInterface::DEFAULT_SHIPPING] = ($customerModel->getDefaultShippingAddress() && $addressObject->getId() == $customerModel->getDefaultShippingAddress()->getId()); return $address; } /** * Transform single customer address data from object to in array format * * @param AddressInterface $addressObject * @return array */ public function getAddressData(AddressInterface $addressObject): array { $address = $this->serviceOutputProcessor->process( $addressObject, AddressRepositoryInterface::class, 'getById' ); $address = $this->curateAddressDefaultValues($address, $addressObject); if (isset($address[CustomAttributesDataInterface::EXTENSION_ATTRIBUTES_KEY])) { $address = array_merge($address, $address[CustomAttributesDataInterface::EXTENSION_ATTRIBUTES_KEY]); } $customAttributes = []; if (isset($address[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES])) { foreach ($address[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] as $attribute) { $isArray = false; if (is_array($attribute['value'])) { $isArray = true; foreach ($attribute['value'] as $attributeValue) { if (is_array($attributeValue)) { $customAttributes[$attribute['attribute_code']] = $this->jsonSerializer->serialize( $attribute['value'] ); continue; } $customAttributes[$attribute['attribute_code']] = implode(',', $attribute['value']); continue; } } if ($isArray) { continue; } $customAttributes[$attribute['attribute_code']] = $attribute['value']; } } $address = array_merge($address, $customAttributes); return $address; } }