Skip to content

Commit fb4d381

Browse files
MAGETWO-48516: Most of category fields don't have Use Default Value option in Store/StoreView scope on the redesigned category page
1 parent 36f08f0 commit fb4d381

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public function getMeta()
174174
$meta = parent::getMeta();
175175
$meta = $this->prepareMeta($meta);
176176
$meta = $this->addUseDefaultValueCheckbox($this->getCurrentCategory(), $meta);
177+
$meta = $this->resolveParentInheritance($this->getCurrentCategory(), $meta);
177178

178179
return $meta;
179180
}
@@ -191,14 +192,14 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta)
191192
$canDisplayUseDefault = $attribute->getScope() != EavAttributeInterface::SCOPE_GLOBAL_TEXT
192193
&& $category->getId()
193194
&& $category->getStoreId();
194-
$sectionName = $this->getSectionName($meta, $attributeCode);
195+
$attributePath = $this->getArrayManager()->findPath($attributeCode, $meta);
195196

196-
if (!$sectionName || !$canDisplayUseDefault) {
197+
if (!$attributePath || !$canDisplayUseDefault || $attribute->getFrontendInput() === 'image') {
197198
continue;
198199
}
199200

200-
$meta = $this->getArrayManager()->set(
201-
[$sectionName, 'children', $attributeCode, 'arguments/data/config'],
201+
$meta = $this->getArrayManager()->merge(
202+
[$attributePath, 'arguments/data/config'],
202203
$meta,
203204
[
204205
'service' => [
@@ -218,12 +219,33 @@ private function addUseDefaultValueCheckbox(Category $category, array $meta)
218219
return $meta;
219220
}
220221

222+
/**
223+
* Removes not necessary inheritance fields
224+
*
225+
* @param Category $category
226+
* @param array $meta
227+
* @return array
228+
*/
229+
private function resolveParentInheritance(Category $category, array $meta)
230+
{
231+
if (!$category->getParentId() || !$this->getArrayManager()->findPath('custom_use_parent_settings', $meta)) {
232+
return $meta;
233+
}
234+
235+
$meta = $this->getArrayManager()->merge(
236+
[$this->getArrayManager()->findPath('custom_use_parent_settings', $meta), 'arguments/data/config'],
237+
$meta,
238+
['visible' => false]
239+
);
240+
241+
return $meta;
242+
}
243+
221244
/**
222245
* Prepare meta data
223246
*
224247
* @param array $meta
225248
* @return array
226-
* @deprecated
227249
*/
228250
public function prepareMeta($meta)
229251
{
@@ -549,24 +571,6 @@ protected function getFieldsMap()
549571
];
550572
}
551573

552-
/**
553-
* Retrieve section name by attribute code
554-
*
555-
* @param array $meta
556-
* @param string $attributeCode
557-
* @return string|null
558-
*/
559-
private function getSectionName(array $meta, $attributeCode)
560-
{
561-
foreach ($meta as $name => $section) {
562-
if (isset($section['children'][$attributeCode])) {
563-
return $name;
564-
}
565-
}
566-
567-
return null;
568-
}
569-
570574
/**
571575
* Retrieve scope overridden value
572576
*

app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,18 @@
453453
<field name="custom_use_parent_settings">
454454
<argument name="data" xsi:type="array">
455455
<item name="config" xsi:type="array">
456-
<item name="additionalClasses" xsi:type="string">admin__field-no-label</item>
456+
<item name="additionalClasses" xsi:type="string">admin__field-x-small</item>
457457
<item name="sortOrder" xsi:type="number">170</item>
458-
<item name="label" xsi:type="string"/>
459-
<item name="description" xsi:type="string" translate="true">Use Parent Category Settings</item>
458+
<item name="label" xsi:type="string">Use Parent Category Settings</item>
460459
<item name="dataType" xsi:type="string">boolean</item>
461460
<item name="formElement" xsi:type="string">checkbox</item>
462461
<item name="valueMap" xsi:type="array">
463462
<item name="true" xsi:type="string">1</item>
464463
<item name="false" xsi:type="string">0</item>
465464
</item>
466465
<item name="default" xsi:type="string">0</item>
466+
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox</item>
467+
<item name="prefer" xsi:type="string">toggle</item>
467468
</item>
468469
</argument>
469470
</field>
@@ -509,20 +510,21 @@
509510
<field name="custom_apply_to_products">
510511
<argument name="data" xsi:type="array">
511512
<item name="config" xsi:type="array">
512-
<item name="additionalClasses" xsi:type="string">admin__field-no-label</item>
513+
<item name="additionalClasses" xsi:type="string">admin__field-x-small</item>
513514
<item name="sortOrder" xsi:type="number">210</item>
514-
<item name="label" xsi:type="string"/>
515-
<item name="description" xsi:type="string" translate="true">Apply Design to Products</item>
515+
<item name="label" xsi:type="string" translate="true">Apply Design to Products</item>
516516
<item name="dataType" xsi:type="string">boolean</item>
517517
<item name="formElement" xsi:type="string">checkbox</item>
518-
<item name="imports" xsi:type="array">
519-
<item name="disabled" xsi:type="string">ns = ${ $.ns }, index = custom_use_parent_settings :checked</item>
520-
</item>
521518
<item name="valueMap" xsi:type="array">
522519
<item name="true" xsi:type="string">1</item>
523520
<item name="false" xsi:type="string">0</item>
524521
</item>
525522
<item name="default" xsi:type="string">0</item>
523+
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox</item>
524+
<item name="prefer" xsi:type="string">toggle</item>
525+
<item name="imports" xsi:type="array">
526+
<item name="disabled" xsi:type="string">ns = ${ $.ns }, index = custom_use_parent_settings:checked</item>
527+
</item>
526528
</item>
527529
</argument>
528530
</field>

lib/internal/Magento/Framework/Stdlib/ArrayManager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ public function get($path, array $data, $defaultValue = null, $delimiter = self:
5757
/**
5858
* Set value into node and return modified data
5959
*
60-
* @param array|string $path
60+
* @param string $path
6161
* @param array $data
6262
* @param mixed $value
6363
* @param string $delimiter
6464
* @return array
6565
*/
6666
public function set($path, array $data, $value, $delimiter = self::DEFAULT_PATH_DELIMITER)
6767
{
68-
if (is_array($path)) {
69-
$path = implode($delimiter, $path);
70-
}
71-
7268
if ($this->find($path, $data, $delimiter, true)) {
7369
$this->parentNode[$this->nodeIndex] = $value;
7470
}
@@ -177,14 +173,18 @@ public function remove($path, array $data, $delimiter = self::DEFAULT_PATH_DELIM
177173
/**
178174
* Finds node in nested array and saves its index and parent node reference
179175
*
180-
* @param string $path
176+
* @param array|string $path
181177
* @param array $data
182178
* @param string $delimiter
183179
* @param bool $populate
184180
* @return bool
185181
*/
186182
protected function find($path, array &$data, $delimiter, $populate = false)
187183
{
184+
if (is_array($path)) {
185+
$path = implode($delimiter, $path);
186+
}
187+
188188
if ($path === null) {
189189
return false;
190190
}

0 commit comments

Comments
 (0)