Skip to content

Commit 21ac7c7

Browse files
ENGCOM-8039: Fixed wrong customer group assign to order 26976 #27857
2 parents 29cc296 + a2a3d65 commit 21ac7c7

File tree

4 files changed

+102
-18
lines changed

4 files changed

+102
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontCustomerCheckoutWithCustomerGroupTest">
11+
<annotations>
12+
<features value="Customer Checkout"/>
13+
<stories value="Customer checkout with Customer Group assigned"/>
14+
<title value="Place order by Customer with Customer Group assigned"/>
15+
<description value="Customer Group should be assigned to Order when setting Auto Group Assign is enabled for Customer"/>
16+
<testCaseId value="MC-37259"/>
17+
<severity value="MAJOR"/>
18+
<group value="checkout"/>
19+
<group value="customer"/>
20+
</annotations>
21+
<before>
22+
23+
<magentoCLI command="config:set customer/create_account/auto_group_assign 1" stepKey="enableAutoGroupAssign"/>
24+
25+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
26+
<createData entity="SimpleProduct" stepKey="createSimpleProduct">
27+
<requiredEntity createDataKey="createCategory"/>
28+
</createData>
29+
30+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
31+
32+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
33+
34+
<actionGroup ref="AdminUpdateCustomerGroupByEmailActionGroup" stepKey="updateCustomerGroup">
35+
<argument name="emailAddress" value="$$createCustomer.email$$"/>
36+
<argument name="customerGroup" value="Retail"/>
37+
</actionGroup>
38+
39+
</before>
40+
<after>
41+
<magentoCLI command="config:set customer/create_account/auto_group_assign 0" stepKey="disableAutoGroupAssign"/>
42+
43+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/>
44+
<deleteData createDataKey="createCustomer" stepKey="deleteUsCustomer"/>
45+
<actionGroup ref="AdminClearCustomersFiltersActionGroup" stepKey="resetCustomerFilters"/>
46+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>
47+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
48+
<deleteData createDataKey="createCategory" stepKey="deleteSimpleCategory"/>
49+
</after>
50+
51+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="storefrontCustomerLogin">
52+
<argument name="Customer" value="$$createCustomer$$"/>
53+
</actionGroup>
54+
55+
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage">
56+
<argument name="category" value="$$createCategory$$"/>
57+
</actionGroup>
58+
59+
<waitForPageLoad stepKey="waitForCatalogPageLoad"/>
60+
61+
<actionGroup ref="StorefrontAddCategoryProductToCartActionGroup" stepKey="addProductToCart">
62+
<argument name="product" value="$$createSimpleProduct$$"/>
63+
<argument name="productCount" value="CONST.one"/>
64+
</actionGroup>
65+
66+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
67+
<actionGroup ref="CheckoutSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRate"/>
68+
<actionGroup ref="StorefrontCheckoutForwardFromShippingStepActionGroup" stepKey="goToReview"/>
69+
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyOrder"/>
70+
<actionGroup ref="CheckoutPlaceOrderActionGroup" stepKey="clickOnPlaceOrder">
71+
<argument name="orderNumberMessage" value="CONST.successCheckoutOrderNumberMessage"/>
72+
<argument name="emailYouMessage" value="CONST.successCheckoutEmailYouMessage"/>
73+
</actionGroup>
74+
75+
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="orderNumber"/>
76+
77+
<actionGroup ref="OpenOrderByIdActionGroup" stepKey="addFilterToGridAndOpenOrder">
78+
<argument name="orderId" value="{$orderNumber}"/>
79+
</actionGroup>
80+
81+
<see selector="{{AdminOrderDetailsInformationSection.orderStatus}}" userInput="Pending" stepKey="verifyOrderStatus"/>
82+
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="Customer" stepKey="verifyAccountInformation"/>
83+
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="$$createCustomer.email$$" stepKey="verifyCustomerEmail"/>
84+
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="Retail" stepKey="verifyCustomerGroup"/>
85+
<see selector="{{AdminOrderDetailsInformationSection.billingAddress}}" userInput="{{US_Address_TX.street[0]}}" stepKey="verifyBillingAddress"/>
86+
<see selector="{{AdminOrderDetailsInformationSection.shippingAddress}}" userInput="{{US_Address_TX.street[0]}}" stepKey="verifyShippingAddress"/>
87+
<see selector="{{AdminOrderDetailsInformationSection.itemsOrdered}}" userInput="$$createSimpleProduct.name$$" stepKey="verifyProductName"/>
88+
89+
</test>
90+
</tests>

app/code/Magento/Quote/Observer/Frontend/Quote/Address/CollectTotalsObserver.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
119119

