Skip to content

Fixed wrong customer group assign to order 26976 #27857

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

Merged
merged 29 commits into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a84629f
fixed wrong customer group that assign to order
ProkopovVitaliy Apr 14, 2020
24793f9
refactored unit test class
ProkopovVitaliy Apr 14, 2020
669c923
Merge branch '2.4-develop' into fix-26976
swnsma Apr 15, 2020
92bd591
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy Apr 20, 2020
a6cf5cb
fixed too long string
ProkopovVitaliy Apr 20, 2020
245453e
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy Apr 28, 2020
eb3fe20
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy Apr 29, 2020
183a2a0
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy May 8, 2020
c38d1ef
fixed integration test
ProkopovVitaliy May 23, 2020
c6ebe35
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy May 28, 2020
38ae3b1
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy May 28, 2020
3ed5e1c
Merge branch '2.4-develop' into fix-26976
engcom-Kilo Jun 1, 2020
07e9b1c
Merge branch '2.4-develop' into fix-26976
engcom-Kilo Jun 17, 2020
cae2258
MFTF test
engcom-Kilo Jun 17, 2020
7153359
Merge branch '2.4-develop' into fix-26976
swnsma Jun 20, 2020
2ce9abd
Merge branch '2.4-develop' into fix-26976
ProkopovVitaliy Jun 24, 2020
32be93c
Merge branch '2.4-develop' into fix-26976
swnsma Jun 24, 2020
a5dba17
Merge branch '2.4-develop' into fix-26976
engcom-Kilo Jul 15, 2020
d231549
Merge branch '2.4-develop' into fix-26976
swnsma Jul 21, 2020
c1fbef5
Merge branch '2.4-develop' into fix-26976
engcom-Kilo Jul 22, 2020
a9e6752
Correct Static and Unit test
engcom-Kilo Jul 27, 2020
22f98a6
Merge branch '2.4-develop' into fix-26976
engcom-Kilo Jul 27, 2020
d64c0e7
Merge branch '2.4-develop' into fix-26976
engcom-Kilo Aug 3, 2020
7c6b7f7
Update StorefrontCustomerCheckoutWithCustomerGroupTest.xml
lenaorobei Aug 19, 2020
74c0c92
Merge branch '2.4-develop' into fix-26976
lenaorobei Aug 19, 2020
818a7fa
Annotations have been updated.
engcom-Hotel Sep 1, 2020
0d97464
Merge branch '2.4-develop' into fix-26976
engcom-Hotel Sep 1, 2020
50bf2f5
Merge branch '2.4-develop' into fix-26976
engcom-Hotel Sep 3, 2020
a8ffe0b
Merge branch '2.4-develop' into fix-26976
engcom-Hotel Sep 10, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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="StorefrontCustomerCheckoutWithCustomerGroupTest">
<annotations>
<features value="Customer Checkout"/>
<stories value="Customer checkout with Customer Group assigned"/>
<title value="Place order by Customer with Customer Group assigned"/>
<description value="Customer Group should be assigned to Order when setting Auto Group Assign is enabled for Customer"/>
<testCaseId value="MC-37259"/>
<severity value="MAJOR"/>
<group value="checkout"/>
<group value="customer"/>
</annotations>
<before>

<magentoCLI command="config:set customer/create_account/auto_group_assign 1" stepKey="enableAutoGroupAssign"/>

<createData entity="SimpleSubCategory" stepKey="createCategory"/>
<createData entity="SimpleProduct" stepKey="createSimpleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>

<createData entity="Simple_US_Customer" stepKey="createCustomer"/>

<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>

<actionGroup ref="AdminUpdateCustomerGroupByEmailActionGroup" stepKey="updateCustomerGroup">
<argument name="emailAddress" value="$$createCustomer.email$$"/>
<argument name="customerGroup" value="Retail"/>
</actionGroup>

</before>
<after>
<magentoCLI command="config:set customer/create_account/auto_group_assign 0" stepKey="disableAutoGroupAssign"/>

<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/>
<deleteData createDataKey="createCustomer" stepKey="deleteUsCustomer"/>
<actionGroup ref="AdminClearCustomersFiltersActionGroup" stepKey="resetCustomerFilters"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
<deleteData createDataKey="createCategory" stepKey="deleteSimpleCategory"/>
</after>

<actionGroup ref="LoginToStorefrontActionGroup" stepKey="storefrontCustomerLogin">
<argument name="Customer" value="$$createCustomer$$"/>
</actionGroup>

<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage">
<argument name="category" value="$$createCategory$$"/>
</actionGroup>

<waitForPageLoad stepKey="waitForCatalogPageLoad"/>

<actionGroup ref="StorefrontAddCategoryProductToCartActionGroup" stepKey="addProductToCart">
<argument name="product" value="$$createSimpleProduct$$"/>
<argument name="productCount" value="CONST.one"/>
</actionGroup>

<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
<actionGroup ref="CheckoutSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRate"/>
<actionGroup ref="StorefrontCheckoutForwardFromShippingStepActionGroup" stepKey="goToReview"/>
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyOrder"/>
<actionGroup ref="CheckoutPlaceOrderActionGroup" stepKey="clickOnPlaceOrder">
<argument name="orderNumberMessage" value="CONST.successCheckoutOrderNumberMessage"/>
<argument name="emailYouMessage" value="CONST.successCheckoutEmailYouMessage"/>
</actionGroup>

<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="orderNumber"/>

