/**
  * Process js Layout of block
  *
  * @param array $jsLayout
  * @return array
  */
 public function process($jsLayout)
 {
     /** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */
     $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection('customer_address', 'customer_register_address');
     $elements = [];
     foreach ($attributes as $attribute) {
         if ($attribute->getIsUserDefined()) {
             continue;
         }
         $elements[$attribute->getAttributeCode()] = $this->attributeMapper->map($attribute);
         if (isset($elements[$attribute->getAttributeCode()]['label'])) {
             $label = $elements[$attribute->getAttributeCode()]['label'];
             $elements[$attribute->getAttributeCode()]['label'] = __($label);
         }
     }
     // The following code is a workaround for custom address attributes
     if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children'])) {
         if (!isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'])) {
             $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] = [];
         }
         $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] = array_merge_recursive($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'], $this->processPaymentConfiguration($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['renders']['children'], $elements));
     }
     if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'])) {
         $fields = $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'];
         $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'] = $this->merger->merge($elements, 'checkoutProvider', 'shippingAddress', $fields);
     }
     return $jsLayout;
 }
 /**
  * Get attribute model by attribute data object
  *
  * @param string $entityType
  * @param AttributeMetadataInterface $attribute
  * @return Attribute
  * @throws NoSuchEntityException
  */
 public function getModelByAttribute($entityType, AttributeMetadataInterface $attribute)
 {
     /** @var Attribute $model */
     $model = $this->attributeMetadataDataProvider->getAttribute($entityType, $attribute->getAttributeCode());
     if ($model) {
         return $model;
     } else {
         throw new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_DOUBLE_FIELDS, ['fieldName' => 'entityType', 'fieldValue' => $entityType, 'field2Name' => 'attributeCode', 'field2Value' => $attribute->getAttributeCode()]));
     }
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage No such entity with entityType = type, attributeCode = code
  */
 public function testGetModelByAttributeWithoutModel()
 {
     $entityType = 'type';
     $attributeCode = 'code';
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->exactly(2))->method('getAttributeCode')->willReturn($attributeCode);
     $this->metadataDataProviderMock->expects($this->once())->method('getAttribute')->with($entityType, $attributeCode)->willReturn(false);
     $this->model->getModelByAttribute($entityType, $attributeMock);
 }
 /**
  * {@inheritdoc}
  */
 public function getAllAttributesMetadata()
 {
     /** @var AbstractAttribute[] $attribute */
     $attributeCodes = $this->attributeMetadataDataProvider->getAllAttributeCodes(self::ENTITY_TYPE_CUSTOMER, self::ATTRIBUTE_SET_ID_CUSTOMER);
     $attributesMetadata = [];
     foreach ($attributeCodes as $attributeCode) {
         try {
             $attributesMetadata[] = $this->getAttributeMetadata($attributeCode);
         } catch (NoSuchEntityException $e) {
             //If no such entity, skip
         }
     }
     return $attributesMetadata;
 }
 /**
  * @return array
  */
 private function getAddressAttributes()
 {
     /** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */
     $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection('customer_address', 'customer_register_address');
     $elements = [];
     foreach ($attributes as $attribute) {
         $code = $attribute->getAttributeCode();
         if ($attribute->getIsUserDefined()) {
             continue;
         }
         $elements[$code] = $this->attributeMapper->map($attribute);
         if (isset($elements[$code]['label'])) {
             $label = $elements[$code]['label'];
             $elements[$code]['label'] = __($label);
         }
     }
     return $elements;
 }
 public function testGetCustomAttributesMetadataWithoutAttributes()
 {
     $attributeCode = 'id';
     $attributeCodes = [$attributeCode];
     $this->attributeProviderMock->expects($this->once())->method('getAllAttributeCodes')->with(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS)->willReturn($attributeCodes);
     /** @var AbstractAttribute|\PHPUnit_Framework_MockObject_MockObject $attributeMock */
     $attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->attributeProviderMock->expects($this->once())->method('getAttribute')->with(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $attributeCode)->willReturn($attributeMock);
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $metadataMock */
     $metadataMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $result = [];
     $this->attributeConverterMock->expects($this->once())->method('createMetadataAttribute')->with($attributeMock)->willReturn($metadataMock);
     $metadataMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
     $this->assertEquals($result, $this->model->getCustomAttributesMetadata());
 }