diff --git a/app/code/Magento/Catalog/Model/Category/DataProvider.php b/app/code/Magento/Catalog/Model/Category/DataProvider.php
index 283e3f87686b9..fe7258398d191 100644
--- a/app/code/Magento/Catalog/Model/Category/DataProvider.php
+++ b/app/code/Magento/Catalog/Model/Category/DataProvider.php
@@ -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;
@@ -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;
@@ -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.
@@ -39,7 +43,7 @@
* @SuppressWarnings(PHPMD.TooManyFields)
* @since 101.0.0
*/
-class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
+class DataProvider extends ModifierPoolDataProvider
{
/**
* @var string
@@ -106,6 +110,15 @@ 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
@@ -113,13 +126,13 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
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;
@@ -155,7 +168,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
private $arrayUtils;
/**
- * @var Filesystem
+ * @var FileInfo
*/
private $fileInfo;
@@ -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(
@@ -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();
@@ -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);
}
@@ -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
@@ -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,
@@ -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
@@ -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 = [];
@@ -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
@@ -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
*/
@@ -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])) {
@@ -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);
@@ -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' => [
- ],
+ ],
];
}
@@ -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;
- }
}
diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Category/DataProviderTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Category/DataProviderTest.php
index 4c3450d555f1d..4ce50537f27bd 100644
--- a/app/code/Magento/Catalog/Test/Unit/Model/Category/DataProviderTest.php
+++ b/app/code/Magento/Catalog/Test/Unit/Model/Category/DataProviderTest.php
@@ -3,87 +3,101 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+
namespace Magento\Catalog\Test\Unit\Model\Category;
+use Magento\Catalog\Model\Category;
+use Magento\Catalog\Model\Category\Attribute\Backend\Image;
use Magento\Catalog\Model\Category\DataProvider;
use Magento\Catalog\Model\Category\FileInfo;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category\Collection;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
+use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Type;
use Magento\Framework\App\RequestInterface;
+use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Registry;
+use Magento\Framework\Stdlib\ArrayUtils;
+use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
+use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\DataProvider\EavValidationRules;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
-use Magento\Framework\Stdlib\ArrayUtils;
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
-class DataProviderTest extends \PHPUnit\Framework\TestCase
+class DataProviderTest extends TestCase
{
/**
- * @var EavValidationRules|\PHPUnit_Framework_MockObject_MockObject
+ * @var EavValidationRules|MockObject
*/
private $eavValidationRules;
/**
- * @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
+ * @var CollectionFactory|MockObject
*/
private $categoryCollectionFactory;
/**
- * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var StoreManagerInterface|MockObject
*/
private $storeManager;
/**
- * @var Registry|\PHPUnit_Framework_MockObject_MockObject
+ * @var Registry|MockObject
*/
private $registry;
/**
- * @var Config|\PHPUnit_Framework_MockObject_MockObject
+ * @var Config|MockObject
*/
private $eavConfig;
/**
- * @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var RequestInterface|MockObject
*/
private $request;
/**
- * @var CategoryFactory|\PHPUnit_Framework_MockObject_MockObject
+ * @var CategoryFactory|MockObject
*/
private $categoryFactory;
/**
- * @var Collection|\PHPUnit_Framework_MockObject_MockObject
+ * @var Collection|MockObject
*/
private $collection;
/**
- * @var Type|\PHPUnit_Framework_MockObject_MockObject
+ * @var Type|MockObject
*/
private $eavEntityMock;
/**
- * @var FileInfo|\PHPUnit_Framework_MockObject_MockObject
+ * @var FileInfo|MockObject
*/
private $fileInfo;
/**
- * @var PoolInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var PoolInterface|MockObject
*/
private $modifierPool;
/**
- * @var ArrayUtils|\PHPUnit_Framework_MockObject_MockObject
+ * @var ArrayUtils|MockObject
*/
private $arrayUtils;
+ /**
+ * @var AuthorizationInterface|MockObject
+ */
+ private $auth;
+
/**
* @inheritDoc
*/
@@ -96,8 +110,7 @@ protected function setUp()
$this->collection = $this->getMockBuilder(Collection::class)
->disableOriginalConstructor()
->getMock();
- $this->collection->expects($this->any())
- ->method('addAttributeToSelect')
+ $this->collection->method('addAttributeToSelect')
->with('*')
->willReturnSelf();
@@ -105,8 +118,7 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
- $this->categoryCollectionFactory->expects($this->any())
- ->method('create')
+ $this->categoryCollectionFactory->method('create')
->willReturn($this->collection);
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
@@ -138,6 +150,8 @@ protected function setUp()
$this->modifierPool = $this->getMockBuilder(PoolInterface::class)->getMockForAbstractClass();
+ $this->auth = $this->getMockBuilder(AuthorizationInterface::class)->getMockForAbstractClass();
+
$this->arrayUtils = $this->getMockBuilder(ArrayUtils::class)
->setMethods(['flatten'])
->disableOriginalConstructor()->getMock();
@@ -152,12 +166,11 @@ private function getModel()
->method('getAttributeCollection')
->willReturn([]);
- $this->eavConfig->expects($this->any())
- ->method('getEntityType')
+ $this->eavConfig->method('getEntityType')
->with('catalog_category')
->willReturn($this->eavEntityMock);
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $objectManager = new ObjectManager($this);
/** @var DataProvider $model */
$model = $objectManager->getObject(
@@ -171,6 +184,7 @@ private function getModel()
'request' => $this->request,
'categoryFactory' => $this->categoryFactory,
'pool' => $this->modifierPool,
+ 'auth' => $this->auth,
'arrayUtils' => $this->arrayUtils
]
);
@@ -204,18 +218,17 @@ public function testGetDataNoFileExists()
'image' => $fileName,
];
- $imageBackendMock = $this->getMockBuilder(\Magento\Catalog\Model\Category\Attribute\Backend\Image::class)
- ->disableOriginalConstructor()
+ $imageBackendMock = $this->getMockBuilder(Image::class)->disableOriginalConstructor()
->getMock();
- $attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
+ $attributeMock = $this->getMockBuilder(Attribute::class)
->disableOriginalConstructor()
->getMock();
$attributeMock->expects($this->once())
->method('getBackend')
->willReturn($imageBackendMock);
- $categoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Category::class)
+ $categoryMock = $this->getMockBuilder(Category::class)
->disableOriginalConstructor()
->getMock();
$categoryMock->expects($this->exactly(2))
@@ -226,13 +239,11 @@ public function testGetDataNoFileExists()
['image', null, $categoryData['image']],
]
);
- $categoryMock->expects($this->any())
- ->method('getExistsStoreValueFlag')
+ $categoryMock->method('getExistsStoreValueFlag')
->with('url_key')
->willReturn(false);
- $categoryMock->expects($this->any())
- ->method('getStoreId')
- ->willReturn(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
+ $categoryMock->method('getStoreId')
+ ->willReturn(Store::DEFAULT_STORE_ID);
$categoryMock->expects($this->once())
->method('getId')
->willReturn($categoryId);
@@ -253,7 +264,7 @@ public function testGetDataNoFileExists()
$model = $this->getModel();
$result = $model->getData();
- $this->assertTrue(is_array($result));
+ $this->assertInternalType('array', $result);
$this->assertArrayHasKey($categoryId, $result);
$this->assertArrayNotHasKey('image', $result[$categoryId]);
}
@@ -280,18 +291,18 @@ public function testGetData()
],
];
- $imageBackendMock = $this->getMockBuilder(\Magento\Catalog\Model\Category\Attribute\Backend\Image::class)
+ $imageBackendMock = $this->getMockBuilder(Image::class)
->disableOriginalConstructor()
->getMock();
- $attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
+ $attributeMock = $this->getMockBuilder(Attribute::class)
->disableOriginalConstructor()
->getMock();
$attributeMock->expects($this->once())
->method('getBackend')
->willReturn($imageBackendMock);
- $categoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Category::class)
+ $categoryMock = $this->getMockBuilder(Category::class)
->disableOriginalConstructor()
->getMock();
$categoryMock->expects($this->exactly(2))
@@ -302,13 +313,11 @@ public function testGetData()
['image', null, $categoryData['image']],
]
);
- $categoryMock->expects($this->any())
- ->method('getExistsStoreValueFlag')
+ $categoryMock->method('getExistsStoreValueFlag')
->with('url_key')
->willReturn(false);
- $categoryMock->expects($this->any())
- ->method('getStoreId')
- ->willReturn(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
+ $categoryMock->method('getStoreId')
+ ->willReturn(Store::DEFAULT_STORE_ID);
$categoryMock->expects($this->once())
->method('getId')
->willReturn($categoryId);
@@ -340,7 +349,7 @@ public function testGetData()
$model = $this->getModel();
$result = $model->getData();
- $this->assertTrue(is_array($result));
+ $this->assertInternalType('array', $result);
$this->assertArrayHasKey($categoryId, $result);
$this->assertArrayHasKey('image', $result[$categoryId]);
@@ -351,14 +360,14 @@ public function testGetMetaWithoutParentInheritanceResolving()
{
$this->arrayUtils->expects($this->atLeastOnce())->method('flatten')->willReturn([1,3,3]);
- $categoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Category::class)
+ $categoryMock = $this->getMockBuilder(Category::class)
->disableOriginalConstructor()
->getMock();
$this->registry->expects($this->atLeastOnce())
->method('registry')
->with('category')
->willReturn($categoryMock);
- $attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
+ $attributeMock = $this->getMockBuilder(Attribute::class)
->disableOriginalConstructor()
->getMock();
$categoryMock->expects($this->once())
diff --git a/app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml b/app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml
index f2afef1215017..d3689a0db1306 100644
--- a/app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml
+++ b/app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml
@@ -354,7 +354,6 @@
true
- $