Skip to content

Commit 70a467a

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-fast-lane-prs
- merged with '2.4-develop-temporary-two-prs' branch
2 parents 4757483 + a12b93b commit 70a467a

File tree

17 files changed

+819
-171
lines changed

17 files changed

+819
-171
lines changed

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 95 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
1313
use Magento\Catalog\Model\Category;
1414
use Magento\Catalog\Model\Category\Attribute\Backend\Image as ImageBackendModel;
15+
use Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate;
1516
use Magento\Catalog\Model\CategoryFactory;
1617
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1718
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
@@ -20,8 +21,10 @@
2021
use Magento\Eav\Model\Entity\Attribute\Source\SpecificSourceInterface;
2122
use Magento\Eav\Model\Entity\Type;
2223
use Magento\Framework\App\ObjectManager;
24+
use Magento\Framework\App\RequestInterface;
25+
use Magento\Framework\Exception\LocalizedException;
2326
use Magento\Framework\Exception\NoSuchEntityException;
24-
use Magento\Framework\Filesystem;
27+
use Magento\Framework\Registry;
2528
use Magento\Framework\Stdlib\ArrayManager;
2629
use Magento\Framework\Stdlib\ArrayUtils;
2730
use Magento\Store\Model\Store;
@@ -30,6 +33,7 @@
3033
use Magento\Ui\DataProvider\EavValidationRules;
3134
use Magento\Ui\DataProvider\Modifier\PoolInterface;
3235
use Magento\Framework\AuthorizationInterface;
36+
use Magento\Ui\DataProvider\ModifierPoolDataProvider;
3337

