Skip to content

Commit dff5331

Browse files
committed
MC-34314: page_layout attribute default option cannot be changed
1 parent 63a6786 commit dff5331

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory as AttributeCollectionFactory;
4141

4242
/**
43-
* Data provider for eav attributes on product page
43+
* Class Eav data provider for product editing form
4444
*
4545
* @api
4646
*
@@ -791,7 +791,9 @@ private function getAttributeDefaultValue(ProductAttributeInterface $attribute)
791791
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
792792
$this->storeManager->getStore()
793793
);
794-
$attribute->setDefaultValue($defaultValue);
794+
if ($defaultValue !== null) {
795+
$attribute->setDefaultValue($defaultValue);
796+
}
795797
}
796798
return $attribute->getDefaultValue();
797799
}

dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,89 @@ private function prepareAttributeSet(array $additional): void
217217
$set->organizeData(array_merge($data, $additional));
218218
$this->setRepository->save($set);
219219
}
220+
221+
/**
222+
* @magentoDataFixture Magento/Catalog/_files/attribute_page_layout_default.php
223+
* @dataProvider testModifyMetaNewProductPageLayoutDefaultProvider
224+
* @return void
225+
*/
226+
public function testModifyMetaNewProductPageLayoutDefault($attributesMeta): void
227+
{
228+
$attributesMeta = array_merge($attributesMeta, ['default' => '1column']);
229+
$expectedMeta = $this->addMetaNesting(
230+
$attributesMeta,
231+
'design',
232+
'page_layout'
233+
);
234+
$this->callModifyMetaAndAssert($this->getNewProduct(), $expectedMeta);
235+
}
236+
237+
/**
238+
* @return array
239+
*/
240+
public function testModifyMetaNewProductPageLayoutDefaultProvider(): array
241+
{
242+
return [
243+
'attributes_meta' => [
244+
[
245+
'dataType' => 'select',
246+
'formElement' => 'select',
247+
'visible' => '1',
248+
'required' => false,
249+
'label' => 'Layout',
250+
'code' => 'page_layout',
251+
'source' => 'design',
252+
'scopeLabel' => '[STORE VIEW]',
253+
'globalScope' => false,
254+
'sortOrder' => '__placeholder__',
255+
'options' =>
256+
[
257+
0 =>
258+
[
259+
'value' => '',
260+
'label' => 'No layout updates',
261+
'__disableTmpl' => true,
262+
],
263+
1 =>
264+
[
265+
'label' => 'Empty',
266+
'value' => 'empty',
267+
'__disableTmpl' => true,
268+
],
269+
2 =>
270+
[
271+
'label' => '1 column',
272+
'value' => '1column',
273+
'__disableTmpl' => true,
274+
],
275+
3 =>
276+
[
277+
'label' => '2 columns with left bar',
278+
'value' => '2columns-left',
279+
'__disableTmpl' => true,
280+
],
281+
4 =>
282+
[
283+
'label' => '2 columns with right bar',
284+
'value' => '2columns-right',
285+
'__disableTmpl' => true,
286+
],
287+
5 =>
288+
[
289+
'label' => '3 columns',
290+
'value' => '3columns',
291+
'__disableTmpl' => true,
292+
],
293+
],
294+
'componentType' => 'field',
295+
'disabled' => true,
296+
'validation' =>
297+
[
298+
'required' => false,
299+
],
300+
'serviceDisabled' => true,
301+
]
302+
]
303+
];
304+
}
220305
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
9+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
10+
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
11+
use Magento\Catalog\Setup\CategorySetup;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
$installer = $objectManager->create(CategorySetup::class);
16+
$attribute = $objectManager->create(AttributeFactory::class)->create();
17+
$attributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
18+
$entityType = $installer->getEntityTypeId(ProductAttributeInterface::ENTITY_TYPE_CODE);
19+
$attribute->loadByCode($entityType, 'page_layout');
20+
$attribute->setData('default_value', '1column');
21+
$attributeRepository->save($attribute);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
9+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
10+
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
11+
use Magento\Catalog\Setup\CategorySetup;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
$installer = $objectManager->create(CategorySetup::class);
16+
$attribute = $objectManager->create(AttributeFactory::class)->create();
17+
$attributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
18+
$entityType = $installer->getEntityTypeId(ProductAttributeInterface::ENTITY_TYPE_CODE);
19+
$attribute->loadByCode($entityType, 'page_layout');
20+
$attribute->setData('default_value', null);
21+
$attributeRepository->save($attribute);

0 commit comments

Comments
 (0)