12
12
use Magento \Catalog \Model \Attribute \ScopeOverriddenValue ;
13
13
use Magento \Catalog \Model \Category ;
14
14
use Magento \Catalog \Model \Category \Attribute \Backend \Image as ImageBackendModel ;
15
+ use Magento \Catalog \Model \Category \Attribute \Backend \LayoutUpdate ;
15
16
use Magento \Catalog \Model \CategoryFactory ;
16
17
use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
17
18
use Magento \Catalog \Model \ResourceModel \Eav \Attribute as EavAttribute ;
20
21
use Magento \Eav \Model \Entity \Attribute \Source \SpecificSourceInterface ;
21
22
use Magento \Eav \Model \Entity \Type ;
22
23
use Magento \Framework \App \ObjectManager ;
24
+ use Magento \Framework \App \RequestInterface ;
25
+ use Magento \Framework \Exception \LocalizedException ;
23
26
use Magento \Framework \Exception \NoSuchEntityException ;
24
- use Magento \Framework \Filesystem ;
27
+ use Magento \Framework \Registry ;
25
28
use Magento \Framework \Stdlib \ArrayManager ;
26
29
use Magento \Framework \Stdlib \ArrayUtils ;
27
30
use Magento \Store \Model \Store ;
30
33
use Magento \Ui \DataProvider \EavValidationRules ;
31
34
use Magento \Ui \DataProvider \Modifier \PoolInterface ;
32
35
use Magento \Framework \AuthorizationInterface ;
36
+ use Magento \Ui \DataProvider \ModifierPoolDataProvider ;
33
37
34
38
/**
35
39
* Category form data provider.
39
43
* @SuppressWarnings(PHPMD.TooManyFields)
40
44
* @since 101.0.0
41
45
*/
42
- class DataProvider extends \ Magento \ Ui \ DataProvider \ ModifierPoolDataProvider
46
+ class DataProvider extends ModifierPoolDataProvider
43
47
{
44
48
/**
45
49
* @var string
@@ -106,20 +110,29 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
106
110
'position '
107
111
];
108
112
113
+ /**
114
+ * Elements with currency symbol
115
+ *
116
+ * @var array
117
+ */
118
+ private $ elementsWithCurrencySymbol = [
119
+ 'filter_price_range ' ,
120
+ ];
121
+
109
122
/**
110
123
* @var EavValidationRules
111
124
* @since 101.0.0
112
125
*/
113
126
protected $ eavValidationRules ;
114
127
115
128
/**
116
- * @var \Magento\Framework\ Registry
129
+ * @var Registry
117
130
* @since 101.0.0
118
131
*/
119
132
protected $ registry ;
120
133
121
134
/**
122
- * @var \Magento\Framework\App\ RequestInterface
135
+ * @var RequestInterface
123
136
* @since 101.0.0
124
137
*/
125
138
protected $ request ;
@@ -155,7 +168,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
155
168
private $ arrayUtils ;
156
169
157
170
/**
158
- * @var Filesystem
171
+ * @var FileInfo
159
172
*/
160
173
private $ fileInfo ;
161
174
@@ -171,16 +184,18 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
171
184
* @param EavValidationRules $eavValidationRules
172
185
* @param CategoryCollectionFactory $categoryCollectionFactory
173
186
* @param StoreManagerInterface $storeManager
174
- * @param \Magento\Framework\ Registry $registry
187
+ * @param Registry $registry
175
188
* @param Config $eavConfig
176
- * @param \Magento\Framework\App\ RequestInterface $request
189
+ * @param RequestInterface $request
177
190
* @param CategoryFactory $categoryFactory
178
191
* @param array $meta
179
192
* @param array $data
180
193
* @param PoolInterface|null $pool
181
194
* @param AuthorizationInterface|null $auth
182
195
* @param ArrayUtils|null $arrayUtils
183
- * @throws \Magento\Framework\Exception\LocalizedException
196
+ * @param ScopeOverriddenValue|null $scopeOverriddenValue
197
+ * @param ArrayManager|null $arrayManager
198
+ * @param FileInfo|null $fileInfo
184
199
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
185
200
*/
186
201
public function __construct (
@@ -190,15 +205,18 @@ public function __construct(
190
205
EavValidationRules $ eavValidationRules ,
191
206
CategoryCollectionFactory $ categoryCollectionFactory ,
192
207
StoreManagerInterface $ storeManager ,
193
- \ Magento \ Framework \ Registry $ registry ,
208
+ Registry $ registry ,
194
209
Config $ eavConfig ,
195
- \ Magento \ Framework \ App \ RequestInterface $ request ,
210
+ RequestInterface $ request ,
196
211
CategoryFactory $ categoryFactory ,
197
212
array $ meta = [],
198
213
array $ data = [],
199
214
PoolInterface $ pool = null ,
200
215
?AuthorizationInterface $ auth = null ,
201
- ?ArrayUtils $ arrayUtils = null
216
+ ?ArrayUtils $ arrayUtils = null ,
217
+ ScopeOverriddenValue $ scopeOverriddenValue = null ,
218
+ ArrayManager $ arrayManager = null ,
219
+ FileInfo $ fileInfo = null
202
220
) {
203
221
$ this ->eavValidationRules = $ eavValidationRules ;
204
222
$ this ->collection = $ categoryCollectionFactory ->create ();
@@ -210,6 +228,10 @@ public function __construct(
210
228
$ this ->categoryFactory = $ categoryFactory ;
211
229
$ this ->auth = $ auth ?? ObjectManager::getInstance ()->get (AuthorizationInterface::class);
212
230
$ this ->arrayUtils = $ arrayUtils ?? ObjectManager::getInstance ()->get (ArrayUtils::class);
231
+ $ this ->scopeOverriddenValue = $ scopeOverriddenValue ?:
232
+ ObjectManager::getInstance ()->get (ScopeOverriddenValue::class);
233
+ $ this ->arrayManager = $ arrayManager ?: ObjectManager::getInstance ()->get (ArrayManager::class);
234
+ $ this ->fileInfo = $ fileInfo ?: ObjectManager::getInstance ()->get (FileInfo::class);
213
235
214
236
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
215
237
}
@@ -247,7 +269,7 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
247
269
$ canDisplayUseDefault = $ attribute ->getScope () != EavAttributeInterface::SCOPE_GLOBAL_TEXT
248
270
&& $ category ->getId ()
249
271
&& $ category ->getStoreId ();
250
- $ attributePath = $ this ->getArrayManager () ->findPath ($ attributeCode , $ meta );
272
+ $ attributePath = $ this ->arrayManager ->findPath ($ attributeCode , $ meta );
251
273
252
274
if (!$ attributePath
253
275
|| !$ canDisplayUseDefault
@@ -256,14 +278,14 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
256
278
continue ;
257
279
}
258
280
259
- $ meta = $ this ->getArrayManager () ->merge (
281
+ $ meta = $ this ->arrayManager ->merge (
260
282
[$ attributePath , 'arguments/data/config ' ],
261
283
$ meta ,
262
284
[
263
285
'service ' => [
264
286
'template ' => 'ui/form/element/helper/service ' ,
265
287
],
266
- 'disabled ' => !$ this ->getScopeOverriddenValue () ->containsValue (
288
+ 'disabled ' => !$ this ->scopeOverriddenValue ->containsValue (
267
289
CategoryInterface::class,
268
290
$ category ,
269
291
$ attributeCode ,
@@ -354,7 +376,7 @@ public function getData()
354
376
*
355
377
* @param Type $entityType
356
378
* @return array
357
- * @throws \Magento\Framework\Exception\ LocalizedException
379
+ * @throws LocalizedException
358
380
* @SuppressWarnings(PHPMD.NPathComplexity)
359
381
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
360
382
* @since 101.0.0
@@ -407,11 +429,22 @@ public function getAttributesMeta(Type $entityType)
407
429
if ($ category ) {
408
430
$ attributeIsLocked = $ category ->isLockedAttribute ($ code );
409
431
$ meta [$ code ]['disabled ' ] = $ attributeIsLocked ;
410
- $ hasUseConfigField = (bool ) array_search ('use_config. ' . $ code , $ fields , true );
432
+ $ hasUseConfigField = (bool )array_search ('use_config. ' . $ code , $ fields , true );
411
433
if ($ hasUseConfigField && $ meta [$ code ]['disabled ' ]) {
412
434
$ meta ['use_config. ' . $ code ]['disabled ' ] = true ;
413
435
}
414
436
}
437
+
438
+ if (in_array ($ code , $ this ->elementsWithCurrencySymbol , false )) {
439
+ $ requestScope = $ this ->request ->getParam (
440
+ $ this ->requestScopeFieldName ,
441
+ Store::DEFAULT_STORE_ID
442
+ );
443
+
444
+ $ meta [$ code ]['addbefore ' ] = $ this ->storeManager ->getStore ($ requestScope )
445
+ ->getBaseCurrency ()
446
+ ->getCurrencySymbol ();
447
+ }
415
448
}
416
449
417
450
$ result = [];
@@ -451,7 +484,7 @@ protected function addUseConfigSettings($categoryData)
451
484
/**
452
485
* Add use default settings
453
486
*
454
- * @param \Magento\Catalog\Model\ Category $category
487
+ * @param Category $category
455
488
* @param array $categoryData
456
489
* @return array
457
490
* @deprecated 101.1.0
@@ -539,7 +572,7 @@ protected function filterFields($categoryData)
539
572
/**
540
573
* Converts category image data to acceptable for rendering format
541
574
*
542
- * @param \Magento\Catalog\Model\ Category $category
575
+ * @param Category $category
543
576
* @param array $categoryData
544
577
* @return array
545
578
*/
@@ -549,7 +582,7 @@ private function convertValues($category, $categoryData): array
549
582
if ($ attributeCode === 'custom_layout_update_file ' ) {
550
583
if (!empty ($ categoryData ['custom_layout_update ' ])) {
551
584
$ categoryData ['custom_layout_update_file ' ]
552
- = \ Magento \ Catalog \ Model \ Category \ Attribute \ Backend \ LayoutUpdate::VALUE_USE_UPDATE_XML ;
585
+ = LayoutUpdate::VALUE_USE_UPDATE_XML ;
553
586
}
554
587
}
555
588
if (!isset ($ categoryData [$ attributeCode ])) {
@@ -560,16 +593,15 @@ private function convertValues($category, $categoryData): array
560
593
unset($ categoryData [$ attributeCode ]);
561
594
562
595
$ fileName = $ category ->getData ($ attributeCode );
563
- $ fileInfo = $ this ->getFileInfo ();
564
596
565
- if ($ fileInfo ->isExist ($ fileName )) {
566
- $ stat = $ fileInfo ->getStat ($ fileName );
567
- $ mime = $ fileInfo ->getMimeType ($ fileName );
597
+ if ($ this -> fileInfo ->isExist ($ fileName )) {
598
+ $ stat = $ this -> fileInfo ->getStat ($ fileName );
599
+ $ mime = $ this -> fileInfo ->getMimeType ($ fileName );
568
600
569
601
// phpcs:ignore Magento2.Functions.DiscouragedFunction
570
602
$ categoryData [$ attributeCode ][0 ]['name ' ] = basename ($ fileName );
571
603
572
- if ($ fileInfo ->isBeginsWithMediaDirectoryPath ($ fileName )) {
604
+ if ($ this -> fileInfo ->isBeginsWithMediaDirectoryPath ($ fileName )) {
573
605
$ categoryData [$ attributeCode ][0 ]['url ' ] = $ fileName ;
574
606
} else {
575
607
$ categoryData [$ attributeCode ][0 ]['url ' ] = $ category ->getImageUrl ($ attributeCode );
@@ -611,53 +643,53 @@ protected function getFieldsMap()
611
643
{
612
644
return [
613
645
'general ' => [
614
- 'parent ' ,
615
- 'path ' ,
616
- 'is_active ' ,
617
- 'include_in_menu ' ,
618
- 'name ' ,
619
- ],
646
+ 'parent ' ,
647
+ 'path ' ,
648
+ 'is_active ' ,
649
+ 'include_in_menu ' ,
650
+ 'name ' ,
651
+ ],
620
652
'content ' => [
621
- 'image ' ,
622
- 'description ' ,
623
- 'landing_page ' ,
624
- ],
653
+ 'image ' ,
654
+ 'description ' ,
655
+ 'landing_page ' ,
656
+ ],
625
657
'display_settings ' => [
626
- 'display_mode ' ,
627
- 'is_anchor ' ,
628
- 'available_sort_by ' ,
629
- 'use_config.available_sort_by ' ,
630
- 'default_sort_by ' ,
631
- 'use_config.default_sort_by ' ,
632
- 'filter_price_range ' ,
633
- 'use_config.filter_price_range ' ,
634
- ],
658
+ 'display_mode ' ,
659
+ 'is_anchor ' ,
660
+ 'available_sort_by ' ,
661
+ 'use_config.available_sort_by ' ,
662
+ 'default_sort_by ' ,
663
+ 'use_config.default_sort_by ' ,
664
+ 'filter_price_range ' ,
665
+ 'use_config.filter_price_range ' ,
666
+ ],
635
667
'search_engine_optimization ' => [
636
- 'url_key ' ,
637
- 'url_key_create_redirect ' ,
638
- 'url_key_group ' ,
639
- 'meta_title ' ,
640
- 'meta_keywords ' ,
641
- 'meta_description ' ,
642
- ],
668
+ 'url_key ' ,
669
+ 'url_key_create_redirect ' ,
670
+ 'url_key_group ' ,
671
+ 'meta_title ' ,
672
+ 'meta_keywords ' ,
673
+ 'meta_description ' ,
674
+ ],
643
675
'assign_products ' => [
644
- ],
676
+ ],
645
677
'design ' => [
646
- 'custom_use_parent_settings ' ,
647
- 'custom_apply_to_products ' ,
648
- 'custom_design ' ,
649
- 'page_layout ' ,
650
- 'custom_layout_update ' ,
651
- 'custom_layout_update_file '
652
- ],
678
+ 'custom_use_parent_settings ' ,
679
+ 'custom_apply_to_products ' ,
680
+ 'custom_design ' ,
681
+ 'page_layout ' ,
682
+ 'custom_layout_update ' ,
683
+ 'custom_layout_update_file '
684
+ ],
653
685
'schedule_design_update ' => [
654
- 'custom_design_from ' ,
655
- 'custom_design_to ' ,
656
- ],
686
+ 'custom_design_from ' ,
687
+ 'custom_design_to ' ,
688
+ ],
657
689
'category_view_optimization ' => [
658
- ],
690
+ ],
659
691
'category_permissions ' => [
660
- ],
692
+ ],
661
693
];
662
694
}
663
695
@@ -671,53 +703,4 @@ private function getFields(): array
671
703
$ fieldsMap = $ this ->getFieldsMap ();
672
704
return $ this ->arrayUtils ->flatten ($ fieldsMap );
673
705
}
674
-
675
- /**
676
- * Retrieve scope overridden value
677
- *
678
- * @return ScopeOverriddenValue
679
- * @deprecated 101.1.0
680
- */
681
- private function getScopeOverriddenValue (): ScopeOverriddenValue
682
- {
683
- if (null === $ this ->scopeOverriddenValue ) {
684
- $ this ->scopeOverriddenValue = \Magento \Framework \App \ObjectManager::getInstance ()->get (
685
- ScopeOverriddenValue::class
686
- );
687
- }
688
-
689
- return $ this ->scopeOverriddenValue ;
690
- }
691
-
692
- /**
693
- * Retrieve array manager
694
- *
695
- * @return ArrayManager
696
- * @deprecated 101.1.0
697
- */
698
- private function getArrayManager (): ArrayManager
699
- {
700
- if (null === $ this ->arrayManager ) {
701
- $ this ->arrayManager = \Magento \Framework \App \ObjectManager::getInstance ()->get (
702
- ArrayManager::class
703
- );
704
- }
705
-
706
- return $ this ->arrayManager ;
707
- }
708
-
709
- /**
710
- * Get FileInfo instance
711
- *
712
- * @return FileInfo
713
- *
714
- * @deprecated 101.1.0
715
- */
716
- private function getFileInfo (): FileInfo
717
- {
718
- if ($ this ->fileInfo === null ) {
719
- $ this ->fileInfo = ObjectManager::getInstance ()->get (FileInfo::class);
720
- }
721
- return $ this ->fileInfo ;
722
- }
723
706
}
0 commit comments