public function testGetAddressAttributeMetadataNoSuchEntity() { try { $this->_service->getAttributeMetadata('1'); $this->fail('Expected exception not thrown.'); } catch (NoSuchEntityException $e) { $this->assertEquals('No such entity with entityType = customer_address, attributeCode = 1', $e->getMessage()); } }
/** * {@inheritdoc} */ protected function _getAttribute($attributeCode) { if ($this->getForceUseCustomerAttributes() || $this->getObject() instanceof CustomerInterface) { return parent::_getAttribute($attributeCode); } try { $attribute = $this->addressMetadata->getAttributeMetadata($attributeCode); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return null; } if ($this->getForceUseCustomerRequiredAttributes() && $attribute && !$attribute->isRequired()) { $customerAttribute = parent::_getAttribute($attributeCode); if ($customerAttribute && $customerAttribute->isRequired()) { $attribute = $customerAttribute; } } return $attribute; }
/** * Get string with frontend validation classes for attribute * * @param string $attributeCode * @return string * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getAttributeValidationClass($attributeCode) { $class = ''; try { /** @var $attribute AttributeMetadataInterface */ $attribute = isset($this->_attributes[$attributeCode]) ? $this->_attributes[$attributeCode] : $this->_addressMetadataService->getAttributeMetadata($attributeCode); $class = $attribute ? $attribute->getFrontendClass() : ''; if (in_array($attributeCode, ['firstname', 'middlename', 'lastname', 'prefix', 'suffix', 'taxvat'])) { if ($class && !$attribute->isVisible()) { // address attribute is not visible thus its validation rules are not applied $class = ''; } /** @var $customerAttribute AttributeMetadataInterface */ $customerAttribute = $this->_customerMetadataService->getAttributeMetadata($attributeCode); $class .= $customerAttribute && $customerAttribute->isVisible() ? $customerAttribute->getFrontendClass() : ''; $class = implode(' ', array_unique(array_filter(explode(' ', $class)))); } } catch (NoSuchEntityException $e) { // the attribute does not exist so just return an empty string } return $class; }