Skip to content

Commit 5d28a94

Browse files
committed
Merge remote-tracking branch 'origin/MC-34314' into 2.4-develop-pr30
2 parents 666fc1d + 0ef6185 commit 5d28a94

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-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: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Eav\Api\AttributeSetRepositoryInterface;
1111
use Magento\Eav\Model\AttributeSetRepository;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\TestFramework\Eav\Model\GetAttributeGroupByName;
1314
use Magento\TestFramework\Eav\Model\ResourceModel\GetEntityIdByAttributeId;
1415

@@ -34,6 +35,9 @@ class EavTest extends AbstractEavTest
3435
*/
3536
private $setRepository;
3637

38+
/** @var ScopeConfigInterface */
39+
private $config;
40+
3741
/**
3842
* @inheritdoc
3943
*/
@@ -43,6 +47,7 @@ protected function setUp(): void
4347
$this->attributeGroupByName = $this->objectManager->get(GetAttributeGroupByName::class);
4448
$this->getEntityIdByAttributeId = $this->objectManager->get(GetEntityIdByAttributeId::class);
4549
$this->setRepository = $this->objectManager->get(AttributeSetRepositoryInterface::class);
50+
$this->config = $this->objectManager->get(ScopeConfigInterface::class);
4651
}
4752

4853
/**
@@ -217,4 +222,92 @@ private function prepareAttributeSet(array $additional): void
217222
$set->organizeData(array_merge($data, $additional));
218223
$this->setRepository->save($set);
219224
}
225+
226+
/**
227+
* @magentoDataFixture Magento/Catalog/_files/attribute_page_layout_default.php
228+
* @dataProvider testModifyMetaNewProductPageLayoutDefaultProvider
229+
* @return void
230+
*/
231+
public function testModifyMetaNewProductPageLayoutDefault($attributesMeta): void
232+
{
233+
$defaultLayout = $this->config->getValue('web/default_layouts/default_product_layout');
234+
if ($defaultLayout) {
235+
$attributesMeta = array_merge($attributesMeta, ['default' => $defaultLayout]);
236+
}
237+
$expectedMeta = $this->addMetaNesting(
238+
$attributesMeta,
239+
'design',
240+
'page_layout'
241+
);
242+
$this->callModifyMetaAndAssert($this->getNewProduct(), $expectedMeta);
243+
}
244+
245+
/**
246+
* @return array
247+
*/
248+
public function testModifyMetaNewProductPageLayoutDefaultProvider(): array
249+
{
250+
return [
251+
'attributes_meta' => [
252+
[
253+
'dataType' => 'select',
254+
'formElement' => 'select',
255+
'visible' => '1',
256+
'required' => false,
257+
'label' => 'Layout',
258+
'code' => 'page_layout',
259+
'source' => 'design',
260+
'scopeLabel' => '[STORE VIEW]',
261+
'globalScope' => false,
262+
'sortOrder' => '__placeholder__',
263+
'options' =>
264+
[
265+
0 =>
266+
[
267+
'value' => '',
268+
'label' => 'No layout updates',
269+
'__disableTmpl' => true,
270+
],
271+
1 =>
272+
[
273+
'label' => 'Empty',
274+
'value' => 'empty',
275+
'__disableTmpl' => true,
276+
],
277+
2 =>
278+
[
279+
'label' => '1 column',
280+
'value' => '1column',
281+
'__disableTmpl' => true,
282+
],
283+
3 =>
284+
[
285+
'label' => '2 columns with left bar',
286+
'value' => '2columns-left',
287+
'__disableTmpl' => true,
288+
],
289+
4 =>
290+
[
291+
'label' => '2 columns with right bar',
292+
'value' => '2columns-right',
293+
'__disableTmpl' => true,
294+
],
295+
5 =>
296+
[
297+
'label' => '3 columns',
298+
'value' => '3columns',
299+
'__disableTmpl' => true,
300+
],
301+
],
302+
'componentType' => 'field',
303+
'disabled' => true,
304+
'validation' =>
305+
[
306+
'required' => false,
307+
],
308+
'serviceDisabled' => true,
309+
]
310+
]
311+
];
312+
}
220313
}
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)