7
7
namespace Magento \Backend \Controller \Adminhtml \System \Store ;
8
8
9
9
use Magento \Framework \App \Action \HttpPostActionInterface as HttpPostActionInterface ;
10
+ use Magento \Store \Model \Group as StoreGroup ;
11
+ use Magento \Store \Model \Store ;
12
+ use Magento \Framework \Exception \LocalizedException ;
10
13
11
14
/**
12
15
* Class Save
@@ -33,6 +36,17 @@ private function processWebsiteSave($postData)
33
36
$ websiteModel ->setId (null );
34
37
}
35
38
39
+ $ groupModel = $ this ->_objectManager ->create (StoreGroup::class);
40
+ $ groupModel ->load ($ websiteModel ->getDefaultGroupId ());
41
+ $ storeModel = $ this ->_objectManager ->create (Store::class);
42
+ $ storeModel ->load ($ groupModel ->getDefaultStoreId ());
43
+
44
+ if ($ websiteModel ->getIsDefault () && !$ storeModel ->isActive ()) {
45
+ throw new LocalizedException (
46
+ __ ('Please enable your Store View before using this Web Site as Default ' )
47
+ );
48
+ }
49
+
36
50
$ websiteModel ->save ();
37
51
$ this ->messageManager ->addSuccessMessage (__ ('You saved the website. ' ));
38
52
@@ -43,13 +57,13 @@ private function processWebsiteSave($postData)
43
57
* Process Store model save
44
58
*
45
59
* @param array $postData
46
- * @throws \Magento\Framework\Exception\ LocalizedException
60
+ * @throws LocalizedException
47
61
* @return array
48
62
*/
49
63
private function processStoreSave ($ postData )
50
64
{
51
- /** @var \Magento\Store\Model\ Store $storeModel */
52
- $ storeModel = $ this ->_objectManager ->create (\ Magento \ Store \ Model \ Store::class);
65
+ /** @var Store $storeModel */
66
+ $ storeModel = $ this ->_objectManager ->create (Store::class);
53
67
$ postData ['store ' ]['name ' ] = $ this ->filterManager ->removeTags ($ postData ['store ' ]['name ' ]);
54
68
if ($ postData ['store ' ]['store_id ' ]) {
55
69
$ storeModel ->load ($ postData ['store ' ]['store_id ' ]);
@@ -59,13 +73,13 @@ private function processStoreSave($postData)
59
73
$ storeModel ->setId (null );
60
74
}
61
75
$ groupModel = $ this ->_objectManager ->create (
62
- \ Magento \ Store \ Model \Group ::class
76
+ StoreGroup ::class
63
77
)->load (
64
78
$ storeModel ->getGroupId ()
65
79
);
66
80
$ storeModel ->setWebsiteId ($ groupModel ->getWebsiteId ());
67
81
if (!$ storeModel ->isActive () && $ storeModel ->isDefault ()) {
68
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
82
+ throw new LocalizedException (
69
83
__ ('The default store cannot be disabled ' )
70
84
);
71
85
}
@@ -79,14 +93,14 @@ private function processStoreSave($postData)
79
93
* Process StoreGroup model save
80
94
*
81
95
* @param array $postData
82
- * @throws \Magento\Framework\Exception\ LocalizedException
96
+ * @throws LocalizedException
83
97
* @return array
84
98
*/
85
99
private function processGroupSave ($ postData )
86
100
{
87
101
$ postData ['group ' ]['name ' ] = $ this ->filterManager ->removeTags ($ postData ['group ' ]['name ' ]);
88
- /** @var \Magento\Store\Model\Group $groupModel */
89
- $ groupModel = $ this ->_objectManager ->create (\ Magento \ Store \ Model \Group ::class);
102
+ /** @var StoreGroup $groupModel */
103
+ $ groupModel = $ this ->_objectManager ->create (StoreGroup ::class);
90
104
if ($ postData ['group ' ]['group_id ' ]) {
91
105
$ groupModel ->load ($ postData ['group ' ]['group_id ' ]);
92
106
}
@@ -95,10 +109,11 @@ private function processGroupSave($postData)
95
109
$ groupModel ->setId (null );
96
110
}
97
111
if (!$ this ->isSelectedDefaultStoreActive ($ postData , $ groupModel )) {
98
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
112
+ throw new LocalizedException (
99
113
__ ('An inactive store view cannot be saved as default store view ' )
100
114
);
101
115
}
116
+
102
117
$ groupModel ->save ();
103
118
$ this ->messageManager ->addSuccessMessage (__ ('You saved the store. ' ));
104
119
@@ -135,7 +150,7 @@ public function execute()
135
150
}
136
151
$ redirectResult ->setPath ('adminhtml/*/ ' );
137
152
return $ redirectResult ;
138
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
153
+ } catch (LocalizedException $ e ) {
139
154
$ this ->messageManager ->addErrorMessage ($ e ->getMessage ());
140
155
$ this ->_getSession ()->setPostData ($ postData );
141
156
} catch (\Exception $ e ) {
@@ -156,10 +171,10 @@ public function execute()
156
171
* Verify if selected default store is active
157
172
*
158
173
* @param array $postData
159
- * @param \Magento\Store\Model\Group $groupModel
174
+ * @param StoreGroup $groupModel
160
175
* @return bool
161
176
*/
162
- private function isSelectedDefaultStoreActive (array $ postData , \ Magento \ Store \ Model \ Group $ groupModel )
177
+ private function isSelectedDefaultStoreActive (array $ postData , StoreGroup $ groupModel )
163
178
{
164
179
if (!empty ($ postData ['group ' ]['default_store_id ' ])) {
165
180
$ defaultStoreId = $ postData ['group ' ]['default_store_id ' ];
0 commit comments