|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\CustomerGraphQl\Model\Resolver\Address; |
| 9 | + |
| 10 | +use Magento\Customer\Api\AddressMetadataManagementInterface; |
| 11 | +use Magento\Customer\Api\Data\AddressInterface; |
| 12 | +use Magento\Framework\Api\DataObjectHelper; |
| 13 | +use Magento\Eav\Model\Config; |
| 14 | + |
| 15 | +/** |
| 16 | + * Customers Address, used for GraphQL request processing. |
| 17 | + */ |
| 18 | +class AddressConfigProvider |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var Config |
| 22 | + */ |
| 23 | + private $eavConfig; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var DataObjectHelper |
| 27 | + */ |
| 28 | + private $dataObjectHelper; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var array |
| 32 | + */ |
| 33 | + private $addressAttributes; |
| 34 | + |
| 35 | + /** |
| 36 | + * @param Config $eavConfig |
| 37 | + * @param DataObjectHelper $dataObjectHelper |
| 38 | + */ |
| 39 | + public function __construct( |
| 40 | + Config $eavConfig, |
| 41 | + DataObjectHelper $dataObjectHelper |
| 42 | + ) { |
| 43 | + $this->eavConfig = $eavConfig; |
| 44 | + $this->dataObjectHelper = $dataObjectHelper; |
| 45 | + $this->addressAttributes = $this->eavConfig->getEntityAttributes( |
| 46 | + AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Add $addressInput array information to a $address object |
| 52 | + * |
| 53 | + * @param AddressInterface $address |
| 54 | + * @param array $addressInput |
| 55 | + * @return AddressInterface |
| 56 | + */ |
| 57 | + public function fillAddress(AddressInterface $address, array $addressInput) : AddressInterface |
| 58 | + { |
| 59 | + $this->dataObjectHelper->populateWithArray( |
| 60 | + $address, |
| 61 | + $addressInput, |
| 62 | + AddressInterface::class |
| 63 | + ); |
| 64 | + return $address; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Get address field configuration |
| 69 | + * |
| 70 | + * @return array |
| 71 | + */ |
| 72 | + public function getAddressAttributes() : array |
| 73 | + { |
| 74 | + return $this->addressAttributes; |
| 75 | + } |
| 76 | +} |
0 commit comments