<actionGroup ref="OpenOrderByIdActionGroup" stepKey="addFilterToGridAndOpenOrder">
<argument name="orderId" value="{$orderNumber}"/>
</actionGroup>

<see selector="{{AdminOrderDetailsInformationSection.orderStatus}}" userInput="Pending" stepKey="verifyOrderStatus"/>
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="Customer" stepKey="verifyAccountInformation"/>
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="$$createCustomer.email$$" stepKey="verifyCustomerEmail"/>
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="Retail" stepKey="verifyCustomerGroup"/>
<see selector="{{AdminOrderDetailsInformationSection.billingAddress}}" userInput="{{US_Address_TX.street[0]}}" stepKey="verifyBillingAddress"/>
<see selector="{{AdminOrderDetailsInformationSection.shippingAddress}}" userInput="{{US_Address_TX.street[0]}}" stepKey="verifyShippingAddress"/>
<see selector="{{AdminOrderDetailsInformationSection.itemsOrdered}}" userInput="$$createSimpleProduct.name$$" stepKey="verifyProductName"/>

</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)

$groupId = null;
if (empty($customerVatNumber) || false == $this->customerVat->isCountryInEU($customerCountryCode)) {
$groupId = $customer->getId() ? $this->groupManagement->getDefaultGroup(
$storeId
)->getId() : $this->groupManagement->getNotLoggedInGroup()->getId();
$groupId = $customer->getId() ? $quote->getCustomerGroupId() :
$this->groupManagement->getNotLoggedInGroup()->getId();
} else {
// Magento always has to emulate group even if customer uses default billing/shipping address
$groupId = $this->customerVat->getCustomerGroupIdBasedOnVatNumber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Api\Data\GroupInterface;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Helper\Address;
use Magento\Customer\Helper\Address as CustomerAddress;
use Magento\Customer\Model\Session;
use Magento\Customer\Model\Vat;
use Magento\Framework\Event\Observer;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
use Magento\Quote\Api\Data\ShippingInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver;
use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class CollectTotalsTest
Expand Down Expand Up @@ -124,7 +125,7 @@ protected function setUp(): void
true,
['getStoreId', 'getCustomAttribute', 'getId', '__wakeup']
);
$this->customerAddressMock = $this->createMock(Address::class);
$this->customerAddressMock = $this->createMock(CustomerAddress::class);
$this->customerVatMock = $this->createMock(Vat::class);
$this->customerDataFactoryMock = $this->getMockBuilder(CustomerInterfaceFactory::class)
->addMethods(['mergeDataObjectWithArray'])
Expand Down Expand Up @@ -174,6 +175,7 @@ protected function setUp(): void

$shippingAssignmentMock = $this->getMockForAbstractClass(ShippingAssignmentInterface::class);
$shippingMock = $this->getMockForAbstractClass(ShippingInterface::class);

$shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
$shippingMock->expects($this->once())->method('getAddress')->willReturn($this->quoteAddressMock);

Expand All @@ -185,7 +187,6 @@ protected function setUp(): void
$this->quoteMock->expects($this->any())
->method('getCustomer')
->willReturn($this->customerMock);

$this->addressRepository = $this->getMockForAbstractClass(AddressRepositoryInterface::class);
$this->customerSession = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -266,26 +267,20 @@ public function testDispatchWithDefaultCustomerGroupId()
->willReturn('customerCountryCode');
$this->quoteAddressMock->expects($this->once())->method('getVatId')->willReturn(null);

$this->quoteMock->expects($this->once())
$this->quoteMock->expects($this->exactly(2))
->method('getCustomerGroupId')
->willReturn('customerGroupId');
$this->customerMock->expects($this->once())->method('getId')->willReturn('1');
$this->groupManagementMock->expects($this->once())
->method('getDefaultGroup')
->willReturn($this->groupInterfaceMock);
$this->groupInterfaceMock->expects($this->once())
->method('getId')->willReturn('defaultCustomerGroupId');

/** Assertions */
$this->quoteAddressMock->expects($this->once())
->method('setPrevQuoteCustomerGroupId')
->with('customerGroupId');
$this->quoteMock->expects($this->once())->method('setCustomerGroupId')->with('defaultCustomerGroupId');
$this->customerDataFactoryMock->expects($this->any())
->method('create')
->willReturn($this->customerMock);

$this->quoteMock->expects($this->once())->method('setCustomer')->with($this->customerMock);

/** SUT execution */
$this->model->execute($this->observerMock);
}
Expand Down Expand Up @@ -343,7 +338,7 @@ public function testDispatchWithAddressCustomerVatIdAndCountryId()
$customerVat = "123123123";
$defaultShipping = 1;

$customerAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
$customerAddress = $this->createMock(Address::class);
$customerAddress->expects($this->any())
->method("getVatId")
->willReturn($customerVat);
Expand Down Expand Up @@ -379,8 +374,8 @@ public function testDispatchWithEmptyShippingAddress()
$customerCountryCode = "DE";
$customerVat = "123123123";
$defaultShipping = 1;

$customerAddress = $this->getMockForAbstractClass(AddressInterface::class);

$customerAddress->expects($this->once())
->method("getCountryId")
->willReturn($customerCountryCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ public function testChangeQuoteCustomerGroupIdForCustomerWithEnabledAutomaticGro
);
$this->model->execute($eventObserver);

$this->assertEquals(1, $quote->getCustomer()->getGroupId());
$this->assertEquals(2, $quote->getCustomer()->getGroupId());
}
}