120120
$groupId = null;
121121
if (empty($customerVatNumber) || false == $this->customerVat->isCountryInEU($customerCountryCode)) {
122-
$groupId = $customer->getId() ? $this->groupManagement->getDefaultGroup(
123-
$storeId
124-
)->getId() : $this->groupManagement->getNotLoggedInGroup()->getId();
122+
$groupId = $customer->getId() ? $quote->getCustomerGroupId() :
123+
$this->groupManagement->getNotLoggedInGroup()->getId();
125124
} else {
126125
// Magento always has to emulate group even if customer uses default billing/shipping address
127126
$groupId = $this->customerVat->getCustomerGroupIdBasedOnVatNumber(

app/code/Magento/Quote/Test/Unit/Observer/Frontend/Quote/Address/CollectTotalsObserverTest.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
1414
use Magento\Customer\Api\Data\GroupInterface;
1515
use Magento\Customer\Api\GroupManagementInterface;
16-
use Magento\Customer\Helper\Address;
16+
use Magento\Customer\Helper\Address as CustomerAddress;
1717
use Magento\Customer\Model\Session;
1818
use Magento\Customer\Model\Vat;
1919
use Magento\Framework\Event\Observer;
2020
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2121
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
2222
use Magento\Quote\Api\Data\ShippingInterface;
2323
use Magento\Quote\Model\Quote;
24+
use Magento\Quote\Model\Quote\Address;
2425
use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver;
2526
use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator;
26-
use PHPUnit\Framework\MockObject\MockObject;
2727
use PHPUnit\Framework\TestCase;
28+
use PHPUnit\Framework\MockObject\MockObject;
2829

2930
/**
3031
* Class CollectTotalsTest
@@ -124,7 +125,7 @@ protected function setUp(): void
124125
true,
125126
['getStoreId', 'getCustomAttribute', 'getId', '__wakeup']
126127
);
127-
$this->customerAddressMock = $this->createMock(Address::class);
128+
$this->customerAddressMock = $this->createMock(CustomerAddress::class);
128129
$this->customerVatMock = $this->createMock(Vat::class);
129130
$this->customerDataFactoryMock = $this->getMockBuilder(CustomerInterfaceFactory::class)
130131
->addMethods(['mergeDataObjectWithArray'])
@@ -174,6 +175,7 @@ protected function setUp(): void
174175

175176
$shippingAssignmentMock = $this->getMockForAbstractClass(ShippingAssignmentInterface::class);
176177
$shippingMock = $this->getMockForAbstractClass(ShippingInterface::class);
178+
177179
$shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
178180
$shippingMock->expects($this->once())->method('getAddress')->willReturn($this->quoteAddressMock);
179181

@@ -185,7 +187,6 @@ protected function setUp(): void
185187
$this->quoteMock->expects($this->any())
186188
->method('getCustomer')
187189
->willReturn($this->customerMock);
188-
189190
$this->addressRepository = $this->getMockForAbstractClass(AddressRepositoryInterface::class);
190191
$this->customerSession = $this->getMockBuilder(Session::class)
191192
->disableOriginalConstructor()
@@ -266,26 +267,20 @@ public function testDispatchWithDefaultCustomerGroupId()
266267
->willReturn('customerCountryCode');
267268
$this->quoteAddressMock->expects($this->once())->method('getVatId')->willReturn(null);
268269

269-
$this->quoteMock->expects($this->once())
270+
$this->quoteMock->expects($this->exactly(2))
270271
->method('getCustomerGroupId')
271272
->willReturn('customerGroupId');
272273
$this->customerMock->expects($this->once())->method('getId')->willReturn('1');
273-
$this->groupManagementMock->expects($this->once())
274-
->method('getDefaultGroup')
275-
->willReturn($this->groupInterfaceMock);
276-
$this->groupInterfaceMock->expects($this->once())
277-
->method('getId')->willReturn('defaultCustomerGroupId');
274+
278275
/** Assertions */
279276
$this->quoteAddressMock->expects($this->once())
280277
->method('setPrevQuoteCustomerGroupId')
281278
->with('customerGroupId');
282-
$this->quoteMock->expects($this->once())->method('setCustomerGroupId')->with('defaultCustomerGroupId');
283279
$this->customerDataFactoryMock->expects($this->any())
284280
->method('create')
285281
->willReturn($this->customerMock);
286282

287283
$this->quoteMock->expects($this->once())->method('setCustomer')->with($this->customerMock);
288-
289284
/** SUT execution */
290285
$this->model->execute($this->observerMock);
291286
}
@@ -343,7 +338,7 @@ public function testDispatchWithAddressCustomerVatIdAndCountryId()
343338
$customerVat = "123123123";
344339
$defaultShipping = 1;
345340

346-
$customerAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
341+
$customerAddress = $this->createMock(Address::class);
347342
$customerAddress->expects($this->any())
348343
->method("getVatId")
349344
->willReturn($customerVat);
@@ -379,8 +374,8 @@ public function testDispatchWithEmptyShippingAddress()
379374
$customerCountryCode = "DE";
380375
$customerVat = "123123123";
381376
$defaultShipping = 1;
382-
383377
$customerAddress = $this->getMockForAbstractClass(AddressInterface::class);
378+
384379
$customerAddress->expects($this->once())
385380
->method("getCountryId")
386381
->willReturn($customerCountryCode);

dev/tests/integration/testsuite/Magento/Quote/Observer/Frontend/Quote/Address/CollectTotalsObserverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ public function testChangeQuoteCustomerGroupIdForCustomerWithEnabledAutomaticGro
133133
);
134134
$this->model->execute($eventObserver);
135135

136-
$this->assertEquals(1, $quote->getCustomer()->getGroupId());
136+
$this->assertEquals(2, $quote->getCustomer()->getGroupId());
137137
}
138138
}

0 commit comments

Comments
 (0)