|
8 | 8 | use Magento\Catalog\Helper\Product\ConfigurationPool;
|
9 | 9 | use Magento\Checkout\Helper\Data as CheckoutHelper;
|
10 | 10 | use Magento\Checkout\Model\Session as CheckoutSession;
|
| 11 | +use Magento\Customer\Api\AddressMetadataInterface; |
11 | 12 | use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
|
12 | 13 | use Magento\Customer\Model\Context as CustomerContext;
|
13 | 14 | use Magento\Customer\Model\Session as CustomerSession;
|
14 | 15 | use Magento\Customer\Model\Url as CustomerUrlManager;
|
15 | 16 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
16 | 17 | use Magento\Framework\App\Http\Context as HttpContext;
|
| 18 | +use Magento\Framework\App\ObjectManager; |
17 | 19 | use Magento\Framework\Data\Form\FormKey;
|
18 | 20 | use Magento\Framework\Locale\FormatInterface as LocaleFormat;
|
19 | 21 | use Magento\Framework\UrlInterface;
|
@@ -159,6 +161,11 @@ class DefaultConfigProvider implements ConfigProviderInterface
|
159 | 161 | */
|
160 | 162 | protected $urlBuilder;
|
161 | 163 |
|
| 164 | + /** |
| 165 | + * @var AddressMetadataInterface |
| 166 | + */ |
| 167 | + private $addressMetadata; |
| 168 | + |
162 | 169 | /**
|
163 | 170 | * @param CheckoutHelper $checkoutHelper
|
164 | 171 | * @param Session $checkoutSession
|
@@ -186,6 +193,7 @@ class DefaultConfigProvider implements ConfigProviderInterface
|
186 | 193 | * @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
187 | 194 | * @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
|
188 | 195 | * @param UrlInterface $urlBuilder
|
| 196 | + * @param AddressMetadataInterface $addressMetadata |
189 | 197 | * @codeCoverageIgnore
|
190 | 198 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
191 | 199 | */
|
@@ -215,7 +223,8 @@ public function __construct(
|
215 | 223 | \Magento\Shipping\Model\Config $shippingMethodConfig,
|
216 | 224 | \Magento\Store\Model\StoreManagerInterface $storeManager,
|
217 | 225 | \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
|
218 |
| - UrlInterface $urlBuilder |
| 226 | + UrlInterface $urlBuilder, |
| 227 | + AddressMetadataInterface $addressMetadata = null |
219 | 228 | ) {
|
220 | 229 | $this->checkoutHelper = $checkoutHelper;
|
221 | 230 | $this->checkoutSession = $checkoutSession;
|
@@ -243,6 +252,7 @@ public function __construct(
|
243 | 252 | $this->storeManager = $storeManager;
|
244 | 253 | $this->paymentMethodManagement = $paymentMethodManagement;
|
245 | 254 | $this->urlBuilder = $urlBuilder;
|
| 255 | + $this->addressMetadata = $addressMetadata ?: ObjectManager::getInstance()->get(AddressMetadataInterface::class); |
246 | 256 | }
|
247 | 257 |
|
248 | 258 | /**
|
@@ -324,11 +334,34 @@ private function getCustomerData()
|
324 | 334 | $customerData = $customer->__toArray();
|
325 | 335 | foreach ($customer->getAddresses() as $key => $address) {
|
326 | 336 | $customerData['addresses'][$key]['inline'] = $this->getCustomerAddressInline($address);
|
| 337 | + if ($address->getCustomAttributes()) { |
| 338 | + $customerData['addresses'][$key]['custom_attributes'] = $this->filterNotVisibleAttributes( |
| 339 | + $customerData['addresses'][$key]['custom_attributes'] |
| 340 | + ); |
| 341 | + } |
327 | 342 | }
|
328 | 343 | }
|
329 | 344 | return $customerData;
|
330 | 345 | }
|
331 | 346 |
|
| 347 | + /** |
| 348 | + * Filter not visible on storefront custom attributes. |
| 349 | + * |
| 350 | + * @param array $attributes |
| 351 | + * @return array |
| 352 | + */ |
| 353 | + private function filterNotVisibleAttributes(array $attributes) |
| 354 | + { |
| 355 | + $attributesMetadata = $this->addressMetadata->getAllAttributesMetadata(); |
| 356 | + foreach ($attributesMetadata as $attributeMetadata) { |
| 357 | + if (!$attributeMetadata->isVisible()) { |
| 358 | + unset($attributes[$attributeMetadata->getAttributeCode()]); |
| 359 | + } |
| 360 | + } |
| 361 | + |
| 362 | + return $attributes; |
| 363 | + } |
| 364 | + |
332 | 365 | /**
|
333 | 366 | * Set additional customer address data
|
334 | 367 | *
|
|
0 commit comments