diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
index 32609252f0552..1967ee87d91aa 100644
--- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
+++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
@@ -12,6 +12,41 @@
class AttributeMerger
{
+ /**
+ * Map form element
+ *
+ * @var array
+ */
+ protected $formElementMap = [
+ 'checkbox' => 'Magento_Ui/js/form/element/select',
+ 'select' => 'Magento_Ui/js/form/element/select',
+ 'textarea' => 'Magento_Ui/js/form/element/textarea',
+ 'multiline' => 'Magento_Ui/js/form/components/group',
+ 'multiselect' => 'Magento_Ui/js/form/element/multiselect',
+ ];
+
+ /**
+ * Map template
+ *
+ * @var array
+ */
+ protected $templateMap = [
+ 'image' => 'media',
+ ];
+
+ /**
+ * Map input_validation and validation rule from js
+ *
+ * @var array
+ */
+ protected $inputValidationMap = [
+ 'alpha' => 'validate-alpha',
+ 'numeric' => 'validate-number',
+ 'alphanumeric' => 'validate-alphanum',
+ 'url' => 'validate-url',
+ 'email' => 'email2',
+ ];
+
/**
* @var AddressHelper
*/
@@ -102,16 +137,22 @@ protected function getFieldConfig(
$dataScopePrefix
) {
// street attribute is unique in terms of configuration, so it has its own configuration builder
- if ($attributeCode == 'street') {
- return $this->getStreetFieldConfig($attributeCode, $attributeConfig, $providerName, $dataScopePrefix);
+ if (isset($attributeConfig['validation']['input_validation'])) {
+ $validationRule = $attributeConfig['validation']['input_validation'];
+ $attributeConfig['validation'][$this->inputValidationMap[$validationRule]] = true;
+ unset($attributeConfig['validation']['input_validation']);
}
- $uiComponent = $attributeConfig['formElement'] == 'select'
- ? 'Magento_Ui/js/form/element/select'
+ if ($attributeConfig['formElement'] == 'multiline') {
+ return $this->getMultilineFieldConfig($attributeCode, $attributeConfig, $providerName, $dataScopePrefix);
+ }
+
+ $uiComponent = isset($this->formElementMap[$attributeConfig['formElement']])
+ ? $this->formElementMap[$attributeConfig['formElement']]
: 'Magento_Ui/js/form/element/abstract';
- $elementTemplate = $attributeConfig['formElement'] == 'select'
- ? 'ui/form/element/select'
- : 'ui/form/element/input';
+ $elementTemplate = isset($this->templateMap[$attributeConfig['formElement']])
+ ? 'ui/form/element/' . $this->templateMap[$attributeConfig['formElement']]
+ : 'ui/form/element/' . $attributeConfig['formElement'];
$element = [
'component' => isset($additionalConfig['component']) ? $additionalConfig['component'] : $uiComponent,
@@ -195,12 +236,13 @@ protected function isFieldVisible($attributeCode, array $attributeConfig, array
* @param string $dataScopePrefix
* @return array
*/
- protected function getStreetFieldConfig($attributeCode, array $attributeConfig, $providerName, $dataScopePrefix)
+ protected function getMultilineFieldConfig($attributeCode, array $attributeConfig, $providerName, $dataScopePrefix)
{
- $streetLines = [];
- for ($lineIndex = 0; $lineIndex < $this->addressHelper->getStreetLines(); $lineIndex++) {
+ $lines = [];
+ unset($attributeConfig['validation']['required-entry']);
+ for ($lineIndex = 0; $lineIndex < (int)$attributeConfig['size']; $lineIndex++) {
$isFirstLine = $lineIndex === 0;
- $streetLines[] = [
+ $lines[] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
// customScope is used to group elements within a single form e.g. they can be validated separately
@@ -210,23 +252,28 @@ protected function getStreetFieldConfig($attributeCode, array $attributeConfig,
],
'dataScope' => $lineIndex,
'provider' => $providerName,
- 'validation' => $isFirstLine ? ['required-entry' => true] : [],
+ 'validation' => $isFirstLine
+ ? array_merge(
+ ['required-entry' => (bool)$attributeConfig['required']],
+ $attributeConfig['validation']
+ )
+ : $attributeConfig['validation'],
'additionalClasses' => $isFirstLine ? : 'additional'
];
}
return [
'component' => 'Magento_Ui/js/form/components/group',
- 'label' => __('Address'),
- 'required' => true,
+ 'label' => $attributeConfig['label'],
+ 'required' => (bool)$attributeConfig['required'],
'dataScope' => $dataScopePrefix . '.' . $attributeCode,
'provider' => $providerName,
'sortOrder' => $attributeConfig['sortOrder'],
'type' => 'group',
'config' => [
'template' => 'ui/group/group',
- 'additionalClasses' => 'street'
+ 'additionalClasses' => $attributeCode
],
- 'children' => $streetLines,
+ 'children' => $lines,
];
}
diff --git a/app/code/Magento/Checkout/view/frontend/web/template/registration.html b/app/code/Magento/Checkout/view/frontend/web/template/registration.html
index c24d5c3e639c2..1ad2006f0a1e2 100644
--- a/app/code/Magento/Checkout/view/frontend/web/template/registration.html
+++ b/app/code/Magento/Checkout/view/frontend/web/template/registration.html
@@ -13,6 +13,6 @@
-
+
diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Group.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Group.php
deleted file mode 100644
index c4a30f1c6e921..0000000000000
--- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Group.php
+++ /dev/null
@@ -1,115 +0,0 @@
-_coreRegistry = $registry;
- $this->_addressHelper = $customerAddress;
- parent::__construct($context, $data);
- }
-
- /**
- * Retrieve disable auto group change element HTML ID
- *
- * @return string
- */
- protected function _getDisableAutoGroupChangeElementHtmlId()
- {
- return $this->getDisableAutoGroupChangeAttribute()->getAttributeCode();
- }
-
- /**
- * Retrieve disable auto group change checkbox label text
- *
- * @return \Magento\Framework\Phrase
- */
- public function getDisableAutoGroupChangeCheckboxLabel()
- {
- return __($this->getDisableAutoGroupChangeAttribute()->getFrontendLabel());
- }
-
- /**
- * Retrieve disable auto group change checkbox state
- *
- * @return string
- */
- public function getDisableAutoGroupChangeCheckboxState()
- {
- $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
- $checkedByDefault = $customerId ? false : $this->_addressHelper->isDisableAutoGroupAssignDefaultValue();
-
- $value = $this->getDisableAutoGroupChangeAttributeValue();
- $state = '';
- if (!empty($value) || $checkedByDefault) {
- $state = 'checked';
- }
- return $state;
- }
-
- /**
- * Retrieve disable auto group change checkbox element HTML NAME
- *
- * @return string
- */
- public function getDisableAutoGroupChangeCheckboxElementName()
- {
- return $this->getElement()->getForm()->getFieldNameSuffix() .
- '[' .
- $this->_getDisableAutoGroupChangeElementHtmlId() .
- ']';
- }
-
- /**
- * Retrieve disable auto group change checkbox element HTML ID
- *
- * @return string
- */
- public function getDisableAutoGroupChangeCheckboxElementId()
- {
- return $this->_getDisableAutoGroupChangeElementHtmlId();
- }
-}
diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php
deleted file mode 100644
index 6ab83f2f7d5a7..0000000000000
--- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php
+++ /dev/null
@@ -1,55 +0,0 @@
-_storeManager = $context->getStoreManager();
- parent::__construct($context, $data);
- }
-
- /**
- * Check if Single Store Mode is enabled
- *
- * @return bool
- */
- public function isSingleStoreMode()
- {
- return $this->_storeManager->isSingleStoreMode();
- }
-
- /**
- * Get form HTML ID
- * @return string
- */
- public function getFormHtmlId()
- {
- return $this->getForm()->getHtmlIdPrefix();
- }
-}
diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Newpass.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Newpass.php
deleted file mode 100644
index 14fba87d23f45..0000000000000
--- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Newpass.php
+++ /dev/null
@@ -1,46 +0,0 @@
-
- */
-class Newpass extends AbstractBlock implements RendererInterface
-{
- /**
- * @param AbstractElement $element
- * @return string
- */
- public function render(AbstractElement $element)
- {
- $html = '';
- $html .= $element->getLabelHtml();
- $html .= '
' . $element->getElementHtml();
- $html .= '
';
- $html .= '
';
- $html .= '';
- $html .= '';
- $html .= '';
- $html .= '
' . "\n";
- $html .= '
' . "\n";
- $html .= '
' . "\n";
- $html .= '
' . "\n";
-
- return $html;
- }
-}
diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php
deleted file mode 100644
index 5eba041c1d53a..0000000000000
--- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php
+++ /dev/null
@@ -1,416 +0,0 @@
-options = $options;
- $this->_jsonEncoder = $jsonEncoder;
- $this->_systemStore = $systemStore;
- $this->_customerFormFactory = $customerFormFactory;
- $this->_accountManagement = $accountManagement;
- $this->_customerMetadata = $customerMetadata;
- $this->customerDataFactory = $customerDataFactory;
- $this->_extensibleDataObjectConverter = $extensibleDataObjectConverter;
- $this->dataObjectHelper = $dataObjectHelper;
- parent::__construct($context, $registry, $formFactory, $dataObjectProcessor, $data);
- }
-
- /**
- * Initialize form
- *
- * @return $this
- *
- * @SuppressWarnings(PHPMD.NPathComplexity)
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public function initForm()
- {
- /** @var \Magento\Framework\Data\Form $form */
- $form = $this->_formFactory->create();
- $form->setHtmlIdPrefix('_account');
- $form->setFieldNameSuffix('account');
-
- /** @var \Magento\Framework\Data\Form\Element\Fieldset $fieldset */
- $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Account Information')]);
- $accountData = $this->_customizeFieldset($fieldset);
-
- $form->setValues($accountData);
- $this->setForm($form);
- return $this;
- }
-
- /**
- * Customize fieldset elements
- *
- * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
- * @return array
- */
- protected function _customizeFieldset($fieldset)
- {
- $attributes = $this->_initCustomerAttributes();
- $this->_setFieldset($attributes, $fieldset, [self::DISABLE_ATTRIBUTE_NAME]);
- $form = $fieldset->getForm();
- $groupElement = $form->getElement(
- 'group_id'
- );
- $groupElement->setRenderer(
- $this->getLayout()->createBlock(
- 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Group'
- )->setDisableAutoGroupChangeAttribute(
- $this->_getCustomerForm()->getAttribute(self::DISABLE_ATTRIBUTE_NAME)
- )->setDisableAutoGroupChangeAttributeValue(
- $this->_getCustomerDataObject()->getCustomAttribute(self::DISABLE_ATTRIBUTE_NAME) ?
- $this->_getCustomerDataObject()->getCustomAttribute(self::DISABLE_ATTRIBUTE_NAME)->getValue() : null
- )
- );
-
- $this->_checkElementType('prefix', $fieldset);
- $this->_checkElementType('suffix', $fieldset);
-
- $fieldset->getForm()->getElement('website_id')->addClass('validate-website-has-store');
- $renderer = $this->getLayout()->createBlock(
- 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
- );
- $form->getElement('website_id')->setRenderer($renderer);
-
- $accountData = $this->_extensibleDataObjectConverter->toFlatArray(
- $this->_getCustomerDataObject(),
- [],
- '\Magento\Customer\Api\Data\CustomerInterface'
- );
-
- if ($this->_getCustomerDataObject()->getId()) {
- $customerFormFields = $this->_addEditCustomerFormFields($fieldset);
- } else {
- $customerFormFields = $this->_addNewCustomerFormFields($fieldset);
- }
-
- $this->_handleReadOnlyCustomer($form, $this->_getCustomerDataObject()->getId(), $attributes);
-
- return array_merge($customerFormFields, $accountData);
- }
-
- /**
- * Check if type of Prefix and Suffix elements should be changed from text to select and change it if need.
- *
- * @param string $elementName
- * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
- * @return null
- */
- protected function _checkElementType($elementName, $fieldset)
- {
- $possibleElements = ['prefix', 'suffix'];
- if (!in_array($elementName, $possibleElements)) {
- return;
- }
- $element = $fieldset->getForm()->getElement($elementName);
- if ($element) {
- if ($elementName == 'prefix') {
- $options = $this->options->getNamePrefixOptions($this->_getCustomerDataObject()->getStoreId());
- $prevSibling = $fieldset->getForm()->getElement('group_id')->getId();
- }
- if ($elementName == 'suffix') {
- $options = $this->options->getNameSuffixOptions($this->_getCustomerDataObject()->getStoreId());
- $prevSibling = $fieldset->getForm()->getElement('lastname')->getId();
- }
-
- if (!empty($options)) {
- $fieldset->removeField($element->getId());
- $elementField = $fieldset->addField(
- $element->getId(),
- 'select',
- $element->getData(),
- $prevSibling
- );
- $elementField->setValues($options);
- }
- }
- }
-
- /**
- * Obtain customer data from session and create customer object
- *
- * @return \Magento\Customer\Api\Data\CustomerInterface
- */
- protected function _getCustomerDataObject()
- {
- if ($this->_customerDataObject === null) {
- $customerData = $this->_backendSession->getCustomerData();
- $accountData = isset($customerData['account']) ? $customerData['account'] : [];
- $this->_customerDataObject = $this->customerDataFactory->create();
- $this->dataObjectHelper->populateWithArray(
- $this->_customerDataObject,
- $accountData,
- '\Magento\Customer\Api\Data\CustomerInterface'
- );
- }
- return $this->_customerDataObject;
- }
-
- /**
- * Return predefined additional element types
- *
- * @return array
- */
- protected function _getAdditionalElementTypes()
- {
- return [
- 'file' => 'Magento\Customer\Block\Adminhtml\Form\Element\File',
- 'image' => 'Magento\Customer\Block\Adminhtml\Form\Element\Image',
- 'boolean' => 'Magento\Customer\Block\Adminhtml\Form\Element\Boolean'
- ];
- }
-
- /**
- * Initialize attribute set.
- *
- * @return AttributeMetadataInterface[]
- */
- protected function _initCustomerAttributes()
- {
- $attributes = $this->_getCustomerForm()->getAttributes();
- foreach ($attributes as $key => $attribute) {
- if ($attribute->getAttributeCode() == 'created_at') {
- unset($attributes[$key]);
- }
- }
- return $attributes;
- }
-
- /**
- * Initialize customer form
- *
- * @return \Magento\Customer\Model\Metadata\Form $customerForm
- */
- protected function _getCustomerForm()
- {
- if ($this->_customerForm === null) {
- $this->_customerForm = $this->_customerFormFactory->create(
- 'customer',
- 'adminhtml_customer',
- $this->_extensibleDataObjectConverter->toFlatArray($this->_getCustomerDataObject())
- );
- }
- return $this->_customerForm;
- }
-
- /**
- * Handle Read-Only customer
- *
- * @param \Magento\Framework\Data\Form $form
- * @param int $customerId
- * @param AttributeMetadataInterface[] $attributes
- * @return void
- */
- protected function _handleReadOnlyCustomer($form, $customerId, $attributes)
- {
- if ($customerId && $this->_accountManagement->isReadonly($customerId)) {
- foreach ($attributes as $attribute) {
- $element = $form->getElement($attribute->getAttributeCode());
- if ($element) {
- $element->setReadonly(true, true);
- }
- }
- }
- }
-
- /**
- * Create New Customer form fields
- *
- * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
- * @return array
- */
- protected function _addNewCustomerFormFields($fieldset)
- {
- $fieldset->removeField('created_in');
-
- // Prepare send welcome email checkbox
- $fieldset->addField(
- 'sendemail',
- 'checkbox',
- ['label' => __('Send Welcome Email'), 'name' => 'sendemail', 'id' => 'sendemail']
- );
- $renderer = $this->getLayout()->createBlock(
- 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail'
- );
- $renderer->setForm($fieldset->getForm());
- $fieldset->getForm()->getElement('sendemail')->setRenderer($renderer);
-
- if (!$this->_storeManager->isSingleStoreMode()) {
- $fieldset->addField(
- 'sendemail_store_id',
- 'select',
- [
- 'label' => __('Send From'),
- 'name' => 'sendemail_store_id',
- 'values' => $this->_systemStore->getStoreValuesForForm()
- ]
- );
- }
-
- return ['sendemail' => '1'];
- }
-
- /**
- * 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->_accountManagement->isReadonly($customerData->getId())) {
- return [];
- }
-
- // Prepare customer confirmation control (only for existing customers)
- $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customerData->getId());
- $confirmationKey = $customerData->getConfirmation();
- if ($confirmationStatus != AccountManagementInterface::ACCOUNT_CONFIRMED) {
- $confirmationAttr = $this->_customerMetadata->getAttributeMetadata('confirmation');
- if (!$confirmationKey) {
- $confirmationKey = $this->_getRandomConfirmationKey();
- }
-
- $element = $fieldset->addField(
- 'confirmation',
- 'select',
- ['name' => 'confirmation', 'label' => __($confirmationAttr->getFrontendLabel())]
- );
- $element->setEntityAttribute($confirmationAttr);
- $element->setValues(['' => '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',
- ['name' => 'sendemail', 'label' => __('Send Welcome Email after Confirmation')]
- );
- return ['sendemail' => '1'];
- }
- }
- return [];
- }
-
- /**
- * Called when account needs confirmation and does not have a confirmation key.
- *
- * @return string confirmation key
- */
- protected function _getRandomConfirmationKey()
- {
- return md5(uniqid());
- }
-}
diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Addresses.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Addresses.php
deleted file mode 100644
index d44d33db5673d..0000000000000
--- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Addresses.php
+++ /dev/null
@@ -1,511 +0,0 @@
-options = $options;
- $this->_addressHelper = $addressHelper;
- $this->_jsonEncoder = $jsonEncoder;
- $this->_regionFactory = $regionFactory;
- $this->_metadataFormFactory = $metadataFormFactory;
- $this->_systemStore = $systemStore;
- $this->_customerAccountManagement = $customerAccountManagement;
- $this->_addressMetadataService = $addressMetadataService;
- $this->addressDataFactory = $addressDataFactory;
- $this->customerDataFactory = $customerInterfaceFactory;
- $this->_directoryHelper = $directoryHelper;
- $this->addressMapper = $addressMapper;
- $this->dataObjectHelper = $dataObjectHelper;
- parent::__construct($context, $registry, $formFactory, $dataObjectProcessor, $data);
- }
-
- /**
- * @return string
- */
- public function getRegionsUrl()
- {
- return $this->getUrl('directory/json/countryRegion');
- }
-
- /**
- * @return $this
- */
- protected function _prepareLayout()
- {
- $this->addChild(
- 'delete_button',
- 'Magento\Backend\Block\Widget\Button',
- [
- 'label' => __('Delete Address'),
- 'name' => 'delete_address',
- 'element_name' => 'delete_address',
- 'disabled' => $this->isReadonly(),
- 'class' => 'delete' . ($this->isReadonly() ? ' disabled' : '')
- ]
- );
- $this->addChild(
- 'add_address_button',
- 'Magento\Backend\Block\Widget\Button',
- [
- 'label' => __('Add New Address'),
- 'id' => 'add_address_button',
- 'name' => 'add_address_button',
- 'element_name' => 'add_address_button',
- 'disabled' => $this->isReadonly(),
- 'class' => 'add' . ($this->isReadonly() ? ' disabled' : ''),
- 'data_attribute' => ['ui-id' => 'adminhtml-edit-tab-addresses-add-address-button']
- ]
- );
- $this->addChild(
- 'cancel_button',
- 'Magento\Backend\Block\Widget\Button',
- [
- 'label' => __('Cancel'),
- 'id' => 'cancel_add_address' . $this->getTemplatePrefix(),
- 'name' => 'cancel_address',
- 'element_name' => 'cancel_address',
- 'class' => 'cancel delete-address' . ($this->isReadonly() ? ' disabled' : ''),
- 'disabled' => $this->isReadonly()
- ]
- );
- return parent::_prepareLayout();
- }
-
- /**
- * Check block is readonly.
- *
- * @return bool
- */
- public function isReadonly()
- {
- $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
-
- if (empty($customerId)) {
- return false;
- }
-
- try {
- return $this->_customerAccountManagement->isReadonly($customerId);
- } catch (NoSuchEntityException $e) {
- return false;
- }
- }
-
- /**
- * @return string
- */
- public function getDeleteButtonHtml()
- {
- return $this->getChildHtml('delete_button');
- }
-
- /**
- * Initialize form object
- *
- * @return $this
- *
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function initForm()
- {
- $customerData = $this->_backendSession->getCustomerData();
-
- /** @var \Magento\Framework\Data\Form $form */
- $form = $this->_formFactory->create();
- $fieldset = $form->addFieldset('address_fieldset', ['legend' => __("Edit Customer's Address")]);
-
- $account = $customerData['account'];
- $address = $this->addressDataFactory->create();
- if (!empty($account) && isset($account['store_id'])) {
- $address->setCountryId(
- $this->_directoryHelper->getDefaultCountry($this->_storeManager->getStore($account['store_id']))
- );
- } else {
- $address->setCountryId($this->_directoryHelper->getDefaultCountry());
- }
-
- $addressForm = $this->_metadataFormFactory->create(
- 'customer_address',
- 'adminhtml_customer_address',
- $this->addressMapper->toFlatArray($address)
- );
-
- $attributes = $addressForm->getAttributes();
- if (isset($attributes['street'])) {
- if ($attributes['street']->getMultilineCount() <= 0) {
- $attributes['street']->setMultilineCount(self::DEFAULT_STREET_LINES_COUNT);
- }
- }
- foreach ($attributes as $key => $attribute) {
- $attributes[$key]->setFrontendLabel(__($attribute->getFrontendLabel()))
- ->setIsVisible(false);
- }
- $this->_setFieldset($attributes, $fieldset);
-
- $regionElement = $form->getElement('region');
-
- if ($regionElement) {
- $regionElement->setRenderer($this->_regionFactory->create());
- }
-
- $regionElement = $form->getElement('region_id');
- if ($regionElement) {
- $regionElement->setNoDisplay(true);
- }
-
- $country = $form->getElement('country_id');
- if ($country) {
- $country->addClass('countries');
- }
-
- $postcode = $form->getElement('postcode');
- if ($postcode) {
- $postcode->removeClass('required-entry')
- ->setRequired(!$this->_directoryHelper->isZipCodeOptional($address->getCountryId()));
- }
-
- if ($this->isReadonly()) {
- foreach ($this->_addressMetadataService->getAllAttributesMetadata() as $attribute) {
- $element = $form->getElement($attribute->getAttributeCode());
- if ($element) {
- $element->setReadonly(true, true);
- }
- }
- }
-
- $customerStoreId = null;
- if (!empty($account) && isset($account['id']) && isset($account['website_id'])) {
- $customerStoreId = $this->_storeManager->getWebsite($account['website_id'])->getDefaultStore()->getId();
- }
-
- $prefixElement = $form->getElement('prefix');
- if ($prefixElement) {
- $prefixOptions = $this->options->getNamePrefixOptions($customerStoreId);
- if (!empty($prefixOptions)) {
- $fieldset->removeField($prefixElement->getId());
- $prefixField = $fieldset->addField($prefixElement->getId(), 'select', $prefixElement->getData(), '^');
- $prefixField->setValues($prefixOptions);
- }
- }
-
- $suffixElement = $form->getElement('suffix');
- if ($suffixElement) {
- $suffixOptions = $this->options->getNameSuffixOptions($customerStoreId);
- if (!empty($suffixOptions)) {
- $fieldset->removeField($suffixElement->getId());
- $suffixField = $fieldset->addField(
- $suffixElement->getId(),
- 'select',
- $suffixElement->getData(),
- $form->getElement('lastname')->getId()
- );
- $suffixField->setValues($suffixOptions);
- }
- }
-
- $customerDataObject = $this->customerDataFactory->create();
- $this->dataObjectHelper->populateWithArray(
- $customerDataObject,
- $account,
- '\Magento\Customer\Api\Data\CustomerInterface'
- );
- $this->assign('customer', $customerDataObject);
- $addressCollection = [];
- foreach ($customerData['address'] as $key => $addressData) {
- $addressDataObject = $this->addressDataFactory->create();
- $this->dataObjectHelper->populateWithArray(
- $addressDataObject,
- $addressData,
- '\Magento\Customer\Api\Data\AddressInterface'
- );
- $addressCollection[$key] = $addressDataObject;
- }
- $this->assign('addressCollection', $addressCollection);
- $form->setValues($this->addressMapper->toFlatArray($address));
- $this->setForm($form);
-
- return $this;
- }
-
- /**
- * @param AddressInterface $address
- * @return $this
- */
- public function initAddressForm(AddressInterface $address)
- {
- $form = $this->initForm()->getForm();
-
- $postcode = $form->getElement('postcode');
- if ($postcode) {
- $postcode->removeClass('required-entry')
- ->setRequired(!$this->_directoryHelper->isZipCodeOptional($address->getCountryId()));
- }
-
- $form->addValues($this->addressMapper->toFlatArray($address))
- ->setHtmlIdPrefix("_item{$address->getId()}")
- ->setFieldNameSuffix('address[' . $address->getId() . ']');
-
- $this->addValuesToNamePrefixElement($address->getPrefix())
- ->addValuesToNameSuffixElement($address->getSuffix());
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getCancelButtonHtml()
- {
- return $this->getChildHtml('cancel_button');
- }
-
- /**
- * @return string
- */
- public function getAddNewButtonHtml()
- {
- return $this->getChildHtml('add_address_button');
- }
-
- /**
- * Return predefined additional element types
- *
- * @return array
- */
- protected function _getAdditionalElementTypes()
- {
- return [
- 'file' => 'Magento\Customer\Block\Adminhtml\Form\Element\File',
- 'image' => 'Magento\Customer\Block\Adminhtml\Form\Element\Image',
- 'boolean' => 'Magento\Customer\Block\Adminhtml\Form\Element\Boolean'
- ];
- }
-
- /**
- * Add specified values to name prefix element values
- *
- * @param string|int|array $values
- * @return $this
- */
- public function addValuesToNamePrefixElement($values)
- {
- if ($this->getForm() && $this->getForm()->getElement('prefix')) {
- $this->getForm()->getElement('prefix')->addElementValues($values);
- }
- return $this;
- }
-
- /**
- * Add specified values to name suffix element values
- *
- * @param string|int|array $values
- * @return $this
- */
- public function addValuesToNameSuffixElement($values)
- {
- if ($this->getForm() && $this->getForm()->getElement('suffix')) {
- $this->getForm()->getElement('suffix')->addElementValues($values);
- }
- return $this;
- }
-
- /**
- * Returns the template prefix
- *
- * @return string
- */
- public function getTemplatePrefix()
- {
- return '_template_';
- }
-
- /**
- * Return array with countries associated to possible websites
- *
- * @return array
- */
- public function getDefaultCountries()
- {
- $websites = $this->_systemStore->getWebsiteValuesForForm(false, true);
- $result = [];
- foreach ($websites as $website) {
- $result[$website['value']] = $this->_storeManager->getWebsite(
- $website['value']
- )->getConfig(
- \Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY
- );
- }
-
- return $result;
- }
-
- /**
- * Return ISO2 country codes, which have optional Zip/Postal pre-configured
- *
- * @return array|string
- */
- public function getOptionalZipCountries()
- {
- return $this->_directoryHelper->getCountriesWithOptionalZip();
- }
-
- /**
- * Returns the list of countries, for which region is required
- *
- * @return array
- */
- public function getRequiredStateForCountries()
- {
- return $this->_directoryHelper->getCountriesWithStatesRequired();
- }
-
- /**
- * Return, whether non-required state should be shown
- *
- * @return int 1 if should be shown, and 0 if not.
- */
- public function getShowAllRegions()
- {
- return (string)$this->_directoryHelper->isShowNonRequiredState() ? 1 : 0;
- }
-
- /**
- * Encode the $data into JSON format.
- *
- * @param object|array $data
- * @return string
- */
- public function jsonEncode($data)
- {
- return $this->_jsonEncoder->encode($data);
- }
-
- /**
- * Format the given address to the given type
- *
- * @param AddressInterface $address
- * @param string $type
- * @return string
- */
- public function format(AddressInterface $address, $type)
- {
- return $this->_addressHelper->getFormatTypeRenderer(
- $type
- )->renderArray(
- $this->addressMapper->toFlatArray($address)
- );
- }
-}
diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
index ca03623385b96..8cc817d34b0de 100644
--- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
+++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
@@ -32,7 +32,6 @@ protected function _extractCustomerData()
CustomerInterface::DEFAULT_BILLING,
CustomerInterface::DEFAULT_SHIPPING,
'confirmation',
- 'sendemail',
];
$customerData = $this->_extractData(
diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php
index aa5a30ea4c53b..6354c18f2f73c 100644
--- a/app/code/Magento/Customer/Model/AccountManagement.php
+++ b/app/code/Magento/Customer/Model/AccountManagement.php
@@ -57,6 +57,8 @@ class AccountManagement implements AccountManagementInterface
*/
const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template';
+ const XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE = 'customer/create_account/email_no_password_template';
+
const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity';
const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template';
@@ -76,9 +78,15 @@ class AccountManagement implements AccountManagementInterface
// Constants for the type of new account email to be sent
const NEW_ACCOUNT_EMAIL_REGISTERED = 'registered';
+ // welcome email, when password setting is required
+ const NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD = 'registered_no_password';
+
// welcome email, when confirmation is enabled
const NEW_ACCOUNT_EMAIL_CONFIRMATION = 'confirmation';
+ // confirmation email, when account is confirmed
+ const NEW_ACCOUNT_EMAIL_CONFIRMED = 'confirmed';
+
/**
* Constants for types of emails to send out.
* pdl:
@@ -470,10 +478,10 @@ public function createAccount(
) {
if (!is_null($password)) {
$this->checkPasswordStrength($password);
+ $hash = $this->createPasswordHash($password);
} else {
- $password = $this->mathRandom->getRandomString(self::MIN_PASSWORD_LENGTH);
+ $hash = null;
}
- $hash = $this->createPasswordHash($password);
return $this->createAccountWithPasswordHash($customer, $hash, $redirectUrl);
}
@@ -566,21 +574,14 @@ public function getDefaultShippingAddress($customerId)
protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl)
{
try {
- if ($this->isConfirmationRequired($customer)) {
- $this->sendNewAccountEmail(
- $customer,
- self::NEW_ACCOUNT_EMAIL_CONFIRMATION,
- $redirectUrl,
- $customer->getStoreId()
- );
- } else {
- $this->sendNewAccountEmail(
- $customer,
- self::NEW_ACCOUNT_EMAIL_REGISTERED,
- $redirectUrl,
- $customer->getStoreId()
- );
+ $hash = $this->customerRegistry->retrieveSecureData($customer->getId())->getPasswordHash();
+ $templateType = self::NEW_ACCOUNT_EMAIL_REGISTERED;
+ if ($this->isConfirmationRequired($customer) && $hash != '') {
+ $templateType = self::NEW_ACCOUNT_EMAIL_CONFIRMATION;
+ } elseif ($hash == '') {
+ $templateType = self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD;
}
+ $this->sendNewAccountEmail($customer, $templateType, $redirectUrl, $customer->getStoreId());
} catch (MailException $e) {
// If we are not able to send a new account email, this should be ignored
$this->logger->critical($e);
@@ -806,7 +807,7 @@ public function isReadonly($customerId)
*/
protected function sendNewAccountEmail(
$customer,
- $type = 'registered',
+ $type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
$backUrl = '',
$storeId = '0',
$sendemailStoreId = null
@@ -901,14 +902,19 @@ protected function getWebsiteStoreId($customer, $defaultStoreId = null)
protected function getTemplateTypes()
{
/**
- * 'registered' welcome email, when confirmation is disabled
- * 'confirmed' welcome email, when confirmation is enabled
- * 'confirmation' email with confirmation link
+ * self::NEW_ACCOUNT_EMAIL_REGISTERED welcome email, when confirmation is disabled
+ * and password is set
+ * self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD welcome email, when confirmation is disabled
+ * and password is not set
+ * self::NEW_ACCOUNT_EMAIL_CONFIRMED welcome email, when confirmation is enabled
+ * and password is set
+ * self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link
*/
$types = [
- 'registered' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,
- 'confirmed' => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE,
- 'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
+ self::NEW_ACCOUNT_EMAIL_REGISTERED => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,
+ self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE,
+ self::NEW_ACCOUNT_EMAIL_CONFIRMED => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE,
+ self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
];
return $types;
}
diff --git a/app/code/Magento/Customer/Model/Customer/Attribute/Source/Website.php b/app/code/Magento/Customer/Model/Customer/Attribute/Source/Website.php
index 7ffda2b40c678..c771c6a685297 100644
--- a/app/code/Magento/Customer/Model/Customer/Attribute/Source/Website.php
+++ b/app/code/Magento/Customer/Model/Customer/Attribute/Source/Website.php
@@ -37,7 +37,7 @@ public function __construct(
public function getAllOptions()
{
if (!$this->_options) {
- $this->_options = $this->_store->getWebsiteValuesForForm(false, true);
+ $this->_options = $this->_store->getWebsiteValuesForForm();
}
return $this->_options;
diff --git a/app/code/Magento/Customer/Model/Resource/Customer.php b/app/code/Magento/Customer/Model/Resource/Customer.php
index 7a793a489aca8..a640c6911b5ba 100644
--- a/app/code/Magento/Customer/Model/Resource/Customer.php
+++ b/app/code/Magento/Customer/Model/Resource/Customer.php
@@ -130,7 +130,7 @@ protected function _beforeSave(\Magento\Framework\Object $customer)
}
// set confirmation key logic
- if ($customer->getForceConfirmed()) {
+ if ($customer->getForceConfirmed() || $customer->getPasswordHash() == '') {
$customer->setConfirmation(null);
} elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
$customer->setConfirmation($customer->getRandomConfirmationKey());
diff --git a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php b/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php
deleted file mode 100644
index e4d52f94c3a6e..0000000000000
--- a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
-contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context')
- ->setMethods(['getStoreManager'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->objectManagerHelper = new ObjectManagerHelper($this);
- }
-
- public function testIsSingleStoreMode()
- {
- $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', ['isSingleStoreMode'], [], '', false);
- $storeManagerMock->expects($this->any())
- ->method('isSingleStoreMode')
- ->will($this->returnValue(true));
- $this->contextMock->expects($this->any())
- ->method('getStoreManager')
- ->will($this->returnValue($storeManagerMock));
-
- $this->block = $this->objectManagerHelper->getObject(
- 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail',
- [
- 'context' => $this->contextMock
- ]
- );
-
- $this->assertTrue($this->block->isSingleStoreMode());
- }
-
- public function testGetFormHtmlId()
- {
- $formMock = $this->getMock('Magento\Framework\Data\Form', ['getHtmlIdPrefix'], [], '', false);
- $formMock->expects($this->once())->method('getHtmlIdPrefix')->will($this->returnValue('account_form'));
- $this->block = $this->objectManagerHelper->getObject(
- 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail',
- [
- 'context' => $this->contextMock,
- 'data' => ['form' => $formMock]
- ]
- );
-
- $this->assertEquals('account_form', $this->block->getFormHtmlId());
- }
-}
diff --git a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/AccountTest.php b/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/AccountTest.php
deleted file mode 100644
index 118b7c5794e4c..0000000000000
--- a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/AccountTest.php
+++ /dev/null
@@ -1,258 +0,0 @@
-objectManagerHelper = new ObjectManagerHelper($this);
- $this->contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context')
- ->setMethods(
- ['getBackendSession', 'getLayout', 'getStoreManager', 'getUrlBuilder']
- )->disableOriginalConstructor()
- ->getMock();
- $this->registryMock = $this->getMock('Magento\Framework\Registry');
- $this->formFactoryMock = $this->getMock('Magento\Framework\Data\FormFactory', [], [], '', false);
- $this->encoderInterfaceMock = $this->getMock('Magento\Framework\Json\EncoderInterface');
- $this->customerFormFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory')
- ->disableOriginalConstructor()
- ->getMock();
- $this->storeMock = $this->getMock('Magento\Store\Model\System\Store', [], [], '', false);
- $this->options = $this->getMockBuilder('Magento\Customer\Model\Options')
- ->setMethods(['getNamePrefixOptions', 'getNameSuffixOptions'])
- ->disableOriginalConstructor()->getMock();
- $this->accountManagementMock = $this->getMock(
- 'Magento\Customer\Api\AccountManagementInterface'
- );
- $this->customerMetadataMock = $this->getMock(
- 'Magento\Customer\Api\CustomerMetadataInterface'
- );
- $this->customerFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterfaceFactory')
- ->setMethods(['create'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->dataObjectHelperMock = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper')
- ->disableOriginalConstructor()
- ->getMock();
- $this->extensibleDataObjectConverterMock = $this->getMockBuilder(
- 'Magento\Framework\Api\ExtensibleDataObjectConverter'
- )->setMethods(['toFlatArray'])->disableOriginalConstructor()->getMock();
- }
-
- /**
- * @param $customerData
- * @param $isSingleStoreMode
- * @param $canModifyCustomer
- *
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer)
- {
- $backendSessionMock = $this->getMock('\Magento\Backend\Model\Session', ['getCustomerData'], [], '', false);
- $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([]));
-
- $layoutMock = $this->getMock('\Magento\Framework\View\Layout\Element\Layout', ['createBlock'], [], '', false);
- $layoutMock->expects($this->at(0))->method('createBlock')
- ->with('Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Group')
- ->will($this->returnValue(
- $this->objectManagerHelper->getObject('Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Group')
- ));
- $layoutMock->expects($this->at(1))->method('createBlock')
- ->with('Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element')
- ->will($this->returnValue(
- $this->objectManagerHelper->getObject(
- 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
- )
- ));
- if (empty($customerData['id'])) {
- $layoutMock->expects($this->at(2))->method('createBlock')
- ->with('Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail')
- ->will($this->returnValue($this->objectManagerHelper->getObject(
- 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail'
- ))
- );
- }
-
- $urlBuilderMock = $this->getMock('\Magento\Backend\Model\Url', ['getBaseUrl'], [], '', false);
- $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl'));
-
- $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false);
- $storeManagerMock->expects($this->any())->method('isSingleStoreMode')
- ->will($this->returnValue($isSingleStoreMode));
-
- $customerObject = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface');
- if (!empty($customerData['id'])) {
- $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id']));
- }
-
- $fieldset = $this->getMockBuilder('\Magento\Framework\Data\Form\Element\Fieldset')
- ->setMethods(['getForm', 'addField', 'removeField'])
- ->disableOriginalConstructor()
- ->getMock();
- $accountForm = $this->getMockBuilder('Magento\Framework\Data\Form')
- ->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])
- ->disableOriginalConstructor()
- ->getMock();
-
- $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')
- ->will($this->returnValue($fieldset));
- $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm));
- $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm));
- $formElement = $this->getMockBuilder('\Magento\Framework\Data\Form\Element\Select')
- ->setMethods(['setRenderer', 'addClass', 'setDisabled'])
- ->disableOriginalConstructor()->getMock();
-
- $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null));
- $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null));
- $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null));
- $accountForm->expects($this->any())->method('getElement')->withAnyParameters()
- ->will($this->returnValue($formElement));
-
- $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement));
-
- $customerForm = $this->getMock('\Magento\Customer\Model\Metadata\Form', ['getAttributes'], [], '', false);
- $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([]));
-
- $this->contextMock->expects($this->any())->method('getBackendSession')
- ->will($this->returnValue($backendSessionMock));
- $this->contextMock->expects($this->any())->method('getLayout')
- ->will($this->returnValue($layoutMock));
- $this->contextMock->expects($this->any())->method('getUrlBuilder')
- ->will($this->returnValue($urlBuilderMock));
- $this->contextMock->expects($this->any())->method('getStoreManager')
- ->will($this->returnValue($storeManagerMock));
- $this->customerFactoryMock->expects($this->any())->method('create')
- ->will($this->returnValue($customerObject));
- $this->dataObjectHelperMock->expects($this->once())
- ->method('populateWithArray');
- $this->options->expects($this->any())->method('getNamePrefixOptions')
- ->will($this->returnValue(['Pref1', 'Pref2']));
- $this->options->expects($this->any())->method('getNameSuffixOptions')
- ->will($this->returnValue(['Suf1', 'Suf2']));
- $this->formFactoryMock->expects($this->any())->method('create')
- ->will($this->returnValue($accountForm));
- $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')
- ->will($this->returnValue($customerData));
- $this->customerFormFactoryMock
- ->expects($this->any())
- ->method('create')
- ->with(
- 'customer',
- 'adminhtml_customer',
- $this->extensibleDataObjectConverterMock->toFlatArray(
- $customerObject,
- [],
- '\Magento\Customer\Api\Data\CustomerInterface'
- )
- )
- ->will($this->returnValue($customerForm));
- $this->accountManagementMock->expects($this->any())->method('isReadOnly')->withAnyParameters()
- ->will($this->returnValue(!$canModifyCustomer));
- $this->accountManagementMock->expects($this->any())->method('getConfirmationStatus')
- ->withAnyParameters()
- ->will($this->returnValue(AccountManagementInterface::ACCOUNT_CONFIRMED));
- }
-
- /**
- * @dataProvider getInitFormData
- */
- public function testInitForm($customerData, $isSingleStoreMode, $canModifyCustomer)
- {
- $this->_setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer);
- $this->objectManagerHelper->getObject(
- 'Magento\Customer\Block\Adminhtml\Edit\Tab\Account',
- [
- 'context' => $this->contextMock,
- 'registry' => $this->registryMock,
- 'formFactory' => $this->formFactoryMock,
- 'jsonEncoder' => $this->encoderInterfaceMock,
- 'customerFormFactory' => $this->customerFormFactoryMock,
- 'systemStore' => $this->storeMock,
- 'options' => $this->options,
- 'accountManagement' => $this->accountManagementMock,
- 'customerMetadata' => $this->customerMetadataMock,
- 'customerDataFactory' => $this->customerFactoryMock,
- 'dataObjectHelper' => $this->dataObjectHelperMock,
- 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverterMock
- ]
- )->initForm();
- }
-
- /**
- * Data provider for method testInitForm
- * @return array
- */
- public function getInitFormData()
- {
- return [
- [[], true, true],
- [['id' => 1], true, true],
- [[], false, false],
- [
- [
- 'id' => 1,
- AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY => [
- [AttributeValue::ATTRIBUTE_CODE => 'test_attribute1', AttributeValue::VALUE => 'test_value1'],
- [AttributeValue::ATTRIBUTE_CODE => 'test_attribute2', AttributeValue::VALUE => 'test_value2'],
- ],
- ],
- false,
- false
- ],
- ];
- }
-}
diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php
index a8fe33e93c985..9309481017446 100644
--- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php
@@ -260,7 +260,6 @@ public function testExecuteWithExistentCustomerAndNoAddresses()
\Magento\Customer\Api\Data\CustomerInterface::DEFAULT_BILLING => false,
\Magento\Customer\Api\Data\CustomerInterface::DEFAULT_SHIPPING => false,
'confirmation' => false,
- 'sendemail' => false,
'id' => $customerId,
];
diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
index 1a7355c6a87ae..f55fb4fa0b0c0 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
@@ -480,18 +480,165 @@ public function testCreateAccountWithPasswordHashWithAddressException()
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- public function testCreateAccountWithPasswordHashWithoutException()
+ public function testCreateAccountWithoutPassword()
{
$websiteId = 1;
$storeId = null;
$defaultStoreId = 1;
$customerId = 1;
$customerEmail = 'email@email.com';
+ $newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
+ $templateIdentifier = 'Template Identifier';
+ $sender = 'Sender';
+
+ $address = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $address->expects($this->once())
+ ->method('setCustomerId')
+ ->with($customerId);
+ $store = $this->getMockBuilder('Magento\Store\Model\Store')->disableOriginalConstructor()->getMock();
+ $store->expects($this->once())
+ ->method('getId')
+ ->willReturn($defaultStoreId);
+ $website = $this->getMockBuilder('Magento\Store\Model\Website')->disableOriginalConstructor()->getMock();
+ $website->expects($this->atLeastOnce())
+ ->method('getStoreIds')
+ ->willReturn([1, 2, 3]);
+ $website->expects($this->once())
+ ->method('getDefaultStore')
+ ->willReturn($store);
+ $customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
+ $customer->expects($this->atLeastOnce())
+ ->method('getId')
+ ->willReturn($customerId);
+ $customer->expects($this->atLeastOnce())
+ ->method('getEmail')
+ ->willReturn($customerEmail);
+ $customer->expects($this->atLeastOnce())
+ ->method('getWebsiteId')
+ ->willReturn($websiteId);
+ $customer->expects($this->atLeastOnce())
+ ->method('getStoreId')
+ ->willReturn($storeId);
+ $customer->expects($this->once())
+ ->method('setStoreId')
+ ->with($defaultStoreId);
+ $customer->expects($this->once())
+ ->method('getAddresses')
+ ->willReturn([$address]);
+ $customer->expects($this->once())
+ ->method('setAddresses')
+ ->with(null);
+ $this->customerRepository
+ ->expects($this->once())
+ ->method('get')
+ ->with($customerEmail)
+ ->willReturn($customer);
+ $this->share->expects($this->once())
+ ->method('isWebsiteScope')
+ ->willReturn(true);
+ $this->storeManager->expects($this->atLeastOnce())
+ ->method('getWebsite')
+ ->with($websiteId)
+ ->willReturn($website);
+ $this->customerRepository->expects($this->atLeastOnce())
+ ->method('save')
+ ->willReturn($customer);
+ $this->addressRepository->expects($this->atLeastOnce())
+ ->method('save')
+ ->with($address);
+ $this->customerRepository->expects($this->once())
+ ->method('getById')
+ ->with($customerId)
+ ->willReturn($customer);
+ $this->random->expects($this->once())
+ ->method('getUniqueHash')
+ ->willReturn($newLinkToken);
+ $customerSecure = $this->getMockBuilder('Magento\Customer\Model\Data\CustomerSecure')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $customerSecure->expects($this->any())
+ ->method('setRpToken')
+ ->with($newLinkToken);
+ $customerSecure->expects($this->any())
+ ->method('setRpTokenCreatedAt');
+ $customerSecure->expects($this->any())
+ ->method('getPasswordHash')
+ ->willReturn(null);
+ $this->customerRegistry->expects($this->atLeastOnce())
+ ->method('retrieveSecureData')
+ ->willReturn($customerSecure);
+ $this->dataObjectProcessor->expects($this->once())
+ ->method('buildOutputDataArray')
+ ->willReturn([]);
+ $this->scopeConfig->expects($this->at(1))
+ ->method('getValue')
+ ->with(
+ AccountManagement::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE,
+ ScopeInterface::SCOPE_STORE,
+ $defaultStoreId
+ )
+ ->willReturn($templateIdentifier);
+ $this->scopeConfig->expects($this->at(2))
+ ->method('getValue')
+ ->willReturn($sender);
+ $transport = $this->getMockBuilder('Magento\Framework\Mail\TransportInterface')->getMock();
+ $this->transportBuilder->expects($this->once())
+ ->method('setTemplateIdentifier')
+ ->with($templateIdentifier)
+ ->willReturnSelf();
+ $this->transportBuilder->expects($this->once())
+ ->method('setTemplateOptions')
+ ->willReturnSelf();
+ $this->transportBuilder->expects($this->once())
+ ->method('setTemplateVars')
+ ->willReturnSelf();
+ $this->transportBuilder->expects($this->once())
+ ->method('setFrom')
+ ->with($sender)
+ ->willReturnSelf();
+ $this->transportBuilder->expects($this->once())
+ ->method('addTo')
+ ->willReturnSelf();
+ $this->transportBuilder->expects($this->once())
+ ->method('getTransport')
+ ->willReturn($transport);
+ $transport->expects($this->once())
+ ->method('sendMessage');
+
+ $this->accountManagement->createAccount($customer);
+ }
+
+ /**
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+ */
+ public function testCreateAccountWithPassword()
+ {
+ $websiteId = 1;
+ $storeId = null;
+ $defaultStoreId = 1;
+ $customerId = 1;
+ $customerEmail = 'email@email.com';
+ $password = 'wrfewqedf1';
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';
$newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
$templateIdentifier = 'Template Identifier';
$sender = 'Sender';
+ $this->string->expects($this->any())
+ ->method('strlen')
+ ->willReturnCallback(
+ function ($string) {
+ return strlen($string);
+ }
+ );
+
+ $this->encryptor->expects($this->once())
+ ->method('getHash')
+ ->with($password, true)
+ ->willReturn($hash);
+
$address = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface')
->disableOriginalConstructor()
->getMock();
@@ -557,6 +704,7 @@ public function testCreateAccountWithPasswordHashWithoutException()
->method('getUniqueHash')
->willReturn($newLinkToken);
$customerSecure = $this->getMockBuilder('Magento\Customer\Model\Data\CustomerSecure')
+ ->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])
->disableOriginalConstructor()
->getMock();
$customerSecure->expects($this->any())
@@ -564,6 +712,9 @@ public function testCreateAccountWithPasswordHashWithoutException()
->with($newLinkToken);
$customerSecure->expects($this->any())
->method('setRpTokenCreatedAt');
+ $customerSecure->expects($this->any())
+ ->method('getPasswordHash')
+ ->willReturn($hash);
$this->customerRegistry->expects($this->atLeastOnce())
->method('retrieveSecureData')
->willReturn($customerSecure);
@@ -572,6 +723,11 @@ public function testCreateAccountWithPasswordHashWithoutException()
->willReturn([]);
$this->scopeConfig->expects($this->at(1))
->method('getValue')
+ ->with(
+ AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE,
+ ScopeInterface::SCOPE_STORE,
+ $defaultStoreId
+ )
->willReturn($templateIdentifier);
$this->scopeConfig->expects($this->at(2))
->method('getValue')
@@ -600,7 +756,7 @@ public function testCreateAccountWithPasswordHashWithoutException()
$transport->expects($this->once())
->method('sendMessage');
- $this->accountManagement->createAccountWithPasswordHash($customer, $hash);
+ $this->accountManagement->createAccount($customer, $password);
}
/**
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Customer/Attribute/Source/WebsiteTest.php b/app/code/Magento/Customer/Test/Unit/Model/Customer/Attribute/Source/WebsiteTest.php
new file mode 100644
index 0000000000000..6cddec488a31b
--- /dev/null
+++ b/app/code/Magento/Customer/Test/Unit/Model/Customer/Attribute/Source/WebsiteTest.php
@@ -0,0 +1,93 @@
+collectionFactoryMock =
+ $this->getMockBuilder('Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->optionFactoryMock = $this->getMockBuilder('Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->storeMock = $this->getMockBuilder('Magento\Store\Model\System\Store')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->model = new Website(
+ $this->collectionFactoryMock,
+ $this->optionFactoryMock,
+ $this->storeMock
+ );
+ }
+
+ /**
+ * Mock website options
+ *
+ * @return array
+ */
+ protected function mockOptions()
+ {
+ $options = [
+ [
+ 'value' => 'value1',
+ 'label' => 'label1',
+ ],
+ [
+ 'value' => 'value2',
+ 'label' => 'label2',
+ ],
+ ];
+
+ $this->storeMock->expects($this->once())
+ ->method('getWebsiteValuesForForm')
+ ->with(false, false)
+ ->willReturn($options);
+
+ return $options;
+ }
+
+ public function testGetAllOptions()
+ {
+ $options = $this->mockOptions();
+
+ $this->assertEquals($options, $this->model->getAllOptions());
+ // Check the options are cached
+ $this->assertEquals($options, $this->model->getAllOptions());
+ }
+
+ public function testGetOptionText()
+ {
+ $this->mockOptions();
+
+ $this->assertEquals('label1', $this->model->getOptionText('value1'));
+ }
+
+ public function testGetOptionTextWithoutOption()
+ {
+ $this->mockOptions();
+
+ $this->assertEquals(false, $this->model->getOptionText('value'));
+ }
+}
diff --git a/app/code/Magento/Customer/etc/adminhtml/system.xml b/app/code/Magento/Customer/etc/adminhtml/system.xml
index df4a56940f5e0..6abb625e8d84e 100644
--- a/app/code/Magento/Customer/etc/adminhtml/system.xml
+++ b/app/code/Magento/Customer/etc/adminhtml/system.xml
@@ -94,6 +94,14 @@
Email template chosen based on theme fallback when "Default" option is selected.
Magento\Config\Model\Config\Source\Email\Template
+
+
+
+ Email template chosen based on theme fallback when "Default" option is selected.
+ ]]>
+ Magento\Config\Model\Config\Source\Email\Template
+
Magento\Config\Model\Config\Source\Email\Identity
diff --git a/app/code/Magento/Customer/etc/config.xml b/app/code/Magento/Customer/etc/config.xml
index 981e8734fd3d1..3439bca8ac8b6 100644
--- a/app/code/Magento/Customer/etc/config.xml
+++ b/app/code/Magento/Customer/etc/config.xml
@@ -18,6 +18,7 @@
example.com
general
customer_create_account_email_template
+ customer_create_account_email_no_password_template
customer_create_account_email_confirmation_template
customer_create_account_email_confirmed_template
0
diff --git a/app/code/Magento/Customer/etc/email_templates.xml b/app/code/Magento/Customer/etc/email_templates.xml
index 943137b85ac99..0fea9f1988dae 100644
--- a/app/code/Magento/Customer/etc/email_templates.xml
+++ b/app/code/Magento/Customer/etc/email_templates.xml
@@ -7,6 +7,7 @@
-->
+
diff --git a/app/code/Magento/Customer/view/adminhtml/layout/customer_index_grid_block.xml b/app/code/Magento/Customer/view/adminhtml/layout/customer_index_grid_block.xml
index 2deaefacb01aa..e24457a4d267f 100644
--- a/app/code/Magento/Customer/view/adminhtml/layout/customer_index_grid_block.xml
+++ b/app/code/Magento/Customer/view/adminhtml/layout/customer_index_grid_block.xml
@@ -138,7 +138,7 @@
col-store
col-store
options
-
+
website_id
diff --git a/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/group.phtml b/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/group.phtml
deleted file mode 100644
index e116490690393..0000000000000
--- a/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/group.phtml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-getElement();
-$_note = $_element->getNote();
-$_class = $_element->getFieldsetHtmlClass();?>
-
-getNoDisplay()): ?>
-
- getType() == 'hidden'): ?>
-
getElementHtml(); ?>
-
- getLabelHtml(); ?>
-
- getElementHtml(); ?>
- getDisableAutoGroupChangeAttribute()): ?>
-
-
-
getDisableAutoGroupChangeCheckboxState() == 'checked') :?> checked="checked" value="1" class="addbefore" />
-
-
-
" id="note_getId(); ?>">
-
-
-
-
-
-
-
-
diff --git a/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml b/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml
deleted file mode 100644
index 30115f19b40ef..0000000000000
--- a/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-getElement();
-?>
-
-
- getLabelHtml(); ?>
-
- getElementHtml(); ?>
-
-
-
-
diff --git a/app/code/Magento/Customer/view/adminhtml/templates/tab/addresses.phtml b/app/code/Magento/Customer/view/adminhtml/templates/tab/addresses.phtml
deleted file mode 100644
index a800f91781e3f..0000000000000
--- a/app/code/Magento/Customer/view/adminhtml/templates/tab/addresses.phtml
+++ /dev/null
@@ -1,162 +0,0 @@
-
-
-
-
-
-
diff --git a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml
index 8bf281411f8b1..a32b3dee3716b 100644
--- a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml
+++ b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml
@@ -245,26 +245,6 @@
-
-
- - Magento\Store\Model\System\Store
- -
-
- Send From
- - number
- - select
-
-
-
-
-
- -
-
- Welcome Email
- - Send a Welcome email
- - boolean
- - checkbox
-
-
-