Skip to content

Commit d78361e

Browse files
author
solwininfotech
committed
Admin Order - Email is Now Required - Magento 2.3 Updated
1 parent 2ac0fe3 commit d78361e

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

app/code/Magento/Customer/etc/adminhtml/system.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<comment>To show VAT number on Storefront, set Show VAT Number on Storefront option to Yes.</comment>
8787
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
8888
</field>
89+
<field id="email_required_create_order" translate="label comment" type="select" sortOrder="58" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
90+
<label>Email is required field for Admin order creation</label>
91+
<comment>If set YES Email field will be required during Admin order creation for new Customer.</comment>
92+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
93+
</field>
8994
<field id="email_domain" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
9095
<label>Default Email Domain</label>
9196
</field>

app/code/Magento/Customer/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<confirm>0</confirm>
1616
<default_group>1</default_group>
1717
<tax_calculation_address_type>billing</tax_calculation_address_type>
18+
<email_required_create_order>0</email_required_create_order>
1819
<email_domain>example.com</email_domain>
1920
<email_identity>general</email_identity>
2021
<email_template>customer_create_account_email_template</email_template>

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Account.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Account extends AbstractForm
3939
*/
4040
protected $_extensibleDataObjectConverter;
4141

42+
private const XML_PATH_EMAIL_REQUIRED_CREATE_ORDER = 'customer/create_account/email_required_create_order';
43+
4244
/**
4345
* @param \Magento\Backend\Block\Template\Context $context
4446
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
@@ -147,7 +149,7 @@ protected function _addAdditionalFormElementData(AbstractElement $element)
147149
{
148150
switch ($element->getId()) {
149151
case 'email':
150-
$element->setRequired(1);
152+
$element->setRequired($this->isEmailRequiredCreateOrder());
151153
$element->setClass('validate-email admin__control-text');
152154
break;
153155
}
@@ -204,4 +206,17 @@ private function extractValuesFromAttributes(array $attributes): array
204206

205207
return $formValues;
206208
}
209+
210+
/**
211+
* Retrieve email is required field for admin order creation
212+
*
213+
* @return bool
214+
*/
215+
private function isEmailRequiredCreateOrder()
216+
{
217+
return $this->_scopeConfig->getValue(
218+
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
219+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
220+
);
221+
}
207222
}

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
3333
*/
3434
const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
3535

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

13711372
$addressForm = $this->_metadataFormFactory->create(
1372-
1373+
13731374
AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
13741375
'adminhtml_customer_address',
13751376
$data,
@@ -2037,7 +2038,30 @@ protected function _validate()
20372038
*/
20382039
protected function _getNewCustomerEmail()
20392040
{
2040-
return $this->getData('account/email');
2041+
$emailrequired = $this->_scopeConfig->getValue(
2042+
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
2043+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
2044+
);
2045+
2046+
if($emailrequired) {
2047+
return $this->getData('account/email');
2048+
} else {
2049+
$email = $this->getData('account/email');
2050+
if (empty($email)) {
2051+
$host = $this->_scopeConfig->getValue(
2052+
self::XML_PATH_DEFAULT_EMAIL_DOMAIN,
2053+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
2054+
);
2055+
$account = time();
2056+
$email = $account . '@' . $host;
2057+
$account = $this->getData('account');
2058+
$account['email'] = $email;
2059+
$this->setData('account', $account);
2060+
}
2061+
2062+
return $email;
2063+
}
2064+
20412065
}
20422066

20432067
/**

0 commit comments

Comments
 (0)