Skip to content

Commit 5881e2b

Browse files
author
Mohan Ahuja
committed
ACP2E-356: Cannot create a new customer from Admin if Customer Sharing setting is set to Global
- Implemented new solution as per request from Viktor to show all the store views for all websites. - Also, selected default store view of selected website.
1 parent 412678e commit 5881e2b

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

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 $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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ define([
2424
groupId.value(option[groupIdFieldKey]);
2525
}
2626

27+
if (option['default_store_view_id']) {
28+
document.getElementsByName("customer[sendemail_store_id]")[0].value = option['default_store_view_id'];
29+
}
2730
return this._super();
2831
}
2932
});

0 commit comments

Comments
 (0)