Skip to content

Commit 1f37b76

Browse files
committed
Merge pull request #396 from magento-folks/catalog_product
[Folks] Catalog product interface
2 parents 7211a23 + 243c744 commit 1f37b76

File tree

22 files changed

+153
-74
lines changed

22 files changed

+153
-74
lines changed

app/code/Magento/Bundle/etc/adminhtml/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</argument>
2020
</arguments>
2121
</type>
22-
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\ModifierPool">
22+
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
2323
<arguments>
2424
<argument name="modifiers" xsi:type="array">
2525
<item name="bundle" xsi:type="array">
@@ -32,7 +32,7 @@
3232
</item>
3333
</argument>
3434
</arguments>
35-
</type>
35+
</virtualType>
3636
<type name="Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\Composite">
3737
<arguments>
3838
<argument name="modifiers" xsi:type="array">

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/SystemTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected function createModel()
3737
return $this->objectManager->getObject(System::class, [
3838
'locator' => $this->locatorMock,
3939
'urlBuilder' => $this->urlBuilderMock,
40+
'productUrls' => []
4041
]);
4142
}
4243

@@ -80,9 +81,9 @@ public function testModifyData()
8081
$this->urlBuilderMock->expects($this->exactly(3))
8182
->method('getUrl')
8283
->willReturnMap([
83-
[System::URL_SUBMIT, $actionParameters, $submitUrl],
84-
[System::URL_VALIDATE, $actionParameters, $validateUrl],
85-
[System::URL_RELOAD, $reloadParameters, $reloadUrl],
84+
['catalog/product/save', $actionParameters, $submitUrl],
85+
['catalog/product/validate', $actionParameters, $validateUrl],
86+
['catalog/product/reload', $reloadParameters, $reloadUrl],
8687
]);
8788

