From 92862225d2e02f23fb094342a945e07b05b92e94 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Tue, 23 Feb 2016 17:03:41 +0200 Subject: [PATCH 1/5] MAGETWO-49634: Eliminate Magento/Catalog/Ui/DataProvider/Grouper --- .../Test/Unit/Ui/DataProvider/GrouperTest.php | 229 ----------------- .../Form/Modifier/AbstractModifierTest.php | 15 -- .../Form/Modifier/AdvancedPricingTest.php | 10 - .../Catalog/Ui/DataProvider/Grouper.php | 236 ------------------ .../Product/Form/Modifier/AdvancedPricing.php | 9 - .../Product/Form/Modifier/General.php | 28 --- .../Form/Modifier/AdvancedInventoryTest.php | 10 - .../Form/Modifier/AdvancedInventory.php | 9 - .../Product/Form/Modifier/MsrpTest.php | 10 - 9 files changed, 556 deletions(-) delete mode 100644 app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/GrouperTest.php delete mode 100644 app/code/Magento/Catalog/Ui/DataProvider/Grouper.php diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/GrouperTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/GrouperTest.php deleted file mode 100644 index b4b156585bed4..0000000000000 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/GrouperTest.php +++ /dev/null @@ -1,229 +0,0 @@ -objectManager = new ObjectManager($this); - $this->grouper = $this->objectManager->getObject(Grouper::class); - } - - public function testGroupMetaElementMinimalOptions() - { - $meta = [ - 'group1' => [ - 'children' => [ - 'element1' => [ - 'label' => 'Element 1', - 'sortOrder' => 10 - ], - 'element2' => [ - 'label' => 'Element 2', - 'sortOrder' => 20 - ] - ] - ] - ]; - - $elements = ['element1', 'element2']; - - $result = [ - 'group1' => [ - 'children' => [ - 'element1' => [ - 'formElement' => 'container', - 'componentType' => 'container', - 'component' => 'Magento_Ui/js/form/components/group', - 'dataScope' => '', - 'label' => 'Element 1', - 'sortOrder' => 10, - 'children' => [ - 'element1' => [ - 'label' => 'Element 1', - 'sortOrder' => 10, - 'dataScope' => 'element1' - ], - 'element2' => [ - 'label' => 'Element 2', - 'sortOrder' => 20, - 'dataScope' => 'element2' - ] - ] - ] - ] - ] - ]; - - $this->assertSame($result, $this->grouper->groupMetaElements($meta, $elements)); - } - - public function testGroupMetaElementsDifferentGroups() - { - $meta = [ - 'group1' => [ - 'children' => [ - 'element1' => [ - 'label' => 'Element 1', - 'sortOrder' => 10 - ] - ] - ], - 'group2' => [ - 'children' => [ - 'element2' => [ - 'label' => 'Element 2', - 'sortOrder' => 10 - ] - ] - ] - ]; - - $elements = [ - 'element1' => [ - 'requiredMeta' => [ - 'required' => true - ] - ], - 'element2' => [ - 'meta' => [ - 'additionalClasses' => 'inline' - ] - ] - ]; - - $result = [ - 'group1' => [ - 'children' => [ - 'element1' => [ - 'label' => 'Element 1', - 'sortOrder' => 10, - 'required' => true - ] - ] - ], - 'group2' => [ - 'children' => [ - 'element2' => [ - 'label' => 'Element 2', - 'sortOrder' => 10 - ] - ] - ] - ]; - - $this->assertSame($result, $this->grouper->groupMetaElements($meta, $elements)); - } - - public function testGroupMetaElementsFullOptions() - { - $meta = [ - 'group1' => [ - 'children' => [ - 'element1' => [ - 'label' => 'Element 1', - 'sortOrder' => 10 - ], - ] - ], - 'group2' => [ - 'children' => [ - 'element2' => [ - 'label' => 'Element 2', - 'sortOrder' => 10 - ] - ] - ] - ]; - - $elements = [ - 'element1' => [ - 'requiredMeta' => [ - 'required' => true - ], - 'meta' => [ - 'additionalClasses' => 'inline' - ] - ], - 'element2' => [ - 'isTarget' => true, - 'requiredMeta' => [ - 'validation' => [ - 'validate-number' => true - ] - ], - 'meta' => [ - 'additionalClasses' => 'inline last', - 'sortOrder' => 20 - ] - ] - ]; - - $groupOptions = [ - 'targetCode' => 'container1', - 'groupNonSiblings' => true, - 'meta' => [ - 'additionalClasses' => 'group' - ] - ]; - - $result = [ - 'group1' => [ - 'children' => [] - ], - 'group2' => [ - 'children' => [ - 'container1' => [ - 'formElement' => 'container', - 'componentType' => 'container', - 'component' => 'Magento_Ui/js/form/components/group', - 'dataScope' => '', - 'label' => 'Element 2', - 'sortOrder' => 10, - 'additionalClasses' => 'group', - 'children' => [ - 'element1' => [ - 'label' => 'Element 1', - 'sortOrder' => 10, - 'required' => true, - 'additionalClasses' => 'inline', - 'dataScope' => 'element1' - ], - 'element2' => [ - 'label' => 'Element 2', - 'sortOrder' => 20, - 'validation' => [ - 'validate-number' => true - ], - 'additionalClasses' => 'inline last', - 'dataScope' => 'element2' - ] - ] - ] - ] - ] - ]; - - $this->assertSame($result, $this->grouper->groupMetaElements($meta, $elements, $groupOptions)); - } -} diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php index 83286105a0ab6..218507d0dd145 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php @@ -13,7 +13,6 @@ use Magento\Store\Model\Store; use Magento\Ui\DataProvider\Modifier\ModifierInterface; use Magento\Framework\Stdlib\ArrayManager; -use Magento\Catalog\Ui\DataProvider\Grouper; /** * Class AbstractDataProviderTest @@ -51,11 +50,6 @@ abstract class AbstractModifierTest extends \PHPUnit_Framework_TestCase */ protected $arrayManagerMock; - /** - * @var Grouper|\PHPUnit_Framework_MockObject_MockObject - */ - protected $grouperMock; - protected function setUp() { $this->objectManager = new ObjectManager($this); @@ -77,9 +71,6 @@ protected function setUp() $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class) ->disableOriginalConstructor() ->getMock(); - $this->grouperMock = $this->getMockBuilder(Grouper::class) - ->disableOriginalConstructor() - ->getMock(); $this->arrayManagerMock->expects($this->any()) ->method('replace') @@ -93,12 +84,6 @@ protected function setUp() $this->arrayManagerMock->expects($this->any()) ->method('merge') ->willReturnArgument(1); - $this->grouperMock->expects($this->any()) - ->method('groupMetaElements') - ->willReturnArgument(0); - $this->grouperMock->expects($this->any()) - ->method('remove') - ->willReturnArgument(1); $this->arrayManagerMock->expects($this->any()) ->method('remove') ->willReturnArgument(1); diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedPricingTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedPricingTest.php index 14fc7e4757af1..ae8d2f8138529 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedPricingTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedPricingTest.php @@ -6,7 +6,6 @@ namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AdvancedPricing; -use Magento\Catalog\Ui\DataProvider\Grouper; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\Data\GroupInterface as CustomerGroupInterface; use Magento\Customer\Api\GroupManagementInterface; @@ -25,11 +24,6 @@ */ class AdvancedPricingTest extends AbstractModifierTest { - /** - * @var Grouper|\PHPUnit_Framework_MockObject_MockObject - */ - protected $grouperMock; - /** * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -78,9 +72,6 @@ class AdvancedPricingTest extends AbstractModifierTest protected function setUp() { parent::setUp(); - $this->grouperMock = $this->getMockBuilder(Grouper::class) - ->disableOriginalConstructor() - ->getMock(); $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) ->getMockForAbstractClass(); $this->groupRepositoryMock = $this->getMockBuilder(GroupRepositoryInterface::class) @@ -117,7 +108,6 @@ protected function createModel() { return $this->objectManager->getObject(AdvancedPricing::class, [ 'locator' => $this->locatorMock, - 'grouper' => $this->grouperMock, 'storeManager' => $this->storeManagerMock, 'groupRepository' => $this->groupRepositoryMock, 'groupManagement' => $this->groupManagementMock, diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Grouper.php b/app/code/Magento/Catalog/Ui/DataProvider/Grouper.php deleted file mode 100644 index 2cdcca04847c5..0000000000000 --- a/app/code/Magento/Catalog/Ui/DataProvider/Grouper.php +++ /dev/null @@ -1,236 +0,0 @@ - false - ]; - - /** - * @var array - */ - protected $defaultGroupMeta = [ - 'formElement' => 'container', - 'componentType' => 'container', - 'component' => 'Magento_Ui/js/form/components/group', - 'dataScope' => '' - ]; - - /** - * @var array - */ - protected $defaultElementOptions = [ - 'autoDataScope' => true - ]; - - /** - * Return updated metadata with the set of elements put into a group - * - * @param array $meta - * @param array $elements - * @param array $groupOptions - * @return array - */ - public function groupMetaElements(array $meta, array $elements, array $groupOptions = []) - { - if (!$elements) { - return $meta; - } - - $grouped = true; - $this->meta = $meta; - $this->groupOptions = array_replace_recursive($this->defaultGroupOptions, $groupOptions); - $this->groupCode = null; - $this->elementCode = null; - $this->groupMeta = $this->defaultGroupMeta; - $this->elementsMeta = []; - - foreach ($elements as $elementCode => $elementOptions) { - if (!is_array($elementOptions)) { - $elementCode = $elementOptions; - $elementOptions = []; - } - - $meta = $this->applyElementRequiredOptions($meta, $elementCode, $elementOptions); - $grouped = $grouped && $this->handleElementOptions($meta, $elementCode, $elementOptions); - } - - if ($grouped) { - $this->meta[$this->groupCode]['children'][$this->elementCode] = array_replace_recursive( - $this->groupMeta, - ['children' => $this->elementsMeta] - ); - - return $this->meta; - } - - return $meta; - } - - /** - * Handle element options - * - * @param array $meta - * @param string $elementCode - * @param array $elementOptions - * @return bool - */ - protected function handleElementOptions(array $meta, $elementCode, array $elementOptions) - { - $groupCode = $this->getGroupCodeByField($meta, $elementCode); - - if (!$groupCode) { - return false; - } - - if (!$this->groupOptions['groupNonSiblings'] && $this->groupCode && $this->groupCode != $groupCode) { - return false; - } - - $elementOptions = array_replace_recursive($this->defaultElementOptions, $elementOptions); - $this->handleGroupOptions($meta, $groupCode, $elementCode, $elementOptions); - - $this->elementsMeta[$elementCode] = array_replace_recursive( - $meta[$groupCode]['children'][$elementCode], - isset($elementOptions['meta']) ? $elementOptions['meta'] : [] - ); - - if ($elementOptions['autoDataScope']) { - $this->elementsMeta[$elementCode]['dataScope'] = $elementCode; - } - - unset($this->meta[$groupCode]['children'][$elementCode]); - - return true; - } - - /** - * Apply only required portion of element options - * - * @param array $meta - * @param string $elementCode - * @param array $elementOptions - * @return array - */ - protected function applyElementRequiredOptions(array $meta, $elementCode, array $elementOptions) - { - if ($groupCode = $this->getGroupCodeByField($meta, $elementCode)) { - $meta[$groupCode]['children'][$elementCode] = array_replace_recursive( - $meta[$groupCode]['children'][$elementCode], - isset($elementOptions['requiredMeta']) ? $elementOptions['requiredMeta'] : [] - ); - } - - return $meta; - } - - /** - * Handle group options - * - * @param array $meta - * @param string $groupCode - * @param string $elementCode - * @param array $elementOptions - * @return void - */ - protected function handleGroupOptions(array $meta, $groupCode, $elementCode, array $elementOptions) - { - $isTarget = !empty($elementOptions['isTarget']); - - if (!$this->groupCode || $isTarget) { - $this->groupCode = $groupCode; - $this->elementCode = isset($this->groupOptions['targetCode']) - ? $this->groupOptions['targetCode'] - : $elementCode; - $this->groupMeta = array_replace_recursive( - $this->groupMeta, - [ - 'label' => $this->getElementOption($meta, $groupCode, $elementCode, 'label'), - 'sortOrder' => $this->getElementOption($meta, $groupCode, $elementCode, 'sortOrder') - ], - isset($this->groupOptions['meta']) ? $this->groupOptions['meta'] : [] - ); - } - } - - /** - * Retrieve element option from metadata - * - * @param array $meta - * @param string $groupCode - * @param string $elementCode - * @param string $optionName - * @param mixed $defaultValue - * @return mixed - */ - protected function getElementOption(array $meta, $groupCode, $elementCode, $optionName, $defaultValue = null) - { - return isset($meta[$groupCode]['children'][$elementCode][$optionName]) - ? $meta[$groupCode]['children'][$elementCode][$optionName] - : $defaultValue; - } - - /** - * Get group code by field - * - * @param array $meta - * @param string $field - * @return string|bool - */ - protected function getGroupCodeByField(array $meta, $field) - { - foreach ($meta as $groupCode => $groupData) { - if (isset($groupData['children'][$field])) { - return $groupCode; - } - } - - return false; - } -} diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php index dcf586662639f..57ec31fee9218 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php @@ -22,7 +22,6 @@ use Magento\Ui\Component\Form\Element\Select; use Magento\Ui\Component\Form\Field; use Magento\Ui\Component\Modal; -use Magento\Catalog\Ui\DataProvider\Grouper; use Magento\Framework\Stdlib\ArrayManager; /** @@ -37,11 +36,6 @@ class AdvancedPricing extends AbstractModifier */ protected $locator; - /** - * @var Grouper - */ - protected $grouper; - /** * @var ModuleManager */ @@ -84,7 +78,6 @@ class AdvancedPricing extends AbstractModifier /** * @param LocatorInterface $locator - * @param Grouper $grouper * @param StoreManagerInterface $storeManager * @param GroupRepositoryInterface $groupRepository * @param GroupManagementInterface $groupManagement @@ -96,7 +89,6 @@ class AdvancedPricing extends AbstractModifier */ public function __construct( LocatorInterface $locator, - Grouper $grouper, StoreManagerInterface $storeManager, GroupRepositoryInterface $groupRepository, GroupManagementInterface $groupManagement, @@ -106,7 +98,6 @@ public function __construct( ArrayManager $arrayManager ) { $this->locator = $locator; - $this->grouper = $grouper; $this->storeManager = $storeManager; $this->groupRepository = $groupRepository; $this->groupManagement = $groupManagement; diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php index 3151dc0dc00a0..d5878955a5781 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php @@ -8,7 +8,6 @@ use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Ui\Component\Form; -use Magento\Catalog\Ui\DataProvider\Grouper; use Magento\Framework\Stdlib\ArrayManager; /** @@ -21,11 +20,6 @@ class General extends AbstractModifier */ protected $locator; - /** - * @var Grouper - */ - protected $grouper; - /** * @var ArrayManager */ @@ -33,16 +27,13 @@ class General extends AbstractModifier /** * @param LocatorInterface $locator - * @param Grouper $grouper * @param ArrayManager $arrayManager */ public function __construct( LocatorInterface $locator, - Grouper $grouper, ArrayManager $arrayManager ) { $this->locator = $locator; - $this->grouper = $grouper; $this->arrayManager = $arrayManager; } @@ -266,25 +257,6 @@ protected function customizeWeightField(array $meta) ] ] ); - - $meta = $this->grouper->groupMetaElements( - $meta, - [AttributeConstantsInterface::CODE_WEIGHT, AttributeConstantsInterface::CODE_HAS_WEIGHT], - [ - 'meta' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'dataScope' => '', - 'breakLine' => false, - 'scopeLabel' => $this->arrayManager->get($weightPath . '/scopeLabel', $meta) - ], - ], - ], - ], - 'targetCode' => 'container_' . AttributeConstantsInterface::CODE_WEIGHT - ] - ); } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedInventoryTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedInventoryTest.php index fdb6696c52efc..79f7bfeb06536 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedInventoryTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedInventoryTest.php @@ -8,7 +8,6 @@ use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest; use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\CatalogInventory\Model\Source\Stock; -use Magento\Catalog\Ui\DataProvider\Grouper; use Magento\CatalogInventory\Api\Data\StockItemInterface; use Magento\Store\Model\Store; use Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier\AdvancedInventory; @@ -18,11 +17,6 @@ */ class AdvancedInventoryTest extends AbstractModifierTest { - /** - * @var Grouper|\PHPUnit_Framework_MockObject_MockObject - */ - protected $grouperMock; - /** * @var Stock|\PHPUnit_Framework_MockObject_MockObject */ @@ -46,9 +40,6 @@ class AdvancedInventoryTest extends AbstractModifierTest protected function setUp() { parent::setUp(); - $this->grouperMock = $this->getMockBuilder(Grouper::class) - ->disableOriginalConstructor() - ->getMock(); $this->stockMock = $this->getMockBuilder(Stock::class) ->disableOriginalConstructor() ->getMock(); @@ -77,7 +68,6 @@ protected function createModel() { return $this->objectManager->getObject(AdvancedInventory::class, [ 'locator' => $this->locatorMock, - 'grouper' => $this->grouperMock, 'stockRegistry' => $this->stockRegistryMock, 'stock' => $this->stockMock, ]); diff --git a/app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php b/app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php index 8e7d6a68a6e30..008bcbf87963e 100644 --- a/app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php +++ b/app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php @@ -9,7 +9,6 @@ use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\CatalogInventory\Model\Source\Stock; -use Magento\Catalog\Ui\DataProvider\Grouper; use Magento\Framework\Stdlib\ArrayManager; /** @@ -24,11 +23,6 @@ class AdvancedInventory extends AbstractModifier */ protected $locator; - /** - * @var Grouper - */ - protected $grouper; - /** * @var StockRegistryInterface */ @@ -51,20 +45,17 @@ class AdvancedInventory extends AbstractModifier /** * @param LocatorInterface $locator - * @param Grouper $grouper * @param Stock $stock * @param StockRegistryInterface $stockRegistry * @param ArrayManager $arrayManager */ public function __construct( LocatorInterface $locator, - Grouper $grouper, Stock $stock, StockRegistryInterface $stockRegistry, ArrayManager $arrayManager ) { $this->locator = $locator; - $this->grouper = $grouper; $this->stockRegistry = $stockRegistry; $this->stock = $stock; $this->arrayManager = $arrayManager; diff --git a/app/code/Magento/Msrp/Test/Unit/Ui/DataProvider/Product/Form/Modifier/MsrpTest.php b/app/code/Magento/Msrp/Test/Unit/Ui/DataProvider/Product/Form/Modifier/MsrpTest.php index c0e55eb83d246..3e322c27280f2 100644 --- a/app/code/Magento/Msrp/Test/Unit/Ui/DataProvider/Product/Form/Modifier/MsrpTest.php +++ b/app/code/Magento/Msrp/Test/Unit/Ui/DataProvider/Product/Form/Modifier/MsrpTest.php @@ -7,7 +7,6 @@ use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest; use Magento\Msrp\Ui\DataProvider\Product\Form\Modifier\Msrp; -use Magento\Catalog\Ui\DataProvider\Grouper; use Magento\Msrp\Model\Config as MsrpConfig; /** @@ -15,11 +14,6 @@ */ class MsrpTest extends AbstractModifierTest { - /** - * @var Grouper|\PHPUnit_Framework_MockObject_MockObject - */ - protected $grouperMock; - /** * @var MsrpConfig|\PHPUnit_Framework_MockObject_MockObject */ @@ -27,9 +21,6 @@ class MsrpTest extends AbstractModifierTest protected function setUp() { - $this->grouperMock = $this->getMockBuilder(Grouper::class) - ->disableOriginalConstructor() - ->getMock(); $this->msrpConfigMock = $this->getMockBuilder(MsrpConfig::class) ->disableOriginalConstructor() ->getMock(); @@ -43,7 +34,6 @@ protected function createModel() { return $this->objectManager->getObject(Msrp::class, [ 'locator' => $this->locatorMock, - 'grouper' => $this->grouperMock, 'msrpConfig' => $this->msrpConfigMock, ]); } From 49470891de7eb9cd92d62548f6dd9b0819181412 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Tue, 23 Feb 2016 17:30:10 +0200 Subject: [PATCH 2/5] MAGETWO-49634: Eliminate Magento/Catalog/Ui/DataProvider/Grouper --- .../Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php | 1 - .../Unit/Ui/DataProvider/Product/Modifier/GiftMessageTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php index 5f85887501726..0384a2c59993e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php @@ -23,7 +23,6 @@ protected function createModel() { return $this->objectManager->getObject(General::class, [ 'locator' => $this->locatorMock, - 'grouper' => $this->grouperMock, 'arrayManager' => $this->arrayManagerMock, ]); } diff --git a/app/code/Magento/GiftMessage/Test/Unit/Ui/DataProvider/Product/Modifier/GiftMessageTest.php b/app/code/Magento/GiftMessage/Test/Unit/Ui/DataProvider/Product/Modifier/GiftMessageTest.php index dd1914c629924..c9b0163f329bc 100644 --- a/app/code/Magento/GiftMessage/Test/Unit/Ui/DataProvider/Product/Modifier/GiftMessageTest.php +++ b/app/code/Magento/GiftMessage/Test/Unit/Ui/DataProvider/Product/Modifier/GiftMessageTest.php @@ -35,7 +35,6 @@ protected function createModel() { return $this->objectManager->getObject(GiftMessage::class, [ 'locator' => $this->locatorMock, - 'grouper' => $this->grouperMock, 'scopeConfig' => $this->scopeConfigMock, ]); } From 4052c8d80679aa7746759a1a4d647ec7e679534e Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Thu, 25 Feb 2016 18:39:17 +0200 Subject: [PATCH 3/5] MAGETWO-49457: Eliminate interface \Magento\Catalog\Model\AttributeConstantsInterface --- .../Product/Form/Modifier/BundleSkuTest.php | 4 +- .../Form/Modifier/BundleAdvancedPricing.php | 16 +++--- .../Product/Form/Modifier/BundlePrice.php | 8 +-- .../Product/Form/Modifier/BundleSku.php | 8 +-- .../Product/Form/Modifier/BundleWeight.php | 10 ++-- .../Api/Data/ProductAttributeInterface.php | 18 +++++++ .../Model/AttributeConstantsInterface.php | 18 ------- .../Product/Form/Modifier/GeneralTest.php | 1 - .../Product/Form/Modifier/ImagesTest.php | 14 ++--- .../Product/Form/Modifier/AdvancedPricing.php | 18 +++---- .../Product/Form/Modifier/AttributeSet.php | 4 +- .../Product/Form/Modifier/General.php | 52 +++++++++---------- .../Form/Modifier/ProductUrlRewriteTest.php | 4 +- .../Form/Modifier/ProductUrlRewrite.php | 6 +-- .../Form/Modifier/DownloadablePanelTest.php | 5 +- .../Form/Modifier/DownloadablePanel.php | 14 ++--- 16 files changed, 99 insertions(+), 101 deletions(-) diff --git a/app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/Form/Modifier/BundleSkuTest.php b/app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/Form/Modifier/BundleSkuTest.php index 86f3739235a85..ba34843c7ed73 100644 --- a/app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/Form/Modifier/BundleSkuTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/Form/Modifier/BundleSkuTest.php @@ -6,7 +6,7 @@ namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Form\Modifier; use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundleSku; -use Magento\Catalog\Model\AttributeConstantsInterface; +use Magento\Catalog\Api\Data\ProductAttributeInterface; /** * Class BundleSkuTest @@ -31,7 +31,7 @@ public function testModifyMeta() $sourceMeta = [ 'testGroup' => [ 'children' => [ - AttributeConstantsInterface::CODE_SKU => [ + ProductAttributeInterface::CODE_SKU => [ 'componentType' => 'testComponent', ], ] diff --git a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleAdvancedPricing.php b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleAdvancedPricing.php index f75e778fa21b1..d36a7e25fbcef 100644 --- a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleAdvancedPricing.php +++ b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleAdvancedPricing.php @@ -5,8 +5,8 @@ */ namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; -use Magento\Catalog\Model\AttributeConstantsInterface as Constants; /** * Customize Advanced Pricing modal panel @@ -32,13 +32,15 @@ public function modifyMeta(array $meta) unset($parentNode['container_' . self::CODE_MSRP]); unset($parentNode['container_' . self::CODE_MSRP_DISPLAY_ACTUAL_PRICE_TYPE]); } - if (isset($parentNode['container_' . Constants::CODE_SPECIAL_PRICE])) { - $currentNode = &$parentNode['container_' . Constants::CODE_SPECIAL_PRICE]['children']; - $currentNode[Constants::CODE_SPECIAL_PRICE]['arguments']['data']['config']['addbefore'] = "%"; + if (isset($parentNode['container_' . ProductAttributeInterface::CODE_SPECIAL_PRICE])) { + $currentNode = &$parentNode['container_' . ProductAttributeInterface::CODE_SPECIAL_PRICE]['children']; + $currentNode[ProductAttributeInterface::CODE_SPECIAL_PRICE]['arguments']['data']['config']['addbefore'] + = "%"; } - $parentNodeChildren = &$parentNode[Constants::CODE_TIER_PRICE]['children']; - if (isset( $parentNodeChildren[self::CODE_RECORD]['children'][Constants::CODE_PRICE])) { - $currentNode = &$parentNodeChildren[self::CODE_RECORD]['children'][Constants::CODE_PRICE]; + $parentNodeChildren = &$parentNode[ProductAttributeInterface::CODE_TIER_PRICE]['children']; + if (isset($parentNodeChildren[self::CODE_RECORD]['children'][ProductAttributeInterface::CODE_PRICE])) { + $currentNode = + &$parentNodeChildren[self::CODE_RECORD]['children'][ProductAttributeInterface::CODE_PRICE]; $currentNode['arguments']['data']['config']['label'] = __('Percent Discount'); } } diff --git a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePrice.php b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePrice.php index 5d48fe4bab615..48330fa0cf658 100644 --- a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePrice.php +++ b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePrice.php @@ -5,8 +5,8 @@ */ namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Ui\Component\Form; use Magento\Framework\Stdlib\ArrayManager; use Magento\Catalog\Model\Locator\LocatorInterface; @@ -49,11 +49,11 @@ public function __construct( */ public function modifyMeta(array $meta) { - if ($groupCode = $this->getGroupCodeByField($meta, AttributeConstantsInterface::CODE_PRICE) + if ($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_PRICE) ?: $this->getGroupCodeByField($meta, self::CODE_GROUP_PRICE) ) { $isNewProduct = ($this->locator->getProduct()->getId()) ? false : true; - $pricePath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_PRICE) + $pricePath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_PRICE) ?: $this->getElementArrayPath($meta, self::CODE_GROUP_PRICE); $meta[$groupCode]['children'][self::CODE_PRICE_TYPE] = [ @@ -91,7 +91,7 @@ public function modifyMeta(array $meta) $meta[$groupCode]['children'][self::CODE_GROUP_PRICE], [ 'children' => [ - AttributeConstantsInterface::CODE_PRICE => [ + ProductAttributeInterface::CODE_PRICE => [ 'arguments' => [ 'data' => [ 'config' => [ diff --git a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleSku.php b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleSku.php index e676916b0c31c..20f4d2d0055c4 100644 --- a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleSku.php +++ b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleSku.php @@ -5,8 +5,8 @@ */ namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Ui\Component\Form; use Magento\Framework\Stdlib\ArrayManager; @@ -36,15 +36,15 @@ public function __construct(ArrayManager $arrayManager) */ public function modifyMeta(array $meta) { - if ($groupCode = $this->getGroupCodeByField($meta, AttributeConstantsInterface::CODE_SKU)) { - $skuPath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_SKU); + if ($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_SKU)) { + $skuPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_SKU); $meta[$groupCode]['children'][self::CODE_SKU_TYPE] = [ 'arguments' => [ 'data' => [ 'config' => [ 'sortOrder' => $this->getNextAttributeSortOrder( $meta, - [AttributeConstantsInterface::CODE_SKU], + [ProductAttributeInterface::CODE_SKU], self::SORT_ORDER ), 'formElement' => Form\Element\Checkbox::NAME, diff --git a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleWeight.php b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleWeight.php index 0b3d5bf1d371b..0d45cc3d077e6 100644 --- a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleWeight.php +++ b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundleWeight.php @@ -5,8 +5,8 @@ */ namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Ui\Component\Form; use Magento\Framework\Stdlib\ArrayManager; @@ -37,10 +37,10 @@ public function __construct(ArrayManager $arrayManager) */ public function modifyMeta(array $meta) { - if (($groupCode = $this->getGroupCodeByField($meta, AttributeConstantsInterface::CODE_WEIGHT) + if (($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_WEIGHT) ?: $this->getGroupCodeByField($meta, self::CODE_CONTAINER_WEIGHT)) ) { - $weightPath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_WEIGHT) + $weightPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_WEIGHT) ?: $this->getElementArrayPath($meta, self::CODE_CONTAINER_WEIGHT); $meta[$groupCode]['children'][self::CODE_WEIGHT_TYPE] = [ 'arguments' => [ @@ -76,7 +76,7 @@ public function modifyMeta(array $meta) $meta[$groupCode]['children'][self::CODE_CONTAINER_WEIGHT], [ 'children' => [ - AttributeConstantsInterface::CODE_HAS_WEIGHT => [ + ProductAttributeInterface::CODE_HAS_WEIGHT => [ 'arguments' => [ 'data' => [ 'config' => [ @@ -93,7 +93,7 @@ public function modifyMeta(array $meta) $meta[$groupCode]['children'][self::CODE_CONTAINER_WEIGHT], [ 'children' => [ - AttributeConstantsInterface::CODE_WEIGHT => [ + ProductAttributeInterface::CODE_WEIGHT => [ 'arguments' => [ 'data' => [ 'config' => [ diff --git a/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php b/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php index 705f55f93a552..6e25fb1120cb6 100644 --- a/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php +++ b/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php @@ -12,4 +12,22 @@ interface ProductAttributeInterface extends \Magento\Catalog\Api\Data\EavAttributeInterface { const ENTITY_TYPE_CODE = 'catalog_product'; + const CODE_TIER_PRICE_FIELD_PRICE = 'price'; + const CODE_HAS_WEIGHT = 'product_has_weight'; + const CODE_SPECIAL_PRICE = 'special_price'; + const CODE_PRICE = 'price'; + const CODE_TIER_PRICE_FIELD_PRICE_QTY = 'price_qty'; + const CODE_SHORT_DESCRIPTION = 'short_description'; + const CODE_SEO_FIELD_META_TITLE = 'meta_title'; + const CODE_STATUS = 'status'; + const CODE_NAME = 'name'; + const CODE_SKU = 'sku'; + const CODE_SEO_FIELD_META_KEYWORD = 'meta_keyword'; + const CODE_IS_DOWNLOADABLE = 'is_downloadable'; + const CODE_DESCRIPTION = 'description'; + const CODE_COST = 'cost'; + const CODE_SEO_FIELD_URL_KEY = 'url_key'; + const CODE_TIER_PRICE = 'tier_price'; + const CODE_SEO_FIELD_META_DESCRIPTION = 'meta_description'; + const CODE_WEIGHT = 'weight'; } diff --git a/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php b/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php index d19730faecaa9..8fdaa1a7e9e21 100644 --- a/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php +++ b/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php @@ -10,22 +10,4 @@ */ interface AttributeConstantsInterface { - const CODE_NAME = 'name'; - const CODE_PRICE = 'price'; - const CODE_WEIGHT = 'weight'; - const CODE_HAS_WEIGHT = 'product_has_weight'; - const CODE_IS_DOWNLOADABLE = 'is_downloadable'; - const CODE_STATUS = 'status'; - const CODE_DESCRIPTION = 'description'; - const CODE_SHORT_DESCRIPTION = 'short_description'; - const CODE_SPECIAL_PRICE = 'special_price'; - const CODE_COST = 'cost'; - const CODE_TIER_PRICE = 'tier_price'; - const CODE_TIER_PRICE_FIELD_PRICE = 'price'; - const CODE_TIER_PRICE_FIELD_PRICE_QTY = 'price_qty'; - const CODE_SKU = 'sku'; - const CODE_SEO_FIELD_URL_KEY = 'url_key'; - const CODE_SEO_FIELD_META_TITLE = 'meta_title'; - const CODE_SEO_FIELD_META_KEYWORD = 'meta_keyword'; - const CODE_SEO_FIELD_META_DESCRIPTION = 'meta_description'; } diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php index 5f85887501726..e31452999fb27 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php @@ -5,7 +5,6 @@ */ namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Catalog\Model\Product\Type; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\General; diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php index 44801bf0646c4..537bfdab3d4d8 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php @@ -5,8 +5,8 @@ */ namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Model\Product\Type; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\General; /** @@ -32,9 +32,9 @@ public function testModifyData() $data = [ $modelId => [ \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\General::DATA_SOURCE_DEFAULT => [ - AttributeConstantsInterface::CODE_SKU => 'product_42', - AttributeConstantsInterface::CODE_PRICE => '42.00', - AttributeConstantsInterface::CODE_STATUS => '1', + ProductAttributeInterface::CODE_SKU => 'product_42', + ProductAttributeInterface::CODE_PRICE => '42.00', + ProductAttributeInterface::CODE_STATUS => '1', \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Images::CODE_MEDIA_GALLERY => [ 'images' => [ [ @@ -55,9 +55,9 @@ public function testModifyData() $expectedData = [ $modelId => [ General::DATA_SOURCE_DEFAULT => [ - AttributeConstantsInterface::CODE_SKU => 'product_42', - AttributeConstantsInterface::CODE_PRICE => '42.00', - AttributeConstantsInterface::CODE_STATUS => '1', + ProductAttributeInterface::CODE_SKU => 'product_42', + ProductAttributeInterface::CODE_PRICE => '42.00', + ProductAttributeInterface::CODE_STATUS => '1', ] ] ]; diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php index dcf586662639f..566c28437159a 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php @@ -5,8 +5,8 @@ */ namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Model\Locator\LocatorInterface; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Directory\Helper\Data; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\Data\GroupInterface; @@ -123,9 +123,9 @@ public function modifyMeta(array $meta) { $this->meta = $meta; - $this->preparePriceFields(AttributeConstantsInterface::CODE_PRICE); - $this->preparePriceFields(AttributeConstantsInterface::CODE_SPECIAL_PRICE); - $this->preparePriceFields(AttributeConstantsInterface::CODE_COST); + $this->preparePriceFields(ProductAttributeInterface::CODE_PRICE); + $this->preparePriceFields(ProductAttributeInterface::CODE_SPECIAL_PRICE); + $this->preparePriceFields(ProductAttributeInterface::CODE_COST); $this->specialPriceDataToInline(); $this->customizeTierPrice(); @@ -180,7 +180,7 @@ protected function preparePriceFields($fieldCode) */ protected function customizeTierPrice() { - $tierPricePath = $this->getElementArrayPath($this->meta, AttributeConstantsInterface::CODE_TIER_PRICE); + $tierPricePath = $this->getElementArrayPath($this->meta, ProductAttributeInterface::CODE_TIER_PRICE); if ($tierPricePath) { $this->meta = $this->arrayManager->set( @@ -190,7 +190,7 @@ protected function customizeTierPrice() ); $this->meta = $this->arrayManager->set( $this->arrayManager->slicePath($tierPricePath, 0, -3) - . '/' . AttributeConstantsInterface::CODE_TIER_PRICE, + . '/' . ProductAttributeInterface::CODE_TIER_PRICE, $this->meta, $this->arrayManager->get($tierPricePath, $this->meta) ); @@ -241,7 +241,7 @@ protected function isScopeGlobal() { return $this->locator->getProduct() ->getResource() - ->getAttribute(AttributeConstantsInterface::CODE_TIER_PRICE) + ->getAttribute(ProductAttributeInterface::CODE_TIER_PRICE) ->isScopeGlobal(); } @@ -353,7 +353,7 @@ protected function isAllowChangeWebsite() */ protected function addAdvancedPriceLink() { - $pricePath = $this->getElementArrayPath($this->meta, AttributeConstantsInterface::CODE_PRICE); + $pricePath = $this->getElementArrayPath($this->meta, ProductAttributeInterface::CODE_PRICE); if ($pricePath) { $this->meta = $this->arrayManager->merge( @@ -608,7 +608,7 @@ protected function customizeAdvancedPricing() ]; $this->meta = $this->arrayManager->merge( - $this->getElementArrayPath($this->meta, static::CONTAINER_PREFIX . AttributeConstantsInterface::CODE_PRICE), + $this->getElementArrayPath($this->meta, static::CONTAINER_PREFIX . ProductAttributeInterface::CODE_PRICE), $this->meta, [ 'arguments' => [ diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AttributeSet.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AttributeSet.php index 37390754e96d2..ce0a8749caaec 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AttributeSet.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AttributeSet.php @@ -5,7 +5,7 @@ */ namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier; -use Magento\Catalog\Model\AttributeConstantsInterface; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory; use Magento\Store\Model\StoreManagerInterface; @@ -96,7 +96,7 @@ public function modifyMeta(array $meta) 'filterUrl' => $this->urlBuilder->getUrl('catalog/product/suggestAttributeSets', ['isAjax' => 'true']), 'sortOrder' => $this->getNextAttributeSortOrder( $meta, - [AttributeConstantsInterface::CODE_STATUS], + [ProductAttributeInterface::CODE_STATUS], self::ATTRIBUTE_SET_FIELD_ORDER ), 'multiple' => false, diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php index 3151dc0dc00a0..aa1669a62b205 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php @@ -5,7 +5,7 @@ */ namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier; -use Magento\Catalog\Model\AttributeConstantsInterface; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Ui\Component\Form; use Magento\Catalog\Ui\DataProvider\Grouper; @@ -55,8 +55,8 @@ public function modifyData(array $data) $data = $this->customizeAdvancedPriceFormat($data); $modelId = $this->locator->getProduct()->getId(); - if (!isset($data[$modelId][static::DATA_SOURCE_DEFAULT][AttributeConstantsInterface::CODE_STATUS])) { - $data[$modelId][static::DATA_SOURCE_DEFAULT][AttributeConstantsInterface::CODE_STATUS] = '1'; + if (!isset($data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS])) { + $data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS] = '1'; } return $data; @@ -73,10 +73,10 @@ protected function customizeNumberFormat(array $data) $model = $this->locator->getProduct(); $modelId = $model->getId(); $numberFields = [ - AttributeConstantsInterface::CODE_PRICE, - AttributeConstantsInterface::CODE_WEIGHT, - AttributeConstantsInterface::CODE_SPECIAL_PRICE, - AttributeConstantsInterface::CODE_COST, + ProductAttributeInterface::CODE_PRICE, + ProductAttributeInterface::CODE_WEIGHT, + ProductAttributeInterface::CODE_SPECIAL_PRICE, + ProductAttributeInterface::CODE_COST, ]; foreach ($numberFields as $fieldCode) { @@ -113,14 +113,14 @@ protected function formatNumber($number, $decimals = 2) protected function customizeAdvancedPriceFormat(array $data) { $modelId = $this->locator->getProduct()->getId(); - $fieldCode = AttributeConstantsInterface::CODE_TIER_PRICE; + $fieldCode = ProductAttributeInterface::CODE_TIER_PRICE; if (isset($data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode])) { foreach ($data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode] as &$value) { - $value[AttributeConstantsInterface::CODE_TIER_PRICE_FIELD_PRICE] = - $this->formatNumber($value[AttributeConstantsInterface::CODE_TIER_PRICE_FIELD_PRICE]); - $value[AttributeConstantsInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] = - (int)$value[AttributeConstantsInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]; + $value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] = + $this->formatNumber($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]); + $value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] = + (int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]; } } @@ -182,7 +182,7 @@ protected function customizeStatusField(array $meta) ], ]; - $path = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_STATUS); + $path = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_STATUS); $meta = $this->arrayManager->merge($path, $meta, $switcherConfig); return $meta; @@ -196,9 +196,9 @@ protected function customizeStatusField(array $meta) */ protected function customizeWeightField(array $meta) { - if ($weightPath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_WEIGHT)) { + if ($weightPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_WEIGHT)) { if ($this->locator->getProduct()->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL) { - $weightPath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_WEIGHT); + $weightPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_WEIGHT); $meta = $this->arrayManager->merge( $weightPath, $meta, @@ -206,7 +206,7 @@ protected function customizeWeightField(array $meta) 'arguments' => [ 'data' => [ 'config' => [ - 'dataScope' => AttributeConstantsInterface::CODE_WEIGHT, + 'dataScope' => ProductAttributeInterface::CODE_WEIGHT, 'validation' => [ 'validate-number' => true, ], @@ -224,7 +224,7 @@ protected function customizeWeightField(array $meta) $containerPath = $this->getElementArrayPath( $meta, - static::CONTAINER_PREFIX . AttributeConstantsInterface::CODE_WEIGHT + static::CONTAINER_PREFIX . ProductAttributeInterface::CODE_WEIGHT ); $meta = $this->arrayManager->merge($containerPath, $meta, [ 'arguments' => [ @@ -237,7 +237,7 @@ protected function customizeWeightField(array $meta) ]); $hasWeightPath = $this->arrayManager->slicePath($weightPath, 0, -1) . '/' - . AttributeConstantsInterface::CODE_HAS_WEIGHT; + . ProductAttributeInterface::CODE_HAS_WEIGHT; $meta = $this->arrayManager->set( $hasWeightPath, $meta, @@ -269,7 +269,7 @@ protected function customizeWeightField(array $meta) $meta = $this->grouper->groupMetaElements( $meta, - [AttributeConstantsInterface::CODE_WEIGHT, AttributeConstantsInterface::CODE_HAS_WEIGHT], + [ProductAttributeInterface::CODE_WEIGHT, ProductAttributeInterface::CODE_HAS_WEIGHT], [ 'meta' => [ 'arguments' => [ @@ -282,7 +282,7 @@ protected function customizeWeightField(array $meta) ], ], ], - 'targetCode' => 'container_' . AttributeConstantsInterface::CODE_WEIGHT + 'targetCode' => 'container_' . ProductAttributeInterface::CODE_WEIGHT ] ); } @@ -360,10 +360,10 @@ protected function customizeNewDateRangeField(array $meta) protected function customizeNameListeners(array $meta) { $listeners = [ - AttributeConstantsInterface::CODE_SKU, - AttributeConstantsInterface::CODE_SEO_FIELD_META_TITLE, - AttributeConstantsInterface::CODE_SEO_FIELD_META_KEYWORD, - AttributeConstantsInterface::CODE_SEO_FIELD_META_DESCRIPTION, + ProductAttributeInterface::CODE_SKU, + ProductAttributeInterface::CODE_SEO_FIELD_META_TITLE, + ProductAttributeInterface::CODE_SEO_FIELD_META_KEYWORD, + ProductAttributeInterface::CODE_SEO_FIELD_META_DESCRIPTION, ]; foreach ($listeners as $listener) { $listenerPath = $this->getElementArrayPath($meta, $listener); @@ -383,7 +383,7 @@ protected function customizeNameListeners(array $meta) $meta = $this->arrayManager->merge($listenerPath, $meta, $importsConfig); } - $skuPath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_SKU); + $skuPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_SKU); $meta = $this->arrayManager->merge( $skuPath, $meta, @@ -399,7 +399,7 @@ protected function customizeNameListeners(array $meta) ] ); - $namePath = $this->getElementArrayPath($meta, AttributeConstantsInterface::CODE_NAME); + $namePath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_NAME); return $this->arrayManager->merge( $namePath, diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewriteTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewriteTest.php index f1c11fe564b38..e23f480bb8a38 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewriteTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewriteTest.php @@ -5,7 +5,7 @@ */ namespace Magento\CatalogUrlRewrite\Test\Unit\Ui\DataProvider\Product\Form\Modifier; -use Magento\Catalog\Model\AttributeConstantsInterface; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest; use Magento\CatalogUrlRewrite\Ui\DataProvider\Product\Form\Modifier\ProductUrlRewrite; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -47,7 +47,7 @@ public function testModifyMeta() $this->assertNotEmpty($this->getModel()->modifyMeta([ 'test_group_code' => [ 'children' => [ - AttributeConstantsInterface::CODE_SEO_FIELD_URL_KEY => [ + ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY => [ 'label' => 'label', 'scopeLabel' => 'scopeLabel', ], diff --git a/app/code/Magento/CatalogUrlRewrite/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewrite.php b/app/code/Magento/CatalogUrlRewrite/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewrite.php index e4af2c6a3f359..4c166913c78bb 100644 --- a/app/code/Magento/CatalogUrlRewrite/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewrite.php +++ b/app/code/Magento/CatalogUrlRewrite/Ui/DataProvider/Product/Form/Modifier/ProductUrlRewrite.php @@ -5,11 +5,11 @@ */ namespace Magento\CatalogUrlRewrite\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\Store\Model\ScopeInterface; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Catalog\Model\AttributeConstantsInterface as AC; use Magento\Ui\Component\Form\Element\Checkbox; use Magento\Ui\Component\Form\Element\DataType\Text; use Magento\Ui\Component\Form\Field; @@ -80,7 +80,7 @@ public function modifyData(array $data) */ protected function addUrlRewriteCheckbox(array $meta) { - $urlPath = $this->getElementArrayPath($meta, AC::CODE_SEO_FIELD_URL_KEY); + $urlPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY); if ($urlPath) { $containerPath = $this->arrayManager->slicePath($urlPath, 0, -2); @@ -111,7 +111,7 @@ protected function addUrlRewriteCheckbox(array $meta) 'true' => $urlKey ], 'imports' => [ - 'handleChanges' => '${ $.provider }:data.product.' . AC::CODE_SEO_FIELD_URL_KEY, + 'handleChanges' => '${ $.provider }:data.product.' . ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY, ], 'description' => __('Create Permanent Redirect for old URL'), 'dataScope' => 'url_key_create_redirect', diff --git a/app/code/Magento/Downloadable/Test/Unit/Ui/DataProvider/Product/Form/Modifier/DownloadablePanelTest.php b/app/code/Magento/Downloadable/Test/Unit/Ui/DataProvider/Product/Form/Modifier/DownloadablePanelTest.php index 88a692e68971d..80883aaa78818 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Ui/DataProvider/Product/Form/Modifier/DownloadablePanelTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Ui/DataProvider/Product/Form/Modifier/DownloadablePanelTest.php @@ -11,9 +11,6 @@ use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Framework\Stdlib\ArrayManager; use Magento\Catalog\Api\Data\ProductInterface; -use Magento\Catalog\Model\AttributeConstantsInterface; -use Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Composite; -use Magento\Ui\Component\Container; use Magento\Ui\Component\Form; /** @@ -85,7 +82,7 @@ public function testModifyData($typeId, $isDownloadable) ->willReturn($typeId); $resultData = [ $productId => [ - AttributeConstantsInterface::CODE_IS_DOWNLOADABLE => $isDownloadable + ObjectManagerHelper::CODE_IS_DOWNLOADABLE => $isDownloadable ] ]; diff --git a/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php b/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php index 654672d6b8d2d..e2e27a70e3b6f 100644 --- a/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php +++ b/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php @@ -5,8 +5,8 @@ */ namespace Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; -use Magento\Catalog\Model\AttributeConstantsInterface; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Downloadable\Model\Product\Type; use Magento\Framework\Stdlib\ArrayManager; @@ -50,7 +50,7 @@ public function modifyData(array $data) { $model = $this->locator->getProduct(); - $data[$model->getId()][AttributeConstantsInterface::CODE_IS_DOWNLOADABLE] = + $data[$model->getId()][ProductAttributeInterface::CODE_IS_DOWNLOADABLE] = ($model->getTypeId() === Type::TYPE_DOWNLOADABLE) ? '1' : '0'; return $data; @@ -95,7 +95,7 @@ protected function addMessageBox() 'visible' => false, 'imports' => [ 'visible' => '${$.provider}:' . self::DATA_SCOPE_PRODUCT . '.' - . AttributeConstantsInterface::CODE_HAS_WEIGHT + . ProductAttributeInterface::CODE_HAS_WEIGHT ], ]; @@ -109,18 +109,18 @@ protected function addMessageBox() */ protected function addCheckboxIsDownloadable() { - $checkboxPath = Composite::CHILDREN_PATH . '/' . AttributeConstantsInterface::CODE_IS_DOWNLOADABLE; + $checkboxPath = Composite::CHILDREN_PATH . '/' . ProductAttributeInterface::CODE_IS_DOWNLOADABLE; $checkboxConfig['arguments']['data']['config'] = [ 'dataType' => Form\Element\DataType\Number::NAME, 'formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'component' => 'Magento_Downloadable/js/components/is-downloadable-handler', 'description' => __('Is this downloadable Product?'), - 'dataScope' => AttributeConstantsInterface::CODE_IS_DOWNLOADABLE, + 'dataScope' => ProductAttributeInterface::CODE_IS_DOWNLOADABLE, 'sortOrder' => 10, 'imports' => [ 'disabled' => '${$.provider}:' . self::DATA_SCOPE_PRODUCT . '.' - . AttributeConstantsInterface::CODE_HAS_WEIGHT + . ProductAttributeInterface::CODE_HAS_WEIGHT ], 'valueMap' => [ 'false' => '0', @@ -134,7 +134,7 @@ protected function addCheckboxIsDownloadable() 'formElement' => Form\Element\Hidden::NAME, 'componentType' => Form\Field::NAME, 'value' => '1', - 'dataScope' => AttributeConstantsInterface::CODE_IS_DOWNLOADABLE, + 'dataScope' => ProductAttributeInterface::CODE_IS_DOWNLOADABLE, 'sortOrder' => 10, ]; From 7fda7bf7d1f44edcfd4728a95753f725395eccf1 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Fri, 26 Feb 2016 11:31:55 +0200 Subject: [PATCH 4/5] MAGETWO-49457: Eliminate interface \Magento\Catalog\Model\AttributeConstantsInterface --- .../Catalog/Api/Data/ProductAttributeInterface.php | 1 - .../Catalog/Model/AttributeConstantsInterface.php | 13 ------------- .../Product/Form/Modifier/ProductUrlRewrite.php | 3 ++- .../Api/Data/ProductAttributeInterface.php | 14 ++++++++++++++ .../Form/Modifier/DownloadablePanelTest.php | 3 ++- .../Product/Form/Modifier/DownloadablePanel.php | 3 ++- 6 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 app/code/Magento/Catalog/Model/AttributeConstantsInterface.php create mode 100644 app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php diff --git a/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php b/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php index 6e25fb1120cb6..8d6b3e46b2eb4 100644 --- a/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php +++ b/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php @@ -23,7 +23,6 @@ interface ProductAttributeInterface extends \Magento\Catalog\Api\Data\EavAttribu const CODE_NAME = 'name'; const CODE_SKU = 'sku'; const CODE_SEO_FIELD_META_KEYWORD = 'meta_keyword'; - const CODE_IS_DOWNLOADABLE = 'is_downloadable'; const CODE_DESCRIPTION = 'description'; const CODE_COST = 'cost'; const CODE_SEO_FIELD_URL_KEY = 'url_key'; diff --git a/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php b/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php deleted file mode 100644 index 8fdaa1a7e9e21..0000000000000 --- a/app/code/Magento/Catalog/Model/AttributeConstantsInterface.php +++ /dev/null @@ -1,13 +0,0 @@ - $urlKey ], 'imports' => [ - 'handleChanges' => '${ $.provider }:data.product.' . ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY, + 'handleChanges' => '${ $.provider }:data.product.' + . ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY, ], 'description' => __('Create Permanent Redirect for old URL'), 'dataScope' => 'url_key_create_redirect', diff --git a/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php b/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php new file mode 100644 index 0000000000000..dcd434fcf9674 --- /dev/null +++ b/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php @@ -0,0 +1,14 @@ +willReturn($typeId); $resultData = [ $productId => [ - ObjectManagerHelper::CODE_IS_DOWNLOADABLE => $isDownloadable + ProductAttributeInterface::CODE_IS_DOWNLOADABLE => $isDownloadable ] ]; diff --git a/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php b/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php index e2e27a70e3b6f..33e275b7d36ff 100644 --- a/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php +++ b/app/code/Magento/Downloadable/Ui/DataProvider/Product/Form/Modifier/DownloadablePanel.php @@ -5,9 +5,9 @@ */ namespace Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier; -use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\Catalog\Model\Locator\LocatorInterface; +use Magento\Downloadable\Api\Data\ProductAttributeInterface; use Magento\Downloadable\Model\Product\Type; use Magento\Framework\Stdlib\ArrayManager; use Magento\Ui\Component\Container; @@ -15,6 +15,7 @@ /** * Class adds Downloadable collapsible panel + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class DownloadablePanel extends AbstractModifier { From 899c0c61f6bf3f1af5ced65566d7d7a6b02fe897 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Fri, 26 Feb 2016 12:11:03 +0200 Subject: [PATCH 5/5] MAGETWO-49457: Eliminate interface \Magento\Catalog\Model\AttributeConstantsInterface --- .../Magento/Downloadable/Api/Data/ProductAttributeInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php b/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php index dcd434fcf9674..f05806d163314 100644 --- a/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php +++ b/app/code/Magento/Downloadable/Api/Data/ProductAttributeInterface.php @@ -11,4 +11,4 @@ interface ProductAttributeInterface extends \Magento\Catalog\Api\Data\ProductAttributeInterface { const CODE_IS_DOWNLOADABLE = 'is_downloadable'; -} \ No newline at end of file +}