public function testGetCustomerAttributeMetadataNoSuchEntity() { try { $this->_service->getCustomerAttributeMetadata('20'); $this->fail('Expected exception not thrown.'); } catch (NoSuchEntityException $e) { $this->assertEquals('No such entity with entityType = customer, attributeCode = 20', $e->getMessage()); } }
/** * 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->getCustomerAttributeMetadata('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(); }
/** * Retrieve customer attribute instance * * @param string $attributeCode * @return \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata|null */ protected function _getAttribute($attributeCode) { try { return $this->_attributeMetadata->getCustomerAttributeMetadata($attributeCode); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return null; } }
/** * @param string $attributeCode * @return Data\Eav\AttributeMetadata|null */ private function getAttributeMetadata($attributeCode) { try { return $this->customerMetadataService->getCustomerAttributeMetadata($attributeCode); } catch (NoSuchEntityException $e) { return null; } }