Skip to content

Commit d8a95c9

Browse files
authored
Merge pull request #2760 from magento-borg/MAGETWO-91555
[borg] MAGETWO-91555: Admin orders can result in a customer with an example email address
2 parents 2375461 + 77b74f7 commit d8a95c9

File tree

9 files changed

+84
-27
lines changed

9 files changed

+84
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected function _addAdditionalFormElementData(AbstractElement $element)
147147
{
148148
switch ($element->getId()) {
149149
case 'email':
150-
$element->setRequired(0);
150+
$element->setRequired(1);
151151
$element->setClass('validate-email admin__control-text');
152152
break;
153153
}

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,26 +2012,13 @@ protected function _validate()
20122012
}
20132013

20142014
/**
2015-
* Retrieve or generate new customer email.
2015+
* Retrieve new customer email.
20162016
*
20172017
* @return string
20182018
*/
20192019
protected function _getNewCustomerEmail()
20202020
{
2021-
$email = $this->getData('account/email');
2022-
if (empty($email)) {
2023-
$host = $this->_scopeConfig->getValue(
2024-
self::XML_PATH_DEFAULT_EMAIL_DOMAIN,
2025-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
2026-
);
2027-
$account = time();
2028-
$email = $account . '@' . $host;
2029-
$account = $this->getData('account');
2030-
$account['email'] = $email;
2031-
$this->setData('account', $account);
2032-
}
2033-
2034-
return $email;
2021+
return $this->getData('account/email');
20352022
}
20362023

