Skip to content

Commit 60ca1f2

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-356' into PR_L3_18_04_2022
2 parents 5f875f5 + 76fdbcb commit 60ca1f2

File tree

6 files changed

+135
-19
lines changed

6 files changed

+135
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCreateCustomerInSecondWebsiteWithGlobalAccountSharingEnabled">
12+
<annotations>
13+
<features value="Customer"/>
14+
<title value="Admin create customer in second website when global account sharing is enabled"/>
15+
<stories value="Admin create customer in second website when global account sharing is enabled"/>
16+
<testCaseId value="AC-2542"/>
17+
<useCaseId value="ACP2E-356"/>
18+
<severity value="MAJOR"/>
19+
<description value="When Admin tries to create a customer in second website with the global account sharing is enabled, then Admin should be able to do so."/>
20+
<group value="customer"/>
21+
</annotations>
22+
<before>
23+
<createData entity="CustomerAccountSharingGlobal" stepKey="setConfigCustomerAccountToGlobal"/>
24+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/>
25+
</before>
26+
<after>
27+
<!--Delete custom website-->
28+
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteWebsite">
29+
<argument name="websiteName" value="{{secondCustomWebsite.name}}"/>
30+
</actionGroup>
31+
<actionGroup ref="DeleteCustomerByEmailActionGroup" stepKey="deleteCustomer">
32+
<argument name="email" value="{{CustomerEntityOne.email}}"/>
33+
</actionGroup>
34+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetGrid"/>
35+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
36+
<createData entity="CustomerAccountSharingDefault" stepKey="setConfigCustomerAccountDefault"/>
37+
</after>
38+
<!-- Create second website -->
39+
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createSecondWebsite">
40+
<argument name="newWebsiteName" value="{{secondCustomWebsite.name}}"/>
41+
<argument name="websiteCode" value="{{secondCustomWebsite.code}}"/>
42+
</actionGroup>
43+
<!-- Create second store -->
44+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createSecondStoreGroup">
45+
<argument name="website" value="{{secondCustomWebsite.name}}"/>
46+
<argument name="storeGroupName" value="{{SecondStoreGroupUnique.name}}"/>
47+
<argument name="storeGroupCode" value="{{SecondStoreGroupUnique.code}}"/>
48+
</actionGroup>
49+
<!-- Create second store view -->
50+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondStoreView">
51+
<argument name="StoreGroup" value="SecondStoreGroupUnique"/>
52+
<argument name="customStore" value="SecondStoreUnique"/>
53+
</actionGroup>
54+
<!--Open New Customer Page -->
55+
<actionGroup ref="AdminNavigateNewCustomerActionGroup" stepKey="waitToCustomerPageLoad"/>
56+
<!--Change customer website to "Second Website"-->
57+
<actionGroup ref="AdminUpdateCustomerWebsiteInCustomerInformationPageActionGroup" stepKey="updateCustomerWebsite">
58+
<argument name="websiteName" value="{{secondCustomWebsite.name}}"/>
59+
</actionGroup>
60+
<!--Verify that "Second Website" is selected in website selector-->
61+
<seeOptionIsSelected selector="{{AdminCustomerAccountInformationSection.associateToWebsite}}" userInput="{{secondCustomWebsite.name}}" stepKey="assertThatSecondWebsiteIsSelected"/>
62+
<fillField userInput="{{CustomerEntityOne.firstname}}" selector="{{AdminCustomerAccountInformationSection.firstName}}" stepKey="fillFirstName"/>
63+
<fillField userInput="{{CustomerEntityOne.lastname}}" selector="{{AdminCustomerAccountInformationSection.lastName}}" stepKey="fillLastName"/>
64+
<fillField userInput="{{CustomerEntityOne.email}}" selector="{{AdminCustomerAccountInformationSection.email}}" stepKey="fillEmail"/>
65+
<click selector="{{AdminCustomerMainActionsSection.saveButton}}" stepKey="saveCustomer"/>
66+
<seeElement selector="{{AdminCustomerMessagesSection.successMessage}}" stepKey="assertSuccessMessage"/>
67+
</test>
68+
</tests>

app/code/Magento/Customer/Test/Unit/ViewModel/Customer/StoreTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Store\Model\Store;
1616
use Magento\Store\Model\StoreManagerInterface;
1717
use Magento\Store\Model\System\Store as SystemStore;
18+
use Magento\Store\Model\Website;
1819
use PHPUnit\Framework\TestCase;
1920

