Skip to content

Commit

Permalink
Admin Order - Email is Now Required - Magento 2.3 Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
solwininfotech committed Aug 16, 2019
1 parent 2ac0fe3 commit d78361e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/code/Magento/Customer/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<comment>To show VAT number on Storefront, set Show VAT Number on Storefront option to Yes.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="email_required_create_order" translate="label comment" type="select" sortOrder="58" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Email is required field for Admin order creation</label>
<comment>If set YES Email field will be required during Admin order creation for new Customer.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="email_domain" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Default Email Domain</label>
</field>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Customer/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<confirm>0</confirm>
<default_group>1</default_group>
<tax_calculation_address_type>billing</tax_calculation_address_type>
<email_required_create_order>0</email_required_create_order>
<email_domain>example.com</email_domain>
<email_identity>general</email_identity>
<email_template>customer_create_account_email_template</email_template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Account extends AbstractForm
*/
protected $_extensibleDataObjectConverter;

private const XML_PATH_EMAIL_REQUIRED_CREATE_ORDER = 'customer/create_account/email_required_create_order';

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
Expand Down Expand Up @@ -147,7 +149,7 @@ protected function _addAdditionalFormElementData(AbstractElement $element)
{
switch ($element->getId()) {
case 'email':
$element->setRequired(1);
$element->setRequired($this->isEmailRequiredCreateOrder());
$element->setClass('validate-email admin__control-text');
break;
}
Expand Down Expand Up @@ -204,4 +206,17 @@ private function extractValuesFromAttributes(array $attributes): array

return $formValues;
}

/**
* Retrieve email is required field for admin order creation
*
* @return bool
*/
private function isEmailRequiredCreateOrder()
{
return $this->_scopeConfig->getValue(
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}
28 changes: 26 additions & 2 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
*/
const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';

private const XML_PATH_EMAIL_REQUIRED_CREATE_ORDER = 'customer/create_account/email_required_create_order';
/**
* Quote session object
*
Expand Down Expand Up @@ -1369,7 +1370,7 @@ protected function _setQuoteAddress(\Magento\Quote\Model\Quote\Address $address,
$data = isset($data['region']) && is_array($data['region']) ? array_merge($data, $data['region']) : $data;

$addressForm = $this->_metadataFormFactory->create(

AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
'adminhtml_customer_address',
$data,
Expand Down Expand Up @@ -2037,7 +2038,30 @@ protected function _validate()
*/
protected function _getNewCustomerEmail()
{
return $this->getData('account/email');
$emailrequired = $this->_scopeConfig->getValue(
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

if($emailrequired) {
return $this->getData('account/email');
} else {
$email = $this->getData('account/email');
if (empty($email)) {
$host = $this->_scopeConfig->getValue(
self::XML_PATH_DEFAULT_EMAIL_DOMAIN,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$account = time();
$email = $account . '@' . $host;
$account = $this->getData('account');
$account['email'] = $email;
$this->setData('account', $account);
}

return $email;
}

}

/**
Expand Down

0 comments on commit d78361e

Please sign in to comment.