11
11
use Magento \Eav \Model \Config ;
12
12
use Magento \Eav \Model \Entity \Type ;
13
13
use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
14
+ use Magento \Store \Model \Store ;
14
15
use Magento \Store \Model \StoreManagerInterface ;
15
16
use Magento \Ui \Component \Form \Field ;
16
17
use Magento \Ui \DataProvider \EavValidationRules ;
18
+ use Magento \Catalog \Model \CategoryFactory ;
19
+ use Magento \Framework \Exception \NoSuchEntityException ;
17
20
18
21
/**
19
22
* Class DataProvider
22
25
*/
23
26
class DataProvider extends \Magento \Ui \DataProvider \AbstractDataProvider
24
27
{
28
+ /**
29
+ * @var string
30
+ */
31
+ protected $ requestScopeFieldName = 'store ' ;
32
+
25
33
/**
26
34
* @var array
27
35
*/
@@ -86,8 +94,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
86
94
/**
87
95
* @var \Magento\Framework\App\RequestInterface
88
96
*/
89
- private $ request ;
90
-
97
+ protected $ request ;
91
98
92
99
/**
93
100
* @var Config
@@ -100,7 +107,12 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
100
107
private $ storeManager ;
101
108
102
109
/**
103
- * Constructor
110
+ * @var CategoryFactory
111
+ */
112
+ private $ categoryFactory ;
113
+
114
+ /**
115
+ * DataProvider constructor
104
116
*
105
117
* @param string $name
106
118
* @param string $primaryFieldName
@@ -111,9 +123,9 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
111
123
* @param \Magento\Framework\Registry $registry
112
124
* @param Config $eavConfig
113
125
* @param \Magento\Framework\App\RequestInterface $request
126
+ * @param CategoryFactory $categoryFactory
114
127
* @param array $meta
115
128
* @param array $data
116
- * @throws \Magento\Framework\Exception\LocalizedException
117
129
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
118
130
*/
119
131
public function __construct (
@@ -126,6 +138,7 @@ public function __construct(
126
138
\Magento \Framework \Registry $ registry ,
127
139
Config $ eavConfig ,
128
140
\Magento \Framework \App \RequestInterface $ request ,
141
+ CategoryFactory $ categoryFactory ,
129
142
array $ meta = [],
130
143
array $ data = []
131
144
) {
@@ -136,6 +149,7 @@ public function __construct(
136
149
$ this ->registry = $ registry ;
137
150
$ this ->storeManager = $ storeManager ;
138
151
$ this ->request = $ request ;
152
+ $ this ->categoryFactory = $ categoryFactory ;
139
153
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data );
140
154
$ this ->meta = $ this ->prepareMeta ($ this ->meta );
141
155
}
@@ -282,7 +296,7 @@ protected function addUseConfigSettings($categoryData)
282
296
protected function addUseDefaultSettings ($ category , $ categoryData )
283
297
{
284
298
if ($ category ->getExistsStoreValueFlag ('url_key ' ) ||
285
- $ category ->getStoreId () === \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
299
+ $ category ->getStoreId () === Store::DEFAULT_STORE_ID
286
300
) {
287
301
$ categoryData ['use_default ' ]['url_key ' ] = false ;
288
302
} else {
@@ -296,10 +310,25 @@ protected function addUseDefaultSettings($category, $categoryData)
296
310
* Get current category
297
311
*
298
312
* @return Category
313
+ * @throws NoSuchEntityException
299
314
*/
300
315
public function getCurrentCategory ()
301
316
{
302
- return $ this ->registry ->registry ('category ' );
317
+ $ category = $ this ->registry ->registry ('category ' );
318
+ if ($ category ) {
319
+ return $ category ;
320
+ }
321
+ $ requestId = $ this ->request ->getParam ($ this ->requestFieldName );
322
+ $ requestScope = $ this ->request ->getParam ($ this ->requestScopeFieldName , Store::DEFAULT_STORE_ID );
323
+ if ($ requestId ) {
324
+ $ category = $ this ->categoryFactory ->create ();
325
+ $ category ->setStoreId ($ requestScope );
326
+ $ category ->load ($ requestId );
327
+ if (!$ category ->getId ()) {
328
+ throw NoSuchEntityException::singleField ('id ' , $ requestId );
329
+ }
330
+ }
331
+ return $ category ;
303
332
}
304
333
305
334
/**
@@ -349,7 +378,6 @@ protected function filterFields($categoryData)
349
378
public function getDefaultMetaData ($ result )
350
379
{
351
380
$ result ['parent ' ]['default ' ] = (int )$ this ->request ->getParam ('parent ' );
352
- $ result ['is_anchor ' ]['default ' ] = false ;
353
381
$ result ['use_config.available_sort_by ' ]['default ' ] = true ;
354
382
$ result ['use_config.default_sort_by ' ]['default ' ] = true ;
355
383
$ result ['use_config.filter_price_range ' ]['default ' ] = true ;
@@ -418,14 +446,14 @@ protected function getFieldsMap()
418
446
[
419
447
'custom_use_parent_settings ' ,
420
448
'custom_apply_to_products ' ,
449
+ 'custom_design ' ,
421
450
'page_layout ' ,
422
451
'custom_layout_update ' ,
423
452
],
424
453
'schedule_design_update ' =>
425
454
[
426
455
'custom_design_from ' ,
427
456
'custom_design_to ' ,
428
- 'custom_design ' ,
429
457
],
430
458
'category_view_optimization ' =>
431
459
[
0 commit comments