20372024
/**

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminMultipleWebsitesUseDefaultValuesTest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535

3636
<!--Create Store view -->
3737
<amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/>
38-
<click selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="createStoreViewButton"/>
38+
<click selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="clickCreateStoreViewButton"/>
3939
<waitForPageLoad stepKey="waitForProductPageLoad"/>
40+
<waitForElementVisible selector="//legend[contains(., 'Store View Information')]" stepKey="waitFornewStorePageToOpen" after="clickCreateStoreViewButton"/>
4041
<selectOption userInput="Second Store" selector="{{AdminNewStoreSection.storeGrpDropdown}}" stepKey="selectStoreGroup"/>
4142
<fillField userInput="Second Store View" selector="{{AdminNewStoreSection.storeNameTextField}}" stepKey="fillStoreViewName"/>
4243
<fillField userInput="second_store_view" selector="{{AdminNewStoreSection.storeCodeTextField}}" stepKey="fillStoreViewCode"/>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/SaveProductWithCustomOptionsSecondWebsiteTest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<testCaseId value="MAGETWO-91436"/>
1919
<group value="product"/>
2020
</annotations>
21-
<before>
2221
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
2322
<!--Create new website -->
2423
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createAdditionalWebsite">
@@ -46,7 +45,7 @@
4645
<conditionalClick selector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" dependentSelector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" visible="true" stepKey="AcceptNewStoreViewCreation"/>
4746
<waitForElementVisible selector="{{AdminStoresGridSection.storeFilterTextField}}" stepKey="waitForPageReolad"/>
4847
<see userInput="You saved the store view." stepKey="seeSaveMessage" />
49-
</before>
48+
5049
<after>
5150
<actionGroup ref="ResetWebUrlOptions" stepKey="resetUrlOption"/>
5251
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteTestWebsite">

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Sales/ActionGroup/AdminOrderActionGroup.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<!--Check the required fields are actually required-->
2626
<actionGroup name="checkRequiredFieldsNewOrderForm">
2727
<seeElement selector="{{AdminOrderFormAccountSection.requiredGroup}}" stepKey="seeCustomerGroupRequired"/>
28+
<seeElement selector="{{AdminOrderFormAccountSection.requiredEmail}}" stepKey="seeEmailRequired"/>
29+
<clearField selector="{{AdminOrderFormAccountSection.email}}" stepKey="clearEmailField"/>
2830
<clearField selector="{{AdminOrderFormBillingAddressSection.FirstName}}" stepKey="clearFirstNameField"/>
2931
<clearField selector="{{AdminOrderFormBillingAddressSection.LastName}}" stepKey="clearLastNameField"/>
3032
<clearField selector="{{AdminOrderFormBillingAddressSection.StreetLine1}}" stepKey="clearStreetField"/>
@@ -35,6 +37,7 @@
3537
<clearField selector="{{AdminOrderFormBillingAddressSection.Phone}}" stepKey="clearPhoneField"/>
3638
<seeElement selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="seeShippingMethodNotSelected"/>
3739
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="trySubmitOrder"/>
40+
<see selector="{{AdminOrderFormBillingAddressSection.emailError}}" userInput="This is a required field." stepKey="seeThatEmailIsRequired"/>
3841
<see selector="{{AdminOrderFormBillingAddressSection.firstNameError}}" userInput="This is a required field." stepKey="seeFirstNameRequired"/>
3942
<see selector="{{AdminOrderFormBillingAddressSection.lastNameError}}" userInput="This is a required field." stepKey="seeLastNameRequired"/>
4043
<see selector="{{AdminOrderFormBillingAddressSection.streetAddressError}}" userInput="This is a required field." stepKey="seeStreetRequired"/>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Sales/Section/AdminOrderFormAccountSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
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']"/>
1516
</section>
1617
</sections>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Sales/Section/AdminOrderFormBillingAddressSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<element name="ValidateVatNumber" type="button" selector="#order-billing_address_vat_id + .actions>button.action-default" timeout="30"/>
2929
<element name="SaveAddress" type="checkbox" selector="#order-billing_address_save_in_address_book"/>
3030

31+
<element name="emailError" type="text" selector="#email-error"/>
3132
<element name="firstNameError" type="text" selector="#order-billing_address_firstname-error"/>
3233
<element name="lastNameError" type="text" selector="#order-billing_address_lastname-error"/>
3334
<element name="streetAddressError" type="text" selector="#order-billing_address_street0-error"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
10+
<test name="AdminSubmitsOrderWithAndWithoutEmailTest">
11+
<annotations>
12+
<title value="Email is required to create an order from Admin Panel"/>
13+
<description value="Admin should not be able to submit orders without an email address"/>
14+
<severity value="MAJOR"/>
15+
<testCaseId value="MAGETWO-92980"/>
16+
<group value="sales"/>
17+
18+
</annotations>
19+
<before>
20+
<createData entity="_defaultCategory" stepKey="createCategory"/>
21+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
22+
<requiredEntity createDataKey="createCategory"/>
23+
</createData>
24+
</before>
25+
<after>
26+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
27+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
28+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
29+
</after>
30+
<!--Create order via Admin-->
31+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
32+
<comment userInput="Admin creates order" stepKey="adminCreateOrderComment"/>
33+
<!--<actionGroup ref="navigateToNewOrderPageNewCustomer" stepKey="navigateToNewOrderPage"/>-->
34+
<amOnPage url="{{AdminOrdersPage.url}}" stepKey="navigateToOrderIndexPage"/>
35+
<waitForPageLoad stepKey="waitForIndexPageLoad"/>
36+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="Orders" stepKey="seeIndexPageTitle"/>
37+
<click selector="{{AdminOrdersGridSection.createNewOrder}}" stepKey="clickCreateNewOrder"/>
38+
<click selector="{{AdminOrderFormActionSection.CreateNewCustomer}}" stepKey="clickCreateCustomer"/>
39+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="Create New Order" stepKey="seeNewOrderPageTitle"/>
40+
41+
<!--Check if order can be submitted without the required fields including email address-->
42+
<actionGroup ref="checkRequiredFieldsNewOrderForm" stepKey="checkRequiredFieldsNewOrder" after="seeNewOrderPageTitle"/>
43+
<scrollToTopOfPage stepKey="scrollToTopOfOrderFormPage" after="checkRequiredFieldsNewOrder"/>
44+
<actionGroup ref="addSimpleProductToOrder" stepKey="addSimpleProductToOrder" after="scrollToTopOfOrderFormPage">
45+
<argument name="product" value="_defaultProduct"/>
46+
</actionGroup>
47+
48+
<!--Fill customer group and customer email-->
49+
<selectOption selector="{{AdminOrderFormAccountSection.group}}" userInput="{{GeneralCustomerGroup.code}}" stepKey="selectCustomerGroup" after="addSimpleProductToOrder"/>
50+
<fillField selector="{{AdminOrderFormAccountSection.email}}" userInput="{{Simple_US_Customer.email}}" stepKey="fillCustomerEmail" after="selectCustomerGroup"/>
51+
52+
<!--Fill customer address information-->
53+
<actionGroup ref="fillOrderCustomerInformation" stepKey="fillCustomerAddress" after="fillCustomerEmail">
54+
<argument name="customer" value="Simple_US_Customer"/>
55+
<argument name="address" value="US_Address_TX"/>
56+
</actionGroup>
57+
<!-- Select shipping -->
58+
<actionGroup ref="orderSelectFlatRateShipping" stepKey="selectFlatRateShipping" after="fillCustomerAddress"/>
59+
60+
<!--Verify totals on Order page-->
61+
<see selector="{{AdminOrderFormTotalSection.total('Subtotal')}}" userInput="${{AdminOrderSimpleProduct.subtotal}}" stepKey="seeOrderSubTotal" after="selectFlatRateShipping"/>
62+
<see selector="{{AdminOrderFormTotalSection.total('Shipping')}}" userInput="${{AdminOrderSimpleProduct.shipping}}" stepKey="seeOrderShipping" after="seeOrderSubTotal"/>
63+
<scrollTo selector="{{AdminOrderFormTotalSection.grandTotal}}" stepKey="scrollToOrderGrandTotal"/>
64+
<see selector="{{AdminOrderFormTotalSection.grandTotal}}" userInput="${{AdminOrderSimpleProduct.grandTotal}}" stepKey="seeCorrectGrandTotal" after="scrollToOrderGrandTotal"/>
65+
66+
<!--Submit Order and verify information-->
67+
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder" after="seeCorrectGrandTotal"/>
68+
<seeInCurrentUrl url="{{AdminOrderDetailsPage.url}}" stepKey="seeViewOrderPage" after="clickSubmitOrder"/>
69+
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeSuccessMessage" after="seeViewOrderPage"/>
70+
</test>
71+
</tests>

dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,20 +519,14 @@ public function testCreateOrderNewCustomerWithFailedFirstPlaceOrderAction(
519519
* Email before and after failed first place order action.
520520
*
521521
* @case #1 Is the same.
522-
* @case #2 Is empty.
523-
* @case #3 Filled after failed first place order action.
524-
* @case #4 Empty after failed first place order action.
525-
* @case #5 Changed after failed first place order action.
522+
* @case #2 Changed after failed first place order action.
526523
* @return array
527524
*/
528525
public function createOrderNewCustomerWithFailedFirstPlaceOrderActionDataProvider()
529526
{
530527
return [
531528
532-
2 => ['', ''],
533-
3 => ['', '[email protected]'],
534-
4 => ['[email protected]', ''],
535-
529+
536530
];
537531
}
538532

0 commit comments

Comments
 (0)