20
20
use Magento \Eav \Model \Entity \Attribute \Source \SpecificSourceInterface ;
21
21
use Magento \Eav \Model \Entity \Type ;
22
22
use Magento \Framework \App \ObjectManager ;
23
+ use Magento \Framework \App \RequestInterface ;
24
+ use Magento \Framework \Exception \LocalizedException ;
23
25
use Magento \Framework \Exception \NoSuchEntityException ;
24
26
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 ;
@@ -171,16 +184,19 @@ 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 Filesystem|null $fileInfo
199
+ * @throws LocalizedException
184
200
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
185
201
*/
186
202
public function __construct (
@@ -190,15 +206,18 @@ public function __construct(
190
206
EavValidationRules $ eavValidationRules ,
191
207
CategoryCollectionFactory $ categoryCollectionFactory ,
192
208
StoreManagerInterface $ storeManager ,
193
- \ Magento \ Framework \ Registry $ registry ,
209
+ Registry $ registry ,
194
210
Config $ eavConfig ,
195
- \ Magento \ Framework \ App \ RequestInterface $ request ,
211
+ RequestInterface $ request ,
196
212
CategoryFactory $ categoryFactory ,
197
213
array $ meta = [],
198
214
array $ data = [],
199
215
PoolInterface $ pool = null ,
200
216
?AuthorizationInterface $ auth = null ,
201
- ?ArrayUtils $ arrayUtils = null
217
+ ?ArrayUtils $ arrayUtils = null ,
218
+ ScopeOverriddenValue $ scopeOverriddenValue = null ,
219
+ ArrayManager $ arrayManager = null ,
220
+ Filesystem $ fileInfo = null
202
221
) {
203
222
$ this ->eavValidationRules = $ eavValidationRules ;
204
223
$ this ->collection = $ categoryCollectionFactory ->create ();
@@ -210,6 +229,10 @@ public function __construct(
210
229
$ this ->categoryFactory = $ categoryFactory ;
211
230
$ this ->auth = $ auth ?? ObjectManager::getInstance ()->get (AuthorizationInterface::class);
212
231
$ this ->arrayUtils = $ arrayUtils ?? ObjectManager::getInstance ()->get (ArrayUtils::class);
232
+ $ this ->scopeOverriddenValue = $ scopeOverriddenValue ?:
233
+ ObjectManager::getInstance ()->get (ScopeOverriddenValue::class);
234
+ $ this ->arrayManager = $ arrayManager ?: ObjectManager::getInstance ()->get (ArrayManager::class);
235
+ $ this ->fileInfo = $ fileInfo ?: ObjectManager::getInstance ()->get (Filesystem::class);
213
236
214
237
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
215
238
}
@@ -247,7 +270,7 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
247
270
$ canDisplayUseDefault = $ attribute ->getScope () != EavAttributeInterface::SCOPE_GLOBAL_TEXT
248
271
&& $ category ->getId ()
249
272
&& $ category ->getStoreId ();
250
- $ attributePath = $ this ->getArrayManager () ->findPath ($ attributeCode , $ meta );
273
+ $ attributePath = $ this ->arrayManager ->findPath ($ attributeCode , $ meta );
251
274
252
275
if (!$ attributePath
253
276
|| !$ canDisplayUseDefault
@@ -256,14 +279,14 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
256
279
continue ;
257
280
}
258
281
259
- $ meta = $ this ->getArrayManager () ->merge (
282
+ $ meta = $ this ->arrayManager ->merge (
260
283
[$ attributePath , 'arguments/data/config ' ],
261
284
$ meta ,
262
285
[
263
286
'service ' => [
264
287
'template ' => 'ui/form/element/helper/service ' ,
265
288
],
266
- 'disabled ' => !$ this ->getScopeOverriddenValue () ->containsValue (
289
+ 'disabled ' => !$ this ->scopeOverriddenValue ->containsValue (
267
290
CategoryInterface::class,
268
291
$ category ,
269
292
$ attributeCode ,
@@ -354,7 +377,7 @@ public function getData()
354
377
*
355
378
* @param Type $entityType
356
379
* @return array
357
- * @throws \Magento\Framework\Exception\ LocalizedException
380
+ * @throws LocalizedException
358
381
* @SuppressWarnings(PHPMD.NPathComplexity)
359
382
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
360
383
* @since 101.0.0
@@ -407,11 +430,22 @@ public function getAttributesMeta(Type $entityType)
407
430
if ($ category ) {
408
431
$ attributeIsLocked = $ category ->isLockedAttribute ($ code );
409
432
$ meta [$ code ]['disabled ' ] = $ attributeIsLocked ;
410
- $ hasUseConfigField = (bool ) array_search ('use_config. ' . $ code , $ fields , true );
433
+ $ hasUseConfigField = (bool )array_search ('use_config. ' . $ code , $ fields , true );
411
434
if ($ hasUseConfigField && $ meta [$ code ]['disabled ' ]) {
412
435
$ meta ['use_config. ' . $ code ]['disabled ' ] = true ;
413
436
}
414
437
}
438
+
439
+ if (in_array ($ code , $ this ->elementsWithCurrencySymbol , false )) {
440
+ $ requestScope = $ this ->request ->getParam (
441
+ $ this ->requestScopeFieldName ,
442
+ Store::DEFAULT_STORE_ID
443
+ );
444
+
445
+ $ meta [$ code ]['addbefore ' ] = $ this ->storeManager ->getStore ($ requestScope )
446
+ ->getBaseCurrency ()
447
+ ->getCurrencySymbol ();
448
+ }
415
449
}
416
450
417
451
$ result = [];
@@ -560,16 +594,15 @@ private function convertValues($category, $categoryData): array
560
594
unset($ categoryData [$ attributeCode ]);
561
595
562
596
$ fileName = $ category ->getData ($ attributeCode );
563
- $ fileInfo = $ this ->getFileInfo ();
564
597
565
- if ($ fileInfo ->isExist ($ fileName )) {
566
- $ stat = $ fileInfo ->getStat ($ fileName );
567
- $ mime = $ fileInfo ->getMimeType ($ fileName );
598
+ if ($ this -> fileInfo ->isExist ($ fileName )) {
599
+ $ stat = $ this -> fileInfo ->getStat ($ fileName );
600
+ $ mime = $ this -> fileInfo ->getMimeType ($ fileName );
568
601
569
602
// phpcs:ignore Magento2.Functions.DiscouragedFunction
570
603
$ categoryData [$ attributeCode ][0 ]['name ' ] = basename ($ fileName );
571
604
572
- if ($ fileInfo ->isBeginsWithMediaDirectoryPath ($ fileName )) {
605
+ if ($ this -> fileInfo ->isBeginsWithMediaDirectoryPath ($ fileName )) {
573
606
$ categoryData [$ attributeCode ][0 ]['url ' ] = $ fileName ;
574
607
} else {
575
608
$ categoryData [$ attributeCode ][0 ]['url ' ] = $ category ->getImageUrl ($ attributeCode );
@@ -611,53 +644,53 @@ protected function getFieldsMap()
611
644
{
612
645
return [
613
646
'general ' => [
614
- 'parent ' ,
615
- 'path ' ,
616
- 'is_active ' ,
617
- 'include_in_menu ' ,
618
- 'name ' ,
619
- ],
647
+ 'parent ' ,
648
+ 'path ' ,
649
+ 'is_active ' ,
650
+ 'include_in_menu ' ,
651
+ 'name ' ,
652
+ ],
620
653
'content ' => [
621
- 'image ' ,
622
- 'description ' ,
623
- 'landing_page ' ,
624
- ],
654
+ 'image ' ,
655
+ 'description ' ,
656
+ 'landing_page ' ,
657
+ ],
625
658
'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
- ],
659
+ 'display_mode ' ,
660
+ 'is_anchor ' ,
661
+ 'available_sort_by ' ,
662
+ 'use_config.available_sort_by ' ,
663
+ 'default_sort_by ' ,
664
+ 'use_config.default_sort_by ' ,
665
+ 'filter_price_range ' ,
666
+ 'use_config.filter_price_range ' ,
667
+ ],
635
668
'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
- ],
669
+ 'url_key ' ,
670
+ 'url_key_create_redirect ' ,
671
+ 'url_key_group ' ,
672
+ 'meta_title ' ,
673
+ 'meta_keywords ' ,
674
+ 'meta_description ' ,
675
+ ],
643
676
'assign_products ' => [
644
- ],
677
+ ],
645
678
'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
- ],
679
+ 'custom_use_parent_settings ' ,
680
+ 'custom_apply_to_products ' ,
681
+ 'custom_design ' ,
682
+ 'page_layout ' ,
683
+ 'custom_layout_update ' ,
684
+ 'custom_layout_update_file '
685
+ ],
653
686
'schedule_design_update ' => [
654
- 'custom_design_from ' ,
655
- 'custom_design_to ' ,
656
- ],
687
+ 'custom_design_from ' ,
688
+ 'custom_design_to ' ,
689
+ ],
657
690
'category_view_optimization ' => [
658
- ],
691
+ ],
659
692
'category_permissions ' => [
660
- ],
693
+ ],
661
694
];
662
695
}
663
696
@@ -671,53 +704,4 @@ private function getFields(): array
671
704
$ fieldsMap = $ this ->getFieldsMap ();
672
705
return $ this ->arrayUtils ->flatten ($ fieldsMap );
673
706
}
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
707
}
0 commit comments