8889
$expectedData = [

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class AdvancedPricing extends AbstractModifier
7777
*/
7878
protected $arrayManager;
7979

80+
/**
81+
* @var string
82+
*/
83+
protected $targetName = 'product_form.product_form';
84+
8085
/**
8186
* @var array
8287
*/
@@ -370,7 +375,7 @@ protected function addAdvancedPriceLink()
370375
'template' => 'ui/form/components/button/container',
371376
'actions' => [
372377
[
373-
'targetName' => 'product_form.product_form.advanced_pricing_modal',
378+
'targetName' => $this->targetName . '.advanced_pricing_modal',
374379
'actionName' => 'toggleModal',
375380
]
376381
],

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,36 @@ class CustomOptions extends AbstractModifier
121121
*/
122122
protected $meta = [];
123123

124+
/**
125+
* @var string
126+
*/
127+
protected $scopeName;
128+
124129
/**
125130
* @param LocatorInterface $locator
126131
* @param StoreManagerInterface $storeManager
127132
* @param ConfigInterface $productOptionsConfig
128133
* @param ProductOptionsPrice $productOptionsPrice
129134
* @param UrlInterface $urlBuilder
130135
* @param ArrayManager $arrayManager
136+
* @param string $scopeName
131137
*/
132138
public function __construct(
133139
LocatorInterface $locator,
134140
StoreManagerInterface $storeManager,
135141
ConfigInterface $productOptionsConfig,
136142
ProductOptionsPrice $productOptionsPrice,
137143
UrlInterface $urlBuilder,
138-
ArrayManager $arrayManager
144+
ArrayManager $arrayManager,
145+
$scopeName = ''
139146
) {
140147
$this->locator = $locator;
141148
$this->storeManager = $storeManager;
142149
$this->productOptionsConfig = $productOptionsConfig;
143150
$this->productOptionsPrice = $productOptionsPrice;
144151
$this->urlBuilder = $urlBuilder;
145152
$this->arrayManager = $arrayManager;
153+
$this->scopeName = $scopeName;
146154
}
147155

148156
/**
@@ -287,7 +295,7 @@ protected function getHeaderContainerConfig($sortOrder)
287295
'component' => 'Magento_Ui/js/form/components/button',
288296
'actions' => [
289297
[
290-
'targetName' => 'product_form.product_form.'
298+
'targetName' => $this->scopeName . '.'
291299
. static::GROUP_CUSTOM_OPTIONS_NAME . '.' . static::IMPORT_OPTIONS_MODAL,
292300
'actionName' => 'toggleModal',
293301
]
@@ -309,7 +317,7 @@ protected function getHeaderContainerConfig($sortOrder)
309317
'sortOrder' => 20,
310318
'actions' => [
311319
[
312-
'targetName' => 'product_form.product_form.'
320+
'targetName' => $this->scopeName . '.'
313321
. static::GROUP_CUSTOM_OPTIONS_NAME . '.' . static::GRID_OPTIONS_NAME,
314322
'actionName' => 'addChild',
315323
]
@@ -1007,7 +1015,7 @@ protected function getProductOptionTypes()
10071015
foreach ($this->productOptionsConfig->getAll() as $option) {
10081016
$group = [
10091017
'value' => $groupIndex,
1010-
'label' => __($option['label']),
1018+
'label' => $option['label'],
10111019
'optgroup' => []
10121020
];
10131021

@@ -1016,7 +1024,7 @@ protected function getProductOptionTypes()
10161024
continue;
10171025
}
10181026

1019-
$group['optgroup'][] = ['label' => __($type['label']), 'value' => $type['name']];
1027+
$group['optgroup'][] = ['label' => $type['label'], 'value' => $type['name']];
10201028
}
10211029

10221030
if (count($group['optgroup'])) {

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ class Eav extends AbstractModifier
139139
*/
140140
private $bannedInputTypes = ['media_image'];
141141

142+
/**
143+
* @var array
144+
*/
145+
private $attributesToDisable;
146+
147+
/**
148+
* @var array
149+
*/
150+
private $attributesToEliminate;
151+
142152
/**
143153
* Initialize dependencies
144154
*
@@ -157,6 +167,8 @@ class Eav extends AbstractModifier
157167
* @param EavAttributeFactory $eavAttributeFactory
158168
* @param Translit $translitFilter
159169
* @param ScopeOverriddenValue $scopeOverriddenValue
170+
* @param array $attributesToDisable
171+
* @param array $attributesToEliminate
160172
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
161173
*/
162174
public function __construct(
@@ -174,7 +186,9 @@ public function __construct(
174186
SortOrderBuilder $sortOrderBuilder,
175187
EavAttributeFactory $eavAttributeFactory,
176188
Translit $translitFilter,
177-
ScopeOverriddenValue $scopeOverriddenValue
189+
ScopeOverriddenValue $scopeOverriddenValue,
190+
$attributesToDisable = [],
191+
$attributesToEliminate = []
178192
) {
179193
$this->locator = $locator;
180194
$this->eavValidationRules = $eavValidationRules;
@@ -191,6 +205,8 @@ public function __construct(
191205
$this->eavAttributeFactory = $eavAttributeFactory;
192206
$this->translitFilter = $translitFilter;
193207
$this->scopeOverriddenValue = $scopeOverriddenValue;
208+
$this->attributesToDisable = $attributesToDisable;
209+
$this->attributesToEliminate = $attributesToEliminate;
194210
}
195211

196212
/**
@@ -204,7 +220,7 @@ public function modifyMeta(array $meta)
204220
if ($attributes) {
205221
$meta[$groupCode]['children'] = $this->getAttributesMeta($attributes, $groupCode);
206222
$meta[$groupCode]['arguments']['data']['config']['componentType'] = Fieldset::NAME;
207-
$meta[$groupCode]['arguments']['data']['config']['label'] = __($group->getAttributeGroupName());
223+
$meta[$groupCode]['arguments']['data']['config']['label'] = $group->getAttributeGroupName();
208224
$meta[$groupCode]['arguments']['data']['config']['collapsible'] = true;
209225
$meta[$groupCode]['arguments']['data']['config']['dataScope'] = self::DATA_SCOPE_PRODUCT;
210226
$meta[$groupCode]['arguments']['data']['config']['sortOrder'] =
@@ -223,6 +239,8 @@ public function modifyMeta(array $meta)
223239
* @param string $groupCode
224240
* @return array
225241
* @throws \Magento\Framework\Exception\LocalizedException
242+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
243+
* @SuppressWarnings(PHPMD.NPathComplexity)
226244
*/
227245
protected function getAttributesMeta(array $attributes, $groupCode)
228246
{
@@ -234,16 +252,19 @@ protected function getAttributesMeta(array $attributes, $groupCode)
234252
}
235253

236254
$code = $attribute->getAttributeCode();
237-
$child = $this->setupMetaProperties($attribute);
255+
if (in_array($code, $this->attributesToEliminate)) {
256+
continue;
257+
}
238258

259+
$child = $this->setupMetaProperties($attribute);
239260
$meta[static::CONTAINER_PREFIX . $code] = [
240261
'arguments' => [
241262
'data' => [
242263
'config' => [
243264
'formElement' => 'container',
244265
'componentType' => 'container',
245266
'breakLine' => false,
246-
'label' => __($attribute->getDefaultFrontendLabel()),
267+
'label' => $attribute->getDefaultFrontendLabel(),
247268
'sortOrder' => $sortKey * self::SORT_ORDER_MULTIPLIER,
248269
'required' => $attribute->getIsRequired(),
249270
],
@@ -266,6 +287,9 @@ protected function getAttributesMeta(array $attributes, $groupCode)
266287
$child['arguments']['data']['config']['componentType'] = Field::NAME;
267288
}
268289

290+
if (in_array($code, $this->attributesToDisable)) {
291+
$child['arguments']['data']['config']['disabled'] = true;
292+
}
269293
// TODO: getAttributeModel() should not be used when MAGETWO-48284 is complete
270294
if (($rules = $this->eavValidationRules->build($this->getAttributeModel($attribute), $child))) {
271295
$child['arguments']['data']['config']['validation'] = $rules;
@@ -444,7 +468,7 @@ protected function setupMetaProperties(ProductAttributeInterface $attribute)
444468
'required' => $attribute->getIsRequired(),
445469
'notice' => $attribute->getNote(),
446470
'default' => $attribute->getDefaultValue(),
447-
'label' => __($attribute->getDefaultFrontendLabel()),
471+
'label' => $attribute->getDefaultFrontendLabel(),
448472
],
449473
],
450474
],

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Related.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class Related extends AbstractModifier
7878
*/
7979
protected $attributeSetRepository;
8080

81+
/**
82+
* @var string
83+
*/
84+
protected $scopeName;
85+
8186
/**
8287
* @param LocatorInterface $locator
8388
* @param UrlInterface $urlBuilder
@@ -86,6 +91,7 @@ class Related extends AbstractModifier
8691
* @param ImageHelper $imageHelper
8792
* @param Status $status
8893
* @param AttributeSetRepositoryInterface $attributeSetRepository
94+
* @param string $scopeName
8995
*/
9096
public function __construct(
9197
LocatorInterface $locator,
@@ -94,7 +100,8 @@ public function __construct(
94100
ProductRepositoryInterface $productRepository,
95101
ImageHelper $imageHelper,
96102
Status $status,
97-
AttributeSetRepositoryInterface $attributeSetRepository
103+
AttributeSetRepositoryInterface $attributeSetRepository,
104+
$scopeName = ''
98105
) {
99106
$this->locator = $locator;
100107
$this->urlBuilder = $urlBuilder;
@@ -103,6 +110,7 @@ public function __construct(
103110
$this->imageHelper = $imageHelper;
104111
$this->status = $status;
105112
$this->attributeSetRepository = $attributeSetRepository;
113+
$this->scopeName = $scopeName;
106114
}
107115

108116
/**
@@ -333,7 +341,7 @@ protected function getCrossSellFieldset()
333341
*/
334342
protected function getButtonSet(Phrase $content, Phrase $buttonTitle, $scope)
335343
{
336-
$modalTarget = 'product_form.product_form.' . static::GROUP_RELATED . '.' . $scope . '.modal';
344+
$modalTarget = $this->scopeName . '.' . static::GROUP_RELATED . '.' . $scope . '.modal';
337345

338346
return [
339347
'arguments' => [
@@ -365,7 +373,7 @@ protected function getButtonSet(Phrase $content, Phrase $buttonTitle, $scope)
365373
'actionName' => 'render',
366374
]
367375
],
368-
'title' => __($buttonTitle),
376+
'title' => $buttonTitle,
369377
'provider' => null,
370378
],
371379
],
@@ -591,7 +599,7 @@ protected function getTextColumn($dataScope, $fit, $label, $sortOrder)
591599
'dataType' => Text::NAME,
592600
'dataScope' => $dataScope,
593601
'fit' => $fit,
594-
'label' => __($label),
602+
'label' => $label,
595603
'sortOrder' => $sortOrder,
596604
],
597605
],

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/System.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
use Magento\Catalog\Model\Locator\LocatorInterface;
99
use Magento\Framework\UrlInterface;
10-
use Magento\Store\Model\StoreManagerInterface;
11-
use Magento\Ui\Component\Form\Fieldset;
1210

1311
/**
1412
* Class SystemDataProvider
@@ -18,9 +16,6 @@ class System extends AbstractModifier
1816
const KEY_SUBMIT_URL = 'submit_url';
1917
const KEY_VALIDATE_URL = 'validate_url';
2018
const KEY_RELOAD_URL = 'reloadUrl';
21-
const URL_SUBMIT = 'catalog/product/save';
22-
const URL_VALIDATE = 'catalog/product/validate';
23-
const URL_RELOAD = 'catalog/product/reload';
2419

2520
/**
2621
* @var LocatorInterface
@@ -32,14 +27,28 @@ class System extends AbstractModifier
3227
*/
3328
protected $urlBuilder;
3429

30+
/**
31+
* @var array
32+
*/
33+
protected $productUrls = [
34+
self::KEY_SUBMIT_URL => 'catalog/product/save',
35+
self::KEY_VALIDATE_URL => 'catalog/product/validate',
36+
self::KEY_RELOAD_URL => 'catalog/product/reload'
37+
];
38+
3539
/**
3640
* @param LocatorInterface $locator
3741
* @param UrlInterface $urlBuilder
42+
* @param array $productUrls
3843
*/
39-
public function __construct(LocatorInterface $locator, UrlInterface $urlBuilder)
40-
{
44+
public function __construct(
45+
LocatorInterface $locator,
46+
UrlInterface $urlBuilder,
47+
array $productUrls = []
48+
) {
4149
$this->locator = $locator;
4250
$this->urlBuilder = $urlBuilder;
51+
$this->productUrls = array_replace_recursive($this->productUrls, $productUrls);
4352
}
4453

4554
/**
@@ -65,13 +74,17 @@ public function modifyData(array $data)
6574
]
6675
);
6776

77+
$submitUrl = $this->urlBuilder->getUrl($this->productUrls[self::KEY_SUBMIT_URL], $actionParameters);
78+
$validateUrl = $this->urlBuilder->getUrl($this->productUrls[self::KEY_VALIDATE_URL], $actionParameters);
79+
$reloadUrl = $this->urlBuilder->getUrl($this->productUrls[self::KEY_RELOAD_URL], $reloadParameters);
80+
6881
return array_replace_recursive(
6982
$data,
7083
[
7184
'config' => [
72-
self::KEY_SUBMIT_URL => $this->urlBuilder->getUrl(self::URL_SUBMIT, $actionParameters),
73-
self::KEY_VALIDATE_URL => $this->urlBuilder->getUrl(self::URL_VALIDATE, $actionParameters),
74-
self::KEY_RELOAD_URL => $this->urlBuilder->getUrl(self::URL_RELOAD, $reloadParameters),
85+
self::KEY_SUBMIT_URL => $submitUrl,
86+
self::KEY_VALIDATE_URL => $validateUrl,
87+
self::KEY_RELOAD_URL => $reloadUrl,
7588
]
7689
]
7790
);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/ModifierPool.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)