2021
/**
@@ -90,6 +91,10 @@ public function testToOptionArray(array $options, bool $isWebsiteScope, bool $is
9091
$this->store->method('getWebsiteId')
9192
->willReturn(1);
9293

94+
$websiteMock = $this->createPartialMock(Website::class, ['getId']);
95+
$websiteMock->method('getId')->willReturn(1);
96+
$this->systemStore->method('getWebsiteCollection')->willReturn([$websiteMock]);
97+
9398
if ($isCustomerDataInSession) {
9499
$this->dataPersistor->method('get')
95100
->with('customer')

app/code/Magento/Customer/Test/Unit/ViewModel/Customer/WebsiteTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1414
use Magento\Store\Model\System\Store as SystemStore;
1515
use PHPUnit\Framework\TestCase;
16+
use Magento\Store\Model\Website;
17+
use Magento\Store\Model\Store;
1618

1719
/**
1820
* Test for customer's website view model
@@ -49,6 +51,20 @@ protected function setUp(): void
4951
'scopeConfig' => $this->scopeConfig
5052
]
5153
);
54+
$websiteMock1 = $this->createPartialMock(Website::class, ['getId', 'getDefaultStore']);
55+
$websiteMock2 = $this->createPartialMock(Website::class, ['getId', 'getDefaultStore']);
56+
$storeMock1 = $this->createPartialMock(Store::class, ['getId']);
57+
$storeMock2 = $this->createPartialMock(Store::class, ['getId']);
58+
59+
$storeMock1->method('getId')->willReturn('1');
60+
$websiteMock1->method('getId')->willReturn('1');
61+
$websiteMock1->method('getDefaultStore')->willReturn($storeMock1);
62+
63+
$storeMock2->method('getId')->willReturn('2');
64+
$websiteMock2->method('getId')->willReturn('2');
65+
$websiteMock2->method('getDefaultStore')->willReturn($storeMock2);
66+
67+
$this->systemStore->method('getWebsiteCollection')->willReturn([$websiteMock1, $websiteMock2]);
5268
}
5369

5470
/**
@@ -92,11 +108,13 @@ public function dataProviderOptionsArray(): array
92108
'label' => 'Main Website',
93109
'value' => '1',
94110
'group_id' => '1',
111+
'default_store_view_id' => '1',
95112
],
96113
[
97114
'label' => 'Second Website',
98115
'value' => '2',
99116
'group_id' => '1',
117+
'default_store_view_id' => '2',
100118
],
101119
],
102120
],

app/code/Magento/Customer/ViewModel/Customer/Store.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,22 @@ private function getStoreOptions(): array
109109
private function getStoreOptionsWithCurrentWebsiteId(): array
110110
{
111111
$options = $this->systemStore->getStoreValuesForForm();
112-
113-
if (!empty($this->dataPersistor->get('customer')['account'])) {
114-
$currentWebsiteId = (string)$this->dataPersistor->get('customer')['account']['website_id'];
115-
} else {
116-
$defaultStore = $this->storeManager->getDefaultStoreView();
117-
if (!$defaultStore) {
118-
$stores = $this->storeManager->getStores();
119-
$defaultStore = array_shift($stores);
120-
}
121-
$currentWebsiteId = $defaultStore->getWebsiteId();
122-
}
123-
124-
foreach ($options as $key => $option) {
125-
$options[$key]['website_id'] = $currentWebsiteId;
126-
if (is_array($option['value']) && !empty($option['value'])) {
127-
foreach ($option['value'] as $storeViewKey => $storeView) {
128-
$storeView['website_id'] = $currentWebsiteId;
129-
$options[$key]['value'][$storeViewKey] = $storeView;
112+
$websites = $this->systemStore->getWebsiteCollection();
113+
$allOptions = [];
114+
115+
foreach ($websites as $website) {
116+
foreach ($options as $key => $option) {
117+
$options[$key]['website_id'] = $website->getId();
118+
if (is_array($option['value']) && !empty($option['value'])) {
119+
foreach ($option['value'] as $storeViewKey => $storeView) {
120+
$storeView['website_id'] = $website->getId();
121+
$options[$key]['value'][$storeViewKey] = $storeView;
122+
}
130123
}
124+
$allOptions[] = $options[$key];
131125
}
132126
}
133127

134-
return $options;
128+
return $allOptions;
135129
}
136130
}

app/code/Magento/Customer/ViewModel/Customer/Website.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,34 @@ private function getWebsiteOptions(): array
6767
$websiteId
6868
);
6969
$options[$key]['group_id'] = $groupId;
70+
$options[$key]['default_store_view_id'] = $this->getWebsiteDefaultStoreViewId($websiteId);
7071
}
7172

7273
return $options;
7374
}
75+
76+
/**
77+
* Get Default store view id by Website id
78+
*
79+
* @param string $websiteId
80+
* @return mixed
81+
*/
82+
private function getWebsiteDefaultStoreViewId($websiteId)
83+
{
84+
$defaultStoreViewId = null;
85+
$websites = $this->systemStore->getWebsiteCollection();
86+
87+
foreach ($websites as $website) {
88+
if ($website->getId() === $websiteId) {
89+
$defaultStore = $website->getDefaultStore();
90+
// Check if the default store exist
91+
if ($defaultStore) {
92+
$defaultStoreViewId = $defaultStore->getId();
93+
}
94+
break;
95+
}
96+
}
97+
98+
return $defaultStoreViewId;
99+
}
74100
}

app/code/Magento/Customer/view/adminhtml/web/js/form/element/website.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ define([
1717
*/
1818
onUpdate: function (value) {
1919
var groupIdFieldKey = 'group_id',
20+
sendEmailStoreIdFieldKey = 'sendemail_store_id',
2021
groupId = registry.get('index = ' + groupIdFieldKey),
22+
sendEmailStoreId = registry.get('index = ' + sendEmailStoreIdFieldKey),
2123
option = this.getOption(value);
2224

2325
if (groupId) {
2426
groupId.value(option[groupIdFieldKey]);
2527
}
2628

29+
if (sendEmailStoreId && option['default_store_view_id']) {
30+
sendEmailStoreId.value(option['default_store_view_id']);
31+
}
2732
return this._super();
2833
}
2934
});

0 commit comments

Comments
 (0)