Skip to content

Commit bef9ab7

Browse files
authored
ENGCOM-6208: 22251 admin order email is now required 1 #24479
2 parents ce8817a + 3a34d7f commit bef9ab7

File tree

14 files changed

+186
-9
lines changed

14 files changed

+186
-9
lines changed

app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@
178178
<data key="website_id">0</data>
179179
<requiredEntity type="address">US_Address_CA</requiredEntity>
180180
</entity>
181+
<entity name="Simple_US_Customer_CA_Without_Email" type="customer">
182+
<data key="group_id">0</data>
183+
<data key="default_billing">true</data>
184+
<data key="default_shipping">true</data>
185+
<data key="firstname">John</data>
186+
<data key="lastname">Doe</data>
187+
<data key="fullname">John Doe</data>
188+
<data key="password">pwdTest123!</data>
189+
<data key="store_id">0</data>
190+
<data key="website_id">0</data>
191+
<requiredEntity type="address">US_Address_CA</requiredEntity>
192+
</entity>
181193
<entity name="Simple_US_Customer_For_Update" type="customer">
182194
<var key="id" entityKey="id" entityType="customer"/>
183195
<data key="firstname">Jane</data>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
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_domain" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
90+
<label>Default Email Domain</label>
91+
</field>
8992
<field id="email_template" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
9093
<label>Default Welcome Email</label>
9194
<comment>Email template chosen based on theme fallback when "Default" option is selected.</comment>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<email_confirmed_template>customer_create_account_email_confirmed_template</email_confirmed_template>
2424
<viv_disable_auto_group_assign_default>0</viv_disable_auto_group_assign_default>
2525
<vat_frontend_visibility>0</vat_frontend_visibility>
26+
<email_domain>example.com</email_domain>
2627
<generate_human_friendly_id>0</generate_human_friendly_id>
2728
</create_account>
2829
<default>

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Account extends AbstractForm
3838
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter
3939
*/
4040
protected $_extensibleDataObjectConverter;
41-
41+
private const XML_PATH_EMAIL_REQUIRED_CREATE_ORDER = 'customer/create_account/email_required_create_order';
4242
/**
4343
* @param \Magento\Backend\Block\Template\Context $context
4444
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
@@ -147,7 +147,7 @@ protected function _addAdditionalFormElementData(AbstractElement $element)
147147
{
148148
switch ($element->getId()) {
149149
case 'email':
150-
$element->setRequired(1);
150+
$element->setRequired($this->isEmailRequiredToCreateOrder());
151151
$element->setClass('validate-email admin__control-text');
152152
break;
153153
}
@@ -164,7 +164,7 @@ public function getFormValues()
164164
try {
165165
$customer = $this->customerRepository->getById($this->getCustomerId());
166166
} catch (\Exception $e) {
167-
/** If customer does not exist do nothing. */
167+
$data = [];
168168
}
169169
$data = isset($customer)
170170
? $this->_extensibleDataObjectConverter->toFlatArray(
@@ -204,4 +204,17 @@ private function extractValuesFromAttributes(array $attributes): array
204204

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

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
*/
2929
class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\Model\Cart\CartInterface
3030
{
31+
/**
32+
* Xml default email domain path
33+
*/
34+
const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
35+
36+
private const XML_PATH_EMAIL_REQUIRED_CREATE_ORDER = 'customer/create_account/email_required_create_order';
3137
/**
3238
* Quote session object
3339
*
@@ -1363,7 +1369,7 @@ protected function _setQuoteAddress(\Magento\Quote\Model\Quote\Address $address,
13631369
$data = isset($data['region']) && is_array($data['region']) ? array_merge($data, $data['region']) : $data;
13641370

13651371
$addressForm = $this->_metadataFormFactory->create(
1366-
1372+
13671373
AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
13681374
'adminhtml_customer_address',
13691375
$data,
@@ -2031,7 +2037,47 @@ protected function _validate()
20312037
*/
20322038
protected function _getNewCustomerEmail()
20332039
{
2034-
return $this->getData('account/email');
2040+
$email = $this->getData('account/email');
2041+
2042+
if ($email || $this->isEmailRequired()) {
2043+
return $email;
2044+
}
2045+
2046+
return $this->generateEmail();
2047+
}
2048+
2049+
/**
2050+
* Check email is require
2051+
*
2052+
* @return bool
2053+
*/
2054+
private function isEmailRequired(): bool
2055+
{
2056+
return (bool)$this->_scopeConfig->getValue(
2057+
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
2058+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
2059+
$this->_session->getStore()->getId()
2060+
);
2061+
}
2062+
2063+
/**
2064+
* Generate Email
2065+
*
2066+
* @return string
2067+
*/
2068+
private function generateEmail(): string
2069+
{
2070+
$host = $this->_scopeConfig->getValue(
2071+
self::XML_PATH_DEFAULT_EMAIL_DOMAIN,
2072+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
2073+
);
2074+
$account = time();
2075+
$email = $account . '@' . $host;
2076+
$account = $this->getData('account');
2077+
$account['email'] = $email;
2078+
$this->setData('account', $account);
2079+
2080+
return $email;
20352081
}
20362082

20372083
/**

app/code/Magento/Sales/Test/Mftf/ActionGroup/CheckRequiredFieldsNewOrderFormActionGroup.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<clearField selector="{{AdminOrderFormBillingAddressSection.Phone}}" stepKey="clearPhoneField"/>
2727
<seeElement selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="seeShippingMethodNotSelected"/>
2828
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="trySubmitOrder"/>
29-
<see selector="{{AdminOrderFormBillingAddressSection.emailError}}" userInput="This is a required field." stepKey="seeThatEmailIsRequired"/>
3029
<see selector="{{AdminOrderFormBillingAddressSection.firstNameError}}" userInput="This is a required field." stepKey="seeFirstNameRequired"/>
3130
<see selector="{{AdminOrderFormBillingAddressSection.lastNameError}}" userInput="This is a required field." stepKey="seeLastNameRequired"/>
3231
<see selector="{{AdminOrderFormBillingAddressSection.streetAddressError}}" userInput="This is a required field." stepKey="seeStreetRequired"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="VerifyCreatedOrderInformationWithGeneratedEmailActionGroup">
11+
<annotations>
12+
<description>Validate customer email on order page. Starts on order page.</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="email" type="string" defaultValue="{{CustomerEntityOne.email}}"/>
16+
</arguments>
17+
<see selector="{{AdminOrderDetailsInformationSection.customerEmail}}" userInput="{{email}}" stepKey="seeGeneratedEmail"/>
18+
</actionGroup>
19+
</actionGroups>

app/code/Magento/Sales/Test/Mftf/Data/ConfigData.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@
2020
<data key="label">No</data>
2121
<data key="value">0</data>
2222
</entity>
23+
<entity name="DisableEmailRequiredForOrder">
24+
<data key="path">customer/create_account/email_required_create_order</data>
25+
<data key="value">0</data>
26+
</entity>
27+
<entity name="EnableEmailRequiredForOrder">
28+
<data key="path">customer/create_account/email_required_create_order</data>
29+
<data key="value">1</data>
30+
</entity>
2331
</entities>

app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormAccountSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<element name="group" type="select" selector="#group_id"/>
1313
<element name="email" type="input" selector="#email"/>
1414
<element name="requiredGroup" type="text" selector=".admin__field.required[data-ui-id='billing-address-fieldset-element-form-field-group-id']"/>
15-
<element name="requiredEmail" type="text" selector=".admin__field.required[data-ui-id='billing-address-fieldset-element-form-field-email']"/>
15+
<element name="requiredEmail" type="text" selector=".admin__field[data-ui-id='billing-address-fieldset-element-form-field-email']"/>
1616
<element name="defaultGeneral" type="text" selector="//*[contains(text(),'General')]" timeout="15"/>
1717
<element name="emailErrorMessage" type="text" selector="#email-error"/>
1818
</section>

app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormBillingAddressSection.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
<element name="VatNumber" type="input" selector="#order-billing_address_vat_id" timeout="30"/>
2929
<element name="ValidateVatNumber" type="button" selector="#order-billing_address_vat_id + .actions>button.action-default" timeout="30"/>
3030
<element name="SaveAddress" type="checkbox" selector="#order-billing_address_save_in_address_book"/>
31-
32-
<element name="emailError" type="text" selector="#email-error"/>
3331
<element name="firstNameError" type="text" selector="#order-billing_address_firstname-error"/>
3432
<element name="lastNameError" type="text" selector="#order-billing_address_lastname-error"/>
3533
<element name="streetAddressError" type="text" selector="#order-billing_address_street0-error"/>

0 commit comments

Comments
 (0)