Skip to content

Commit

Permalink
ENGCOM-5986: Fix #21684 - Currency sign for "Layered Navigation Price…
Browse files Browse the repository at this point in the history
… Step" is not according to default settings #24815
  • Loading branch information
VladimirZaets authored Jan 6, 2020
2 parents 87b0a4b + 3812c32 commit a12b93b
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 155 deletions.
207 changes: 95 additions & 112 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Category\Attribute\Backend\Image as ImageBackendModel;
use Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
Expand All @@ -20,8 +21,10 @@
use Magento\Eav\Model\Entity\Attribute\Source\SpecificSourceInterface;
use Magento\Eav\Model\Entity\Type;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\Stdlib\ArrayUtils;
use Magento\Store\Model\Store;
Expand All @@ -30,6 +33,7 @@
use Magento\Ui\DataProvider\EavValidationRules;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Ui\DataProvider\ModifierPoolDataProvider;

/**
* Category form data provider.
Expand All @@ -39,7 +43,7 @@
* @SuppressWarnings(PHPMD.TooManyFields)
* @since 101.0.0
*/
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
class DataProvider extends ModifierPoolDataProvider
{
/**
* @var string
Expand Down Expand Up @@ -106,20 +110,29 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
'position'
];

/**
* Elements with currency symbol
*
* @var array
*/
private $elementsWithCurrencySymbol = [
'filter_price_range',
];

/**
* @var EavValidationRules
* @since 101.0.0
*/
protected $eavValidationRules;

/**
* @var \Magento\Framework\Registry
* @var Registry
* @since 101.0.0
*/
protected $registry;

/**
* @var \Magento\Framework\App\RequestInterface
* @var RequestInterface
* @since 101.0.0
*/
protected $request;
Expand Down Expand Up @@ -155,7 +168,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
private $arrayUtils;

/**
* @var Filesystem
* @var FileInfo
*/
private $fileInfo;

Expand All @@ -171,16 +184,18 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
* @param EavValidationRules $eavValidationRules
* @param CategoryCollectionFactory $categoryCollectionFactory
* @param StoreManagerInterface $storeManager
* @param \Magento\Framework\Registry $registry
* @param Registry $registry
* @param Config $eavConfig
* @param \Magento\Framework\App\RequestInterface $request
* @param RequestInterface $request
* @param CategoryFactory $categoryFactory
* @param array $meta
* @param array $data
* @param PoolInterface|null $pool
* @param AuthorizationInterface|null $auth
* @param ArrayUtils|null $arrayUtils
* @throws \Magento\Framework\Exception\LocalizedException
* @param ScopeOverriddenValue|null $scopeOverriddenValue
* @param ArrayManager|null $arrayManager
* @param FileInfo|null $fileInfo
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -190,15 +205,18 @@ public function __construct(
EavValidationRules $eavValidationRules,
CategoryCollectionFactory $categoryCollectionFactory,
StoreManagerInterface $storeManager,
\Magento\Framework\Registry $registry,
Registry $registry,
Config $eavConfig,
\Magento\Framework\App\RequestInterface $request,
RequestInterface $request,
CategoryFactory $categoryFactory,
array $meta = [],
array $data = [],
PoolInterface $pool = null,
?AuthorizationInterface $auth = null,
?ArrayUtils $arrayUtils = null
?ArrayUtils $arrayUtils = null,
ScopeOverriddenValue $scopeOverriddenValue = null,
ArrayManager $arrayManager = null,
FileInfo $fileInfo = null
) {
$this->eavValidationRules = $eavValidationRules;
$this->collection = $categoryCollectionFactory->create();
Expand All @@ -210,6 +228,10 @@ public function __construct(
$this->categoryFactory = $categoryFactory;
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
$this->arrayUtils = $arrayUtils ?? ObjectManager::getInstance()->get(ArrayUtils::class);
$this->scopeOverriddenValue = $scopeOverriddenValue ?:
ObjectManager::getInstance()->get(ScopeOverriddenValue::class);
$this->arrayManager = $arrayManager ?: ObjectManager::getInstance()->get(ArrayManager::class);
$this->fileInfo = $fileInfo ?: ObjectManager::getInstance()->get(FileInfo::class);

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

if (!$attributePath
|| !$canDisplayUseDefault
Expand All @@ -256,14 +278,14 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta): ar
continue;
}

$meta = $this->getArrayManager()->merge(
$meta = $this->arrayManager->merge(
[$attributePath, 'arguments/data/config'],
$meta,
[
'service' => [
'template' => 'ui/form/element/helper/service',
],
'disabled' => !$this->getScopeOverriddenValue()->containsValue(
'disabled' => !$this->scopeOverriddenValue->containsValue(
CategoryInterface::class,
$category,
$attributeCode,
Expand Down Expand Up @@ -354,7 +376,7 @@ public function getData()
*
* @param Type $entityType
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @since 101.0.0
Expand Down Expand Up @@ -407,11 +429,22 @@ public function getAttributesMeta(Type $entityType)
if ($category) {
$attributeIsLocked = $category->isLockedAttribute($code);
$meta[$code]['disabled'] = $attributeIsLocked;
$hasUseConfigField = (bool) array_search('use_config.' . $code, $fields, true);
$hasUseConfigField = (bool)array_search('use_config.' . $code, $fields, true);
if ($hasUseConfigField && $meta[$code]['disabled']) {
$meta['use_config.' . $code]['disabled'] = true;
}
}

if (in_array($code, $this->elementsWithCurrencySymbol, false)) {
$requestScope = $this->request->getParam(
$this->requestScopeFieldName,
Store::DEFAULT_STORE_ID
);

$meta[$code]['addbefore'] = $this->storeManager->getStore($requestScope)
->getBaseCurrency()
->getCurrencySymbol();
}
}

$result = [];
Expand Down Expand Up @@ -451,7 +484,7 @@ protected function addUseConfigSettings($categoryData)
/**
* Add use default settings
*
* @param \Magento\Catalog\Model\Category $category
* @param Category $category
* @param array $categoryData
* @return array
* @deprecated 101.1.0
Expand Down Expand Up @@ -539,7 +572,7 @@ protected function filterFields($categoryData)
/**
* Converts category image data to acceptable for rendering format
*
* @param \Magento\Catalog\Model\Category $category
* @param Category $category
* @param array $categoryData
* @return array
*/
Expand All @@ -549,7 +582,7 @@ private function convertValues($category, $categoryData): array
if ($attributeCode === 'custom_layout_update_file') {
if (!empty($categoryData['custom_layout_update'])) {
$categoryData['custom_layout_update_file']
= \Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate::VALUE_USE_UPDATE_XML;
= LayoutUpdate::VALUE_USE_UPDATE_XML;
}
}
if (!isset($categoryData[$attributeCode])) {
Expand All @@ -560,16 +593,15 @@ private function convertValues($category, $categoryData): array
unset($categoryData[$attributeCode]);

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

if ($fileInfo->isExist($fileName)) {
$stat = $fileInfo->getStat($fileName);
$mime = $fileInfo->getMimeType($fileName);
if ($this->fileInfo->isExist($fileName)) {
$stat = $this->fileInfo->getStat($fileName);
$mime = $this->fileInfo->getMimeType($fileName);

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

if ($fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
if ($this->fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
$categoryData[$attributeCode][0]['url'] = $fileName;
} else {
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
Expand Down Expand Up @@ -611,53 +643,53 @@ protected function getFieldsMap()
{
return [
'general' => [
'parent',
'path',
'is_active',
'include_in_menu',
'name',
],
'parent',
'path',
'is_active',
'include_in_menu',
'name',
],
'content' => [
'image',
'description',
'landing_page',
],
'image',
'description',
'landing_page',
],
'display_settings' => [
'display_mode',
'is_anchor',
'available_sort_by',
'use_config.available_sort_by',
'default_sort_by',
'use_config.default_sort_by',
'filter_price_range',
'use_config.filter_price_range',
],
'display_mode',
'is_anchor',
'available_sort_by',
'use_config.available_sort_by',
'default_sort_by',
'use_config.default_sort_by',
'filter_price_range',
'use_config.filter_price_range',
],
'search_engine_optimization' => [
'url_key',
'url_key_create_redirect',
'url_key_group',
'meta_title',
'meta_keywords',
'meta_description',
],
'url_key',
'url_key_create_redirect',
'url_key_group',
'meta_title',
'meta_keywords',
'meta_description',
],
'assign_products' => [
],
],
'design' => [
'custom_use_parent_settings',
'custom_apply_to_products',
'custom_design',
'page_layout',
'custom_layout_update',
'custom_layout_update_file'
],
'custom_use_parent_settings',
'custom_apply_to_products',
'custom_design',
'page_layout',
'custom_layout_update',
'custom_layout_update_file'
],
'schedule_design_update' => [
'custom_design_from',
'custom_design_to',
],
'custom_design_from',
'custom_design_to',
],
'category_view_optimization' => [
],
],
'category_permissions' => [
],
],
];
}

Expand All @@ -671,53 +703,4 @@ private function getFields(): array
$fieldsMap = $this->getFieldsMap();
return $this->arrayUtils->flatten($fieldsMap);
}

/**
* Retrieve scope overridden value
*
* @return ScopeOverriddenValue
* @deprecated 101.1.0
*/
private function getScopeOverriddenValue(): ScopeOverriddenValue
{
if (null === $this->scopeOverriddenValue) {
$this->scopeOverriddenValue = \Magento\Framework\App\ObjectManager::getInstance()->get(
ScopeOverriddenValue::class
);
}

return $this->scopeOverriddenValue;
}

/**
* Retrieve array manager
*
* @return ArrayManager
* @deprecated 101.1.0
*/
private function getArrayManager(): ArrayManager
{
if (null === $this->arrayManager) {
$this->arrayManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
ArrayManager::class
);
}

return $this->arrayManager;
}

/**
* Get FileInfo instance
*
* @return FileInfo
*
* @deprecated 101.1.0
*/
private function getFileInfo(): FileInfo
{
if ($this->fileInfo === null) {
$this->fileInfo = ObjectManager::getInstance()->get(FileInfo::class);
}
return $this->fileInfo;
}
}
Loading

0 comments on commit a12b93b

Please sign in to comment.