public function testGetAttributeMetadataNoSuchEntity()
 {
     try {
         $this->_service->getAttributeMetadata('customer_address', '1');
         $this->fail('Expected exception not thrown.');
     } catch (NoSuchEntityException $e) {
         $this->assertEquals('No such entity with entityType = customer_address, attributeCode = 1', $e->getMessage());
     }
 }
Esempio n. 2
0
 public function testGetAttributeMetadataWithoutAttributeMetadata()
 {
     $this->attributeMetadataDataProvider->expects($this->any())->method('getAttribute')->will($this->returnValue(false));
     try {
         $this->service->getAttributeMetadata('attributeId');
         $this->fail('Expected exception not thrown.');
     } catch (NoSuchEntityException $e) {
         $this->assertSame("No such entity with entityType = customer, attributeCode = attributeId", $e->getMessage());
     }
 }
Esempio n. 3
0
 /**
  * Edit/View Existing Customer form fields
  *
  * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
  * @return string[] Values to set on the form
  */
 protected function _addEditCustomerFormFields($fieldset)
 {
     $fieldset->getForm()->getElement('created_in')->setDisabled('disabled');
     $fieldset->getForm()->getElement('website_id')->setDisabled('disabled');
     $customerData = $this->_getCustomerDataObject();
     if ($customerData->getId() && !$this->_customerAccountService->canModify($customerData->getId())) {
         return array();
     }
     // Prepare customer confirmation control (only for existing customers)
     $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customerData->getId());
     $confirmationKey = $customerData->getConfirmation();
     if ($confirmationStatus != CustomerAccountServiceInterface::ACCOUNT_CONFIRMED) {
         $confirmationAttr = $this->_customerMetadataService->getAttributeMetadata('confirmation');
         if (!$confirmationKey) {
             $confirmationKey = $this->_getRandomConfirmationKey();
         }
         $element = $fieldset->addField('confirmation', 'select', array('name' => 'confirmation', 'label' => __($confirmationAttr->getFrontendLabel())));
         $element->setEntityAttribute($confirmationAttr);
         $element->setValues(array('' => 'Confirmed', $confirmationKey => 'Not confirmed'));
         // Prepare send welcome email checkbox if customer is not confirmed
         // no need to add it, if website ID is empty
         if ($customerData->getConfirmation() && $customerData->getWebsiteId()) {
             $fieldset->addField('sendemail', 'checkbox', array('name' => 'sendemail', 'label' => __('Send Welcome Email after Confirmation')));
             return array('sendemail' => '1');
         }
     }
     return array();
 }
Esempio n. 4
0
 /**
  * Retrieve customer attribute instance
  *
  * @param string $attributeCode
  * @return \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata|null
  */
 protected function _getAttribute($attributeCode)
 {
     try {
         return $this->customerMetadataService->getAttributeMetadata($attributeCode);
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
Esempio n. 5
0
 /**
  * Concatenate all customer name parts into full customer name.
  *
  * @param \Magento\Customer\Service\V1\Data\Customer $customerData
  * @return string
  */
 public function getCustomerName(\Magento\Customer\Service\V1\Data\Customer $customerData)
 {
     $name = '';
     $prefixMetadata = $this->_customerMetadataService->getAttributeMetadata('customer', 'prefix');
     if ($prefixMetadata->isVisible() && $customerData->getPrefix()) {
         $name .= $customerData->getPrefix() . ' ';
     }
     $name .= $customerData->getFirstname();
     $middleNameMetadata = $this->_customerMetadataService->getAttributeMetadata('customer', 'middlename');
     if ($middleNameMetadata->isVisible() && $customerData->getMiddlename()) {
         $name .= ' ' . $customerData->getMiddlename();
     }
     $name .= ' ' . $customerData->getLastname();
     $suffixMetadata = $this->_customerMetadataService->getAttributeMetadata('customer', 'suffix');
     if ($suffixMetadata->isVisible() && $customerData->getSuffix()) {
         $name .= ' ' . $customerData->getSuffix();
     }
     return $name;
 }
Esempio n. 6
0
 /**
  * Get string with frontend validation classes for attribute
  *
  * @param string $attributeCode
  * @return string
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getAttributeValidationClass($attributeCode)
 {
     /** @var $attribute \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata */
     $attribute = isset($this->_attributes[$attributeCode]) ? $this->_attributes[$attributeCode] : $this->_customerMetadataService->getAttributeMetadata('customer_address', $attributeCode);
     $class = $attribute ? $attribute->getFrontendClass() : '';
     if (in_array($attributeCode, array('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 \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata */
         $customerAttribute = $this->_customerMetadataService->getAttributeMetadata('customer', $attributeCode);
         $class .= $customerAttribute && $customerAttribute->isVisible() ? $customerAttribute->getFrontendClass() : '';
         $class = implode(' ', array_unique(array_filter(explode(' ', $class))));
     }
     return $class;
 }
Esempio n. 7
0
 /**
  * @param string $attributeCode
  * @return Data\Eav\AttributeMetadata|null
  */
 private function getAttributeMetadata($attributeCode)
 {
     try {
         return $this->customerMetadataService->getAttributeMetadata($attributeCode);
     } catch (NoSuchEntityException $e) {
         return null;
     }
 }