Skip to content

Commit 4834ed1

Browse files
author
Roman Lytvynenko
committed
MC-35179: Unable to save "No layout updates" for category
1 parent 1d0d2e8 commit 4834ed1

File tree

2 files changed

+32
-45
lines changed

2 files changed

+32
-45
lines changed

app/code/Magento/Catalog/Model/Plugin/SetPageLayoutDefaultValue.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ class SetPageLayoutDefaultValue
3535
private $scopeConfig;
3636

3737
/**
38-
* @param string $defaultValue
3938
* @param ScopeConfigInterface|null $scopeConfig
4039
* @param StoreManagerInterface|null $storeManager
40+
* @param string $defaultValue
4141
*/
4242
public function __construct(
43-
string $defaultValue = "",
44-
ScopeConfigInterface $scopeConfig = null,
45-
StoreManagerInterface $storeManager = null
43+
ScopeConfigInterface $scopeConfig,
44+
StoreManagerInterface $storeManager,
45+
string $defaultValue = ""
4646
) {
4747
$this->defaultValue = $defaultValue;
48-
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
49-
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
48+
$this->scopeConfig = $scopeConfig;
49+
$this->storeManager = $storeManager;
5050
}
5151

5252
/**
@@ -66,7 +66,7 @@ public function afterGetDefaultMetaData(DataProvider $subject, array $result): a
6666
$defaultAdminValue = $this->scopeConfig->getValue(
6767
'web/default_layouts/default_category_layout',
6868
ScopeInterface::SCOPE_STORE,
69-
$this->storeManager->getStore()
69+
$this->storeManager->getStore()->getId()
7070
);
7171

7272
$defaultValue = $defaultAdminValue ?: $this->defaultValue;

dev/tests/integration/testsuite/Magento/Catalog/Model/Category/DataProviderTest.php

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -240,59 +240,46 @@ public function testCustomLayoutMeta(): void
240240
}
241241

242242
/**
243-
* Check if category default page layout will be properly returned by DataProvider
243+
* Check if existing category page layout will remain unaffected by category page layout default value setting
244244
*
245-
* @dataProvider categoryDefaultMetaDataProvider
246-
* @param $data
247245
* @return void
246+
*/
247+
public function testExistingCategoryLayoutUnaffectedByDefaults(): void
248+
{
249+
/** @var Category $category */
250+
$category = $this->categoryFactory->create();
251+
$category->load(2);
252+
253+
$this->registry->register('category', $category);
254+
$meta = $this->dataProvider->getMeta();
255+
$categoryPageLayout = $meta["design"]["children"]["page_layout"]["arguments"]["data"]["config"]["default"];
256+
$this->registry->unregister('category');
257+
258+
$this->assertNull($categoryPageLayout);
259+
}
260+
261+
/**
262+
* Check if category page layout default value setting will apply to the new category during it's creation
263+
*
248264
* @throws NoSuchEntityException
249265
*/
250-
public function testDefaultLayoutMeta($data): void
266+
public function testNewCategoryLayoutMatchesDefault(): void
251267
{
252-
$defaultAdminValue = $this->scopeConfig->getValue(
268+
$categoryDefaultPageLayout = $this->scopeConfig->getValue(
253269
'web/default_layouts/default_category_layout',
254270
ScopeInterface::SCOPE_STORE,
255-
$this->storeManager->getStore()
271+
$this->storeManager->getStore()->getId()
256272
);
257273

258274
/** @var Category $category */
259275
$category = $this->categoryFactory->create();
260-
261-
if ($data['createNewCategory']) {
262-
$category->setName('Net Test Category');
263-
} else {
264-
$category->load(2);
265-
}
276+
$category->setName('Net Test Category');
266277

267278
$this->registry->register('category', $category);
268279
$meta = $this->dataProvider->getMeta();
269-
$defaultCategoryLayout = $meta["design"]["children"]["page_layout"]["arguments"]["data"]["config"]["default"];
280+
$categoryPageLayout = $meta["design"]["children"]["page_layout"]["arguments"]["data"]["config"]["default"];
270281
$this->registry->unregister('category');
271282

272-
if ($data['defaultValueEqSettings']) {
273-
$this->assertEquals($defaultAdminValue, $defaultCategoryLayout);
274-
} else {
275-
$this->assertEquals($data['expectedDefaultValue'], $defaultCategoryLayout);
276-
}
277-
}
278-
279-
public function categoryDefaultMetaDataProvider(): array
280-
{
281-
return [
282-
[
283-
[
284-
'createNewCategory' => false,
285-
'expectedDefaultValue' => null,
286-
'defaultValueEqSettings' => false
287-
]
288-
],
289-
[
290-
[
291-
'createNewCategory' => true,
292-
'expectedDefaultValue' => false,
293-
'defaultValueEqSettings' => true
294-
]
295-
]
296-
];
283+
$this->assertEquals($categoryDefaultPageLayout, $categoryPageLayout);
297284
}
298285
}

0 commit comments

Comments
 (0)