Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22251 admin order email is now required 1 #24479

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2ac0fe3
force change files
Aug 16, 2019
d78361e
Admin Order - Email is Now Required - Magento 2.3 Updated
Aug 16, 2019
078bd69
Email field translation
Sep 9, 2019
7e5bb80
_getNewCustomerEmail seperate it in differnet method
Sep 14, 2019
b5265e8
Update Create.php
swnsma Sep 16, 2019
3c1d73e
system.xml is placed in sales module
Sep 17, 2019
339c4c2
resolved Sales en_US.csv file conflict
Sep 17, 2019
49f9277
Merge branch '2.3-develop' into 22251-admin-order-email-is-now-requir…
solwininfotech Sep 17, 2019
0627db9
boolean function starts with is
Sep 21, 2019
1e9e940
discarding customer language file
Sep 21, 2019
6dcdd8a
Discard NonComposerComponentRegistration file
Sep 21, 2019
0e392e7
discard files
Sep 21, 2019
d4bcc7f
file permission change for account.php and create.php file
Sep 23, 2019
4e4e6a2
added required discared files
Sep 23, 2019
7da3d53
corrected di.xml and Account.php files
Sep 25, 2019
82ed876
Merge branch '2.3-develop' into 22251-admin-order-email-is-now-requir…
Sep 27, 2019
5851126
Added Function and Integration
Oct 1, 2019
7772d52
functional test changes
Oct 4, 2019
6915dc8
Added Function and Integration email validation
Oct 4, 2019
65ae5b0
Integration test
Oct 11, 2019
93fc0ee
integration test fails
Oct 11, 2019
225ba00
Merge branch '2.3-develop' into 22251-admin-order-email-is-now-requir…
Oct 16, 2019
d5997ce
version checker test failed
Oct 16, 2019
781684a
Integration test changes
Oct 22, 2019
fbe87ab
static test failed exception fix
Nov 1, 2019
93d698a
static test failed exception space fix
Nov 1, 2019
f4692b2
Semantic Version Checker
Nov 1, 2019
3e8369e
revert for composer json change
Nov 1, 2019
183b315
Merge remote-tracking branch 'upstream/2.3-develop' into 2.3-develop
Nov 6, 2019
6d906ab
Resolved conflict for en_US.csv
Nov 6, 2019
6fe2ab2
git merge with 2.3-develop fix
Nov 9, 2019
dfe0392
Merge remote-tracking branch 'upstream/2.3-develop' into 2.3-develop
Nov 20, 2019
ab86799
Merge branch '2.3-develop' into 22251-admin-order-email-is-now-requir…
Nov 20, 2019
74cfd18
merge with 2.3
Nov 20, 2019
505549b
merge magento 2.3
Dec 24, 2019
168a006
Merge branch '2.4-develop' of http://github.com/magento/magento2 into…
engcom-Echo Feb 4, 2020
b1b3e6c
Cover MFTF test
engcom-Echo Feb 4, 2020
ca32574
Merge branch '2.4-develop' into 22251-admin-order-email-is-now-requir…
solwininfotech Feb 11, 2020
531e1b5
resolved merge conflict
Feb 17, 2020
864f396
Merge branch '2.4-develop' into 22251-admin-order-email-is-now-requir…
swnsma Mar 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@
<data key="website_id">0</data>
<requiredEntity type="address">US_Address_CA</requiredEntity>
</entity>
<entity name="Simple_US_Customer_CA_Without_Email" type="customer">
<data key="group_id">0</data>
<data key="default_billing">true</data>
<data key="default_shipping">true</data>
<data key="firstname">John</data>
<data key="lastname">Doe</data>
<data key="fullname">John Doe</data>
<data key="password">pwdTest123!</data>
<data key="store_id">0</data>
<data key="website_id">0</data>
<requiredEntity type="address">US_Address_CA</requiredEntity>
</entity>
<entity name="Simple_US_Customer_For_Update" type="customer">
<var key="id" entityKey="id" entityType="customer"/>
<data key="firstname">Jane</data>
Expand Down
3 changes: 3 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,9 @@
<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_domain" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Default Email Domain</label>
</field>
<field id="email_template" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Default Welcome Email</label>
<comment>Email template chosen based on theme fallback when "Default" option is selected.</comment>
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 @@ -23,6 +23,7 @@
<email_confirmed_template>customer_create_account_email_confirmed_template</email_confirmed_template>
<viv_disable_auto_group_assign_default>0</viv_disable_auto_group_assign_default>
<vat_frontend_visibility>0</vat_frontend_visibility>
<email_domain>example.com</email_domain>
<generate_human_friendly_id>0</generate_human_friendly_id>
</create_account>
<default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Account extends AbstractForm
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter
*/
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 +147,7 @@ protected function _addAdditionalFormElementData(AbstractElement $element)
{
switch ($element->getId()) {
case 'email':
$element->setRequired(1);
$element->setRequired($this->isEmailRequiredToCreateOrder());
$element->setClass('validate-email admin__control-text');
break;
}
Expand All @@ -164,7 +164,7 @@ public function getFormValues()
try {
$customer = $this->customerRepository->getById($this->getCustomerId());
} catch (\Exception $e) {
/** If customer does not exist do nothing. */
$data = [];
}
$data = isset($customer)
? $this->_extensibleDataObjectConverter->toFlatArray(
Expand Down Expand Up @@ -204,4 +204,17 @@ private function extractValuesFromAttributes(array $attributes): array

return $formValues;
}

/**
* Retrieve email is required field for admin order creation
*
* @return bool
*/
private function isEmailRequiredToCreateOrder()
{
return $this->_scopeConfig->getValue(
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}
50 changes: 48 additions & 2 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
*/
class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\Model\Cart\CartInterface
{
/**
* Xml default email domain path
*/
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 @@ -1363,7 +1369,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 @@ -2031,7 +2037,47 @@ protected function _validate()
*/
protected function _getNewCustomerEmail()
{
return $this->getData('account/email');
$email = $this->getData('account/email');

if ($email || $this->isEmailRequired()) {
return $email;
}

return $this->generateEmail();
}

/**
* Check email is require
*
* @return bool
*/
private function isEmailRequired(): bool
{
return (bool)$this->_scopeConfig->getValue(
self::XML_PATH_EMAIL_REQUIRED_CREATE_ORDER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->_session->getStore()->getId()
);
}

/**
* Generate Email
*
* @return string
*/
private function generateEmail(): string
{
$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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<clearField selector="{{AdminOrderFormBillingAddressSection.Phone}}" stepKey="clearPhoneField"/>
<seeElement selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="seeShippingMethodNotSelected"/>
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="trySubmitOrder"/>
<see selector="{{AdminOrderFormBillingAddressSection.emailError}}" userInput="This is a required field." stepKey="seeThatEmailIsRequired"/>
<see selector="{{AdminOrderFormBillingAddressSection.firstNameError}}" userInput="This is a required field." stepKey="seeFirstNameRequired"/>
<see selector="{{AdminOrderFormBillingAddressSection.lastNameError}}" userInput="This is a required field." stepKey="seeLastNameRequired"/>
<see selector="{{AdminOrderFormBillingAddressSection.streetAddressError}}" userInput="This is a required field." stepKey="seeStreetRequired"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="VerifyCreatedOrderInformationWithGeneratedEmailActionGroup">
<annotations>
<description>Validate customer email on order page. Starts on order page.</description>
</annotations>
<arguments>
<argument name="email" type="string" defaultValue="{{CustomerEntityOne.email}}"/>
</arguments>
<see selector="{{AdminOrderDetailsInformationSection.customerEmail}}" userInput="{{email}}" stepKey="seeGeneratedEmail"/>
</actionGroup>
</actionGroups>
8 changes: 8 additions & 0 deletions app/code/Magento/Sales/Test/Mftf/Data/ConfigData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@
<data key="label">No</data>
<data key="value">0</data>
</entity>
<entity name="DisableEmailRequiredForOrder">
<data key="path">customer/create_account/email_required_create_order</data>
<data key="value">0</data>
</entity>
<entity name="EnableEmailRequiredForOrder">
<data key="path">customer/create_account/email_required_create_order</data>
<data key="value">1</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<element name="group" type="select" selector="#group_id"/>
<element name="email" type="input" selector="#email"/>
<element name="requiredGroup" type="text" selector=".admin__field.required[data-ui-id='billing-address-fieldset-element-form-field-group-id']"/>
<element name="requiredEmail" type="text" selector=".admin__field.required[data-ui-id='billing-address-fieldset-element-form-field-email']"/>
<element name="requiredEmail" type="text" selector=".admin__field[data-ui-id='billing-address-fieldset-element-form-field-email']"/>
<element name="defaultGeneral" type="text" selector="//*[contains(text(),'General')]" timeout="15"/>
<element name="emailErrorMessage" type="text" selector="#email-error"/>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<element name="VatNumber" type="input" selector="#order-billing_address_vat_id" timeout="30"/>
<element name="ValidateVatNumber" type="button" selector="#order-billing_address_vat_id + .actions>button.action-default" timeout="30"/>
<element name="SaveAddress" type="checkbox" selector="#order-billing_address_save_in_address_book"/>

<element name="emailError" type="text" selector="#email-error"/>
<element name="firstNameError" type="text" selector="#order-billing_address_firstname-error"/>
<element name="lastNameError" type="text" selector="#order-billing_address_lastname-error"/>
<element name="streetAddressError" type="text" selector="#order-billing_address_street0-error"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCreateOrderWithCustomerWithoutEmailTest">
<annotations>
<title value="Admin Create Order"/>
<stories value="Admin create order with customer without email."/>
<description value="Verify, admin able to create order with customer without email."/>
<severity value="MINOR"/>
<group value="Sales"/>
</annotations>
<before>
<!--Disable required 'email' field on create order page.-->
<magentoCLI command="config:set {{DisableEmailRequiredForOrder.path}} {{DisableEmailRequiredForOrder.value}}" stepKey="disableRequiredFieldEmailForAdminOrderCreation"/>
<!--Create test data.-->
<createData entity="_defaultCategory" stepKey="category"/>
<createData entity="SimpleProduct" stepKey="simpleProduct">
<requiredEntity createDataKey="category"/>
</createData>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
</before>
<after>
<!--Clean up created test data.-->
<deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
<!--Enable required 'email' field on create order page.-->
<magentoCLI command="config:set {{EnableEmailRequiredForOrder.path}} {{EnableEmailRequiredForOrder.value}}" stepKey="enableRequiredFieldEmailForAdminOrderCreation"/>
<actionGroup ref="logout" stepKey="logout"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
</after>

<!--Create order.-->
<actionGroup ref="NavigateToNewOrderPageNewCustomerActionGroup" stepKey="navigateToNewOrderPageNewCustomerActionGroup" />
<actionGroup ref="AddSimpleProductToOrderActionGroup" stepKey="addSimpleProductToOrder">
<argument name="product" value="$$simpleProduct$$"/>
<argument name="productQty" value="{{SimpleProduct.quantity}}"/>
</actionGroup>
<!--Fill customer address without 'email'-->
<actionGroup ref="FillOrderCustomerInformationActionGroup" stepKey="fillCustomerInformation">
<argument name="customer" value="Simple_US_Customer_CA_Without_Email"/>
<argument name="address" value="US_Address_CA"/>
</actionGroup>
<actionGroup ref="OrderSelectFlatRateShippingActionGroup" stepKey="orderSelectFlatRateShippingMethod"/>
<actionGroup ref="AdminSubmitOrderActionGroup" stepKey="submitOrder"/>
<!--Verify, 'email' is generated.-->
<actionGroup ref="VerifyCreatedOrderInformationWithGeneratedEmailActionGroup" stepKey="verifyCustomerEmail">
<argument name="email" value="@example.com"/>
</actionGroup>
<grabTextFrom selector="{{AdminOrderDetailsInformationSection.customerEmail}}" stepKey="generatedCustomerEmail"/>
<actionGroup ref="DeleteCustomerByEmailActionGroup" stepKey="deleteCustomer">
<argument name="email" value="$generatedCustomerEmail"/>
</actionGroup>
</test>
</tests>
10 changes: 10 additions & 0 deletions app/code/Magento/Sales/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -566,5 +566,15 @@
</field>
</group>
</section>
<section id="customer">
<group id="create_account" translate="label" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Create New Account Options</label>
<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>
</group>
</section>
</system>
</config>
5 changes: 5 additions & 0 deletions app/code/Magento/Sales/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,10 @@
<async_indexing>0</async_indexing>
</grid>
</dev>
<customer>
<create_account>
<email_required_create_order>1</email_required_create_order>
</create_account>
</customer>
</default>
</config>
2 changes: 2 additions & 0 deletions app/code/Magento/Sales/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ Created,Created
Refunds,Refunds
"Allow Zero GrandTotal for Creditmemo","Allow Zero GrandTotal for Creditmemo"
"Allow Zero GrandTotal","Allow Zero GrandTotal"
Email is required field for Admin order creation,Email is required field for Admin order creation
If set YES Email field will be required during Admin order creation for new Customer.,If set YES Email field will be required during Admin order creation for new Customer.
"Could not save the shipment tracking","Could not save the shipment tracking"
"Please enter a coupon code!","Please enter a coupon code!"
"Reorder is not available.","Reorder is not available."