9
9
10
10
/**
11
11
* Class Save
12
- *
12
+ *
13
13
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
14
*/
15
15
class Save extends \Magento \Catalog \Controller \Adminhtml \Category
@@ -34,15 +34,13 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
34
34
* @var array
35
35
*/
36
36
protected $ stringToBoolInputs = [
37
- 'general ' => [
38
- 'custom_use_parent_settings ' ,
39
- 'custom_apply_to_products ' ,
40
- 'is_active ' ,
41
- 'include_in_menu ' ,
42
- 'is_anchor ' ,
43
- 'use_default ' => ['url_key ' ],
44
- 'use_config ' => ['available_sort_by ' , 'filter_price_range ' , 'default_sort_by ' ]
45
- ]
37
+ 'custom_use_parent_settings ' ,
38
+ 'custom_apply_to_products ' ,
39
+ 'is_active ' ,
40
+ 'include_in_menu ' ,
41
+ 'is_anchor ' ,
42
+ 'use_default ' => ['url_key ' ],
43
+ 'use_config ' => ['available_sort_by ' , 'filter_price_range ' , 'default_sort_by ' ]
46
44
];
47
45
48
46
/**
@@ -110,15 +108,18 @@ public function execute()
110
108
}
111
109
112
110
$ data ['general ' ] = $ this ->getRequest ()->getPostValue ();
113
- $ isNewCategory = !isset ($ data ['general ' ]['entity_id ' ]);
114
- $ data = $ this ->stringToBoolConverting ($ data );
115
- $ data = $ this ->imagePreprocessing ($ data );
116
- $ storeId = isset ($ data ['general ' ]['store_id ' ]) ? $ data ['general ' ]['store_id ' ] : null ;
111
+ $ categoryPostData = $ data ['general ' ];
112
+
113
+ $ isNewCategory = !isset ($ categoryPostData ['entity_id ' ]);
114
+ $ categoryPostData = $ this ->stringToBoolConverting ($ categoryPostData );
115
+ $ categoryPostData = $ this ->imagePreprocessing ($ categoryPostData );
116
+ $ categoryPostData = $ this ->dateTimePreprocessing ($ category , $ categoryPostData );
117
+ $ storeId = isset ($ categoryPostData ['store_id ' ]) ? $ categoryPostData ['store_id ' ] : null ;
117
118
$ store = $ this ->storeManager ->getStore ($ storeId );
118
119
$ this ->storeManager ->setCurrentStore ($ store ->getCode ());
119
- $ parentId = isset ($ data [ ' general ' ][ ' parent ' ]) ? $ data [ ' general ' ] ['parent ' ] : null ;
120
- if ($ data [ ' general ' ] ) {
121
- $ category ->addData ($ this ->_filterCategoryPostData ($ data [ ' general ' ] ));
120
+ $ parentId = isset ($ categoryPostData [ ' parent ' ]) ? $ categoryPostData ['parent ' ] : null ;
121
+ if ($ categoryPostData ) {
122
+ $ category ->addData ($ this ->_filterCategoryPostData ($ categoryPostData ));
122
123
if ($ isNewCategory ) {
123
124
$ parentCategory = $ this ->getParentCategory ($ parentId , $ storeId );
124
125
$ category ->setPath ($ parentCategory ->getPath ());
@@ -128,10 +129,10 @@ public function execute()
128
129
/**
129
130
* Process "Use Config Settings" checkboxes
130
131
*/
131
- $ generalPost = $ data [ ' general ' ];
132
+
132
133
$ useConfig = [];
133
- if (isset ($ generalPost ['use_config ' ]) && !empty ($ generalPost ['use_config ' ])) {
134
- foreach ($ generalPost ['use_config ' ] as $ attributeCode => $ attributeValue ) {
134
+ if (isset ($ categoryPostData ['use_config ' ]) && !empty ($ categoryPostData ['use_config ' ])) {
135
+ foreach ($ categoryPostData ['use_config ' ] as $ attributeCode => $ attributeValue ) {
135
136
if ($ attributeValue ) {
136
137
$ useConfig [] = $ attributeCode ;
137
138
$ category ->setData ($ attributeCode , null );
@@ -141,11 +142,11 @@ public function execute()
141
142
142
143
$ category ->setAttributeSetId ($ category ->getDefaultAttributeSetId ());
143
144
144
- if (isset ($ data [ ' general ' ] ['category_products ' ])
145
- && is_string ($ data [ ' general ' ] ['category_products ' ])
145
+ if (isset ($ categoryPostData ['category_products ' ])
146
+ && is_string ($ categoryPostData ['category_products ' ])
146
147
&& !$ category ->getProductsReadonly ()
147
148
) {
148
- $ products = json_decode ($ data [ ' general ' ] ['category_products ' ], true );
149
+ $ products = json_decode ($ categoryPostData ['category_products ' ], true );
149
150
$ category ->setPostedProducts ($ products );
150
151
}
151
152
$ this ->_eventManager ->dispatch (
@@ -156,8 +157,8 @@ public function execute()
156
157
/**
157
158
* Check "Use Default Value" checkboxes values
158
159
*/
159
- if (isset ($ generalPost ['use_default ' ]) && !empty ($ generalPost ['use_default ' ])) {
160
- foreach ($ generalPost ['use_default ' ] as $ attributeCode => $ attributeValue ) {
160
+ if (isset ($ categoryPostData ['use_default ' ]) && !empty ($ categoryPostData ['use_default ' ])) {
161
+ foreach ($ categoryPostData ['use_default ' ] as $ attributeCode => $ attributeValue ) {
161
162
if ($ attributeValue ) {
162
163
$ category ->setData ($ attributeCode , null );
163
164
}
@@ -197,15 +198,15 @@ public function execute()
197
198
} catch (\Magento \Framework \Exception \AlreadyExistsException $ e ) {
198
199
$ this ->messageManager ->addError ($ e ->getMessage ());
199
200
$ this ->_objectManager ->get (\Psr \Log \LoggerInterface::class)->critical ($ e );
200
- $ this ->_getSession ()->setCategoryData ($ data );
201
+ $ this ->_getSession ()->setCategoryData ($ categoryPostData );
201
202
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
202
203
$ this ->messageManager ->addError ($ e ->getMessage ());
203
204
$ this ->_objectManager ->get (\Psr \Log \LoggerInterface::class)->critical ($ e );
204
- $ this ->_getSession ()->setCategoryData ($ data );
205
+ $ this ->_getSession ()->setCategoryData ($ categoryPostData );
205
206
} catch (\Exception $ e ) {
206
207
$ this ->messageManager ->addError (__ ('Something went wrong while saving the category. ' ));
207
208
$ this ->_objectManager ->get (\Psr \Log \LoggerInterface::class)->critical ($ e );
208
- $ this ->_getSession ()->setCategoryData ($ data );
209
+ $ this ->_getSession ()->setCategoryData ($ categoryPostData );
209
210
}
210
211
}
211
212
@@ -248,9 +249,9 @@ public function execute()
248
249
*/
249
250
public function imagePreprocessing ($ data )
250
251
{
251
- if (empty ($ data ['general ' ][ ' image ' ])) {
252
- unset($ data ['general ' ][ ' image ' ]);
253
- $ data ['general ' ][ ' image ' ]['delete ' ] = true ;
252
+ if (empty ($ data ['image ' ])) {
253
+ unset($ data ['image ' ]);
254
+ $ data ['image ' ]['delete ' ] = true ;
254
255
}
255
256
return $ data ;
256
257
}
0 commit comments