3438
/**
3539
* Category form data provider.
@@ -39,7 +43,7 @@
3943
* @SuppressWarnings(PHPMD.TooManyFields)
4044
* @since 101.0.0
4145
*/
42-
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
46+
class DataProvider extends ModifierPoolDataProvider
4347
{
4448
/**
4549
* @var string
@@ -106,20 +110,29 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
106110
'position'
107111
];
108112

113+
/**
114+
* Elements with currency symbol
115+
*
116+
* @var array
117+
*/
118+
private $elementsWithCurrencySymbol = [
119+
'filter_price_range',
120+
];
121+
109122
/**
110123
* @var EavValidationRules
111124
* @since 101.0.0
112125
*/
113126
protected $eavValidationRules;
114127

115128
/**
116-
* @var \Magento\Framework\Registry
129+
* @var Registry
117130
* @since 101.0.0
118131
*/
119132
protected $registry;
120133

121134
/**
122-
* @var \Magento\Framework\App\RequestInterface
135+
* @var RequestInterface
123136
* @since 101.0.0
124137
*/
125138
protected $request;
@@ -155,7 +168,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
155168
private $arrayUtils;
156169

157170
/**
158-
* @var Filesystem
171+
* @var FileInfo
159172
*/
160173
private $fileInfo;
161174

@@ -171,16 +184,18 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
171184
* @param EavValidationRules $eavValidationRules
172185
* @param CategoryCollectionFactory $categoryCollectionFactory
173186
* @param StoreManagerInterface $storeManager
174-
* @param \Magento\Framework\Registry $registry
187+
* @param Registry $registry
175188
* @param Config $eavConfig
176-
* @param \Magento\Framework\App\RequestInterface $request
189+
* @param RequestInterface $request
177190
* @param CategoryFactory $categoryFactory
178191
* @param array $meta
179192
* @param array $data
180193
* @param PoolInterface|null $pool
181194
* @param AuthorizationInterface|null $auth
182195
* @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
184199
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
185200
*/
186201
public function __construct(
@@ -190,15 +205,18 @@ public function __construct(
190205
EavValidationRules $eavValidationRules,
191206
CategoryCollectionFactory $categoryCollectionFactory,
192207
StoreManagerInterface $storeManager,
193-
\Magento\Framework\Registry $registry,
208+
Registry $registry,
194209
Config $eavConfig,
195-
\Magento\Framework\App\RequestInterface $request,
210+
RequestInterface $request,
196211
CategoryFactory $categoryFactory,
197212
array $meta = [],
198213
array $data = [],
199214
PoolInterface $pool = null,
200215
?AuthorizationInterface $auth = null,
201-
?ArrayUtils $arrayUtils = null
216+
?ArrayUtils $arrayUtils = null,
217+
ScopeOverriddenValue $scopeOverriddenValue = null,
218+
ArrayManager $arrayManager = null,
219+
FileInfo $fileInfo = null
202220
) {
203221
$this->eavValidationRules = $eavValidationRules;
204222
$this->collection = $categoryCollectionFactory->create();
@@ -210,6 +228,10 @@ public function __construct(
210228
$this->categoryFactory = $categoryFactory;
211229
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
212230
$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);
213235

214236
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
215237
}
@@ -247,7 +269,7 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
247269
$canDisplayUseDefault = $attribute->getScope() != EavAttributeInterface::SCOPE_GLOBAL_TEXT
248270
&& $category->getId()
249271
&& $category->getStoreId();
250-
$attributePath = $this->getArrayManager()->findPath($attributeCode, $meta);
272+
$attributePath = $this->arrayManager->findPath($attributeCode, $meta);
251273

252274
if (!$attributePath
253275
|| !$canDisplayUseDefault
@@ -256,14 +278,14 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
256278
continue;
257279
}
258280

259-
$meta = $this->getArrayManager()->merge(
281+
$meta = $this->arrayManager->merge(
260282
[$attributePath, 'arguments/data/config'],
261283
$meta,
262284
[
263285
'service' => [
264286
'template' => 'ui/form/element/helper/service',
265287
],
266-
'disabled' => !$this->getScopeOverriddenValue()->containsValue(
288+
'disabled' => !$this->scopeOverriddenValue->containsValue(
267289
CategoryInterface::class,
268290
$category,
269291
$attributeCode,
@@ -354,7 +376,7 @@ public function getData()
354376
*
355377
* @param Type $entityType
356378
* @return array
357-
* @throws \Magento\Framework\Exception\LocalizedException
379+
* @throws LocalizedException
358380
* @SuppressWarnings(PHPMD.NPathComplexity)
359381
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
360382
* @since 101.0.0
@@ -407,11 +429,22 @@ public function getAttributesMeta(Type $entityType)
407429
if ($category) {
408430
$attributeIsLocked = $category->isLockedAttribute($code);
409431
$meta[$code]['disabled'] = $attributeIsLocked;
410-
$hasUseConfigField = (bool) array_search('use_config.' . $code, $fields, true);
432+
$hasUseConfigField = (bool)array_search('use_config.' . $code, $fields, true);
411433
if ($hasUseConfigField && $meta[$code]['disabled']) {
412434
$meta['use_config.' . $code]['disabled'] = true;
413435
}
414436
}
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+
}
415448
}
416449

417450
$result = [];
@@ -451,7 +484,7 @@ protected function addUseConfigSettings($categoryData)
451484
/**
452485
* Add use default settings
453486
*
454-
* @param \Magento\Catalog\Model\Category $category
487+
* @param Category $category
455488
* @param array $categoryData
456489
* @return array
457490
* @deprecated 101.1.0
@@ -539,7 +572,7 @@ protected function filterFields($categoryData)
539572
/**
540573
* Converts category image data to acceptable for rendering format
541574
*
542-
* @param \Magento\Catalog\Model\Category $category
575+
* @param Category $category
543576
* @param array $categoryData
544577
* @return array
545578
*/
@@ -549,7 +582,7 @@ private function convertValues($category, $categoryData): array
549582
if ($attributeCode === 'custom_layout_update_file') {
550583
if (!empty($categoryData['custom_layout_update'])) {
551584
$categoryData['custom_layout_update_file']
552-
= \Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate::VALUE_USE_UPDATE_XML;
585+
= LayoutUpdate::VALUE_USE_UPDATE_XML;
553586
}
554587
}
555588
if (!isset($categoryData[$attributeCode])) {
@@ -560,16 +593,15 @@ private function convertValues($category, $categoryData): array
560593
unset($categoryData[$attributeCode]);
561594

562595
$fileName = $category->getData($attributeCode);
563-
$fileInfo = $this->getFileInfo();
564596

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);
568600

569601
// phpcs:ignore Magento2.Functions.DiscouragedFunction
570602
$categoryData[$attributeCode][0]['name'] = basename($fileName);
571603

572-
if ($fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
604+
if ($this->fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
573605
$categoryData[$attributeCode][0]['url'] = $fileName;
574606
} else {
575607
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
@@ -611,53 +643,53 @@ protected function getFieldsMap()
611643
{
612644
return [
613645
'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+
],
620652
'content' => [
621-
'image',
622-
'description',
623-
'landing_page',
624-
],
653+
'image',
654+
'description',
655+
'landing_page',
656+
],
625657
'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+
],
635667
'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+
],
643675
'assign_products' => [
644-
],
676+
],
645677
'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+
],
653685
'schedule_design_update' => [
654-
'custom_design_from',
655-
'custom_design_to',
656-
],
686+
'custom_design_from',
687+
'custom_design_to',
688+
],
657689
'category_view_optimization' => [
658-
],
690+
],
659691
'category_permissions' => [
660-
],
692+
],
661693
];
662694
}
663695

@@ -671,53 +703,4 @@ private function getFields(): array
671703
$fieldsMap = $this->getFieldsMap();
672704
return $this->arrayUtils->flatten($fieldsMap);
673705
}
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-
}
723706
}

0 commit comments

Comments
 (0)