Skip to content

Commit 2c70512

Browse files
committed
Fix #21684 - Currency sign for "Layered Navigation Price Step" is not according to default settings
1 parent d95cea6 commit 2c70512

File tree

3 files changed

+149
-162
lines changed

3 files changed

+149
-162
lines changed

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

Lines changed: 91 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
use Magento\Eav\Model\Entity\Attribute\Source\SpecificSourceInterface;
2121
use Magento\Eav\Model\Entity\Type;
2222
use Magento\Framework\App\ObjectManager;
23+
use Magento\Framework\App\RequestInterface;
24+
use Magento\Framework\Exception\LocalizedException;
2325
use Magento\Framework\Exception\NoSuchEntityException;
2426
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;
@@ -171,16 +184,19 @@ 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 Filesystem|null $fileInfo
199+
* @throws LocalizedException
184200
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
185201
*/
186202
public function __construct(
@@ -190,15 +206,18 @@ public function __construct(
190206
EavValidationRules $eavValidationRules,
191207
CategoryCollectionFactory $categoryCollectionFactory,
192208
StoreManagerInterface $storeManager,
193-
\Magento\Framework\Registry $registry,
209+
Registry $registry,
194210
Config $eavConfig,
195-
\Magento\Framework\App\RequestInterface $request,
211+
RequestInterface $request,
196212
CategoryFactory $categoryFactory,
197213
array $meta = [],
198214
array $data = [],
199215
PoolInterface $pool = null,
200216
?AuthorizationInterface $auth = null,
201-
?ArrayUtils $arrayUtils = null
217+
?ArrayUtils $arrayUtils = null,
218+
ScopeOverriddenValue $scopeOverriddenValue = null,
219+
ArrayManager $arrayManager = null,
220+
Filesystem $fileInfo = null
202221
) {
203222
$this->eavValidationRules = $eavValidationRules;
204223
$this->collection = $categoryCollectionFactory->create();
@@ -210,6 +229,10 @@ public function __construct(
210229
$this->categoryFactory = $categoryFactory;
211230
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
212231
$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);
213236

214237
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
215238
}
@@ -247,7 +270,7 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
247270
$canDisplayUseDefault = $attribute->getScope() != EavAttributeInterface::SCOPE_GLOBAL_TEXT
248271
&& $category->getId()
249272
&& $category->getStoreId();
250-
$attributePath = $this->getArrayManager()->findPath($attributeCode, $meta);
273+
$attributePath = $this->arrayManager->findPath($attributeCode, $meta);
251274

252275
if (!$attributePath
253276
|| !$canDisplayUseDefault
@@ -256,14 +279,14 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
256279
continue;
257280
}
258281

259-
$meta = $this->getArrayManager()->merge(
282+
$meta = $this->arrayManager->merge(
260283
[$attributePath, 'arguments/data/config'],
261284
$meta,
262285
[
263286
'service' => [
264287
'template' => 'ui/form/element/helper/service',
265288
],
266-
'disabled' => !$this->getScopeOverriddenValue()->containsValue(
289+
'disabled' => !$this->scopeOverriddenValue->containsValue(
267290
CategoryInterface::class,
268291
$category,
269292
$attributeCode,
@@ -354,7 +377,7 @@ public function getData()
354377
*
355378
* @param Type $entityType
356379
* @return array
357-
* @throws \Magento\Framework\Exception\LocalizedException
380+
* @throws LocalizedException
358381
* @SuppressWarnings(PHPMD.NPathComplexity)
359382
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
360383
* @since 101.0.0
@@ -407,11 +430,22 @@ public function getAttributesMeta(Type $entityType)
407430
if ($category) {
408431
$attributeIsLocked = $category->isLockedAttribute($code);
409432
$meta[$code]['disabled'] = $attributeIsLocked;
410-
$hasUseConfigField = (bool) array_search('use_config.' . $code, $fields, true);
433+
$hasUseConfigField = (bool)array_search('use_config.' . $code, $fields, true);
411434
if ($hasUseConfigField && $meta[$code]['disabled']) {
412435
$meta['use_config.' . $code]['disabled'] = true;
413436
}
414437
}
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+
}
415449
}
416450

417451
$result = [];
@@ -560,16 +594,15 @@ private function convertValues($category, $categoryData): array
560594
unset($categoryData[$attributeCode]);
561595

562596
$fileName = $category->getData($attributeCode);
563-
$fileInfo = $this->getFileInfo();
564597

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

569602
// phpcs:ignore Magento2.Functions.DiscouragedFunction
570603
$categoryData[$attributeCode][0]['name'] = basename($fileName);
571604

572-
if ($fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
605+
if ($this->fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
573606
$categoryData[$attributeCode][0]['url'] = $fileName;
574607
} else {
575608
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
@@ -611,53 +644,53 @@ protected function getFieldsMap()
611644
{
612645
return [
613646
'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+
],
620653
'content' => [
621-
'image',
622-
'description',
623-
'landing_page',
624-
],
654+
'image',
655+
'description',
656+
'landing_page',
657+
],
625658
'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+
],
635668
'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+
],
643676
'assign_products' => [
644-
],
677+
],
645678
'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+
],
653686
'schedule_design_update' => [
654-
'custom_design_from',
655-
'custom_design_to',
656-
],
687+
'custom_design_from',
688+
'custom_design_to',
689+
],
657690
'category_view_optimization' => [
658-
],
691+
],
659692
'category_permissions' => [
660-
],
693+
],
661694
];
662695
}
663696

@@ -671,53 +704,4 @@ private function getFields(): array
671704
$fieldsMap = $this->getFieldsMap();
672705
return $this->arrayUtils->flatten($fieldsMap);
673706
}
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-
}
723707
}

0 commit comments

Comments
 (0)