Skip to content

Commit b8c7b86

Browse files
committed
Merge branch 'MC-35179' of https://github.com/magento-tango/magento2ce into PR-03-07-2020
2 parents d91befb + cff0d0a commit b8c7b86

File tree

3 files changed

+97
-8
lines changed

3 files changed

+97
-8
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
namespace Magento\Catalog\Model\Plugin;
1212

1313
use Magento\Catalog\Model\Category\DataProvider;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
1415
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\Store\Model\ScopeInterface;
17+
use Magento\Store\Model\StoreManagerInterface;
1518

1619
/**
1720
* Sets the default value for Category Design Layout if provided
@@ -21,11 +24,28 @@ class SetPageLayoutDefaultValue
2124
private $defaultValue;
2225

2326
/**
27+
* @var StoreManagerInterface
28+
*/
29+
private $storeManager;
30+
31+
/**
32+
* @var ScopeConfigInterface
33+
*/
34+
private $scopeConfig;
35+
36+
/**
37+
* @param ScopeConfigInterface $scopeConfig
38+
* @param StoreManagerInterface $storeManager
2439
* @param string $defaultValue
2540
*/
26-
public function __construct(string $defaultValue = "")
27-
{
41+
public function __construct(
42+
ScopeConfigInterface $scopeConfig,
43+
StoreManagerInterface $storeManager,
44+
string $defaultValue = ""
45+
) {
2846
$this->defaultValue = $defaultValue;
47+
$this->scopeConfig = $scopeConfig;
48+
$this->storeManager = $storeManager;
2949
}
3050

3151
/**
@@ -42,7 +62,15 @@ public function afterGetDefaultMetaData(DataProvider $subject, array $result): a
4262
$currentCategory = $subject->getCurrentCategory();
4363

4464
if ($currentCategory && !$currentCategory->getId() && array_key_exists('page_layout', $result)) {
45-
$result['page_layout']['default'] = $this->defaultValue ?: null;
65+
$defaultAdminValue = $this->scopeConfig->getValue(
66+
'web/default_layouts/default_category_layout',
67+
ScopeInterface::SCOPE_STORE,
68+
$this->storeManager->getStore()->getId()
69+
);
70+
71+
$defaultValue = $defaultAdminValue ?: $this->defaultValue;
72+
73+
$result['page_layout']['default'] = $defaultValue ?: null;
4674
}
4775

4876
return $result;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@
471471
</imports>
472472
</settings>
473473
</field>
474-
<field name="page_layout" sortOrder="190" formElement="select" component="Magento_Catalog/js/components/use-parent-settings/select" class="Magento\Catalog\Ui\Component\Form\Field\Category\PageLayout">
474+
<field name="page_layout" sortOrder="190" formElement="select" component="Magento_Catalog/js/components/use-parent-settings/select">
475475
<settings>
476476
<dataType>string</dataType>
477477
<label translate="true">Layout</label>

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

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Model\Category;
78

9+
use Magento\Catalog\Model\Category;
10+
use Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate;
11+
use Magento\Catalog\Model\CategoryFactory;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Framework\Registry;
15+
use Magento\Store\Model\ScopeInterface;
16+
use Magento\Store\Model\StoreManagerInterface;
817
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
918
use Magento\TestFramework\Helper\Bootstrap;
10-
use Magento\Framework\Registry;
1119
use PHPUnit\Framework\TestCase;
12-
use Magento\Catalog\Model\Category;
13-
use Magento\Catalog\Model\CategoryFactory;
14-
use Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate;
1520

1621
/**
1722
* @magentoDbIsolation enabled
@@ -40,6 +45,16 @@ class DataProviderTest extends TestCase
4045
*/
4146
private $fakeFiles;
4247

48+
/**
49+
* @var ScopeConfigInterface
50+
*/
51+
private $scopeConfig;
52+
53+
/**
54+
* @var StoreManagerInterface
55+
*/
56+
private $storeManager;
57+
4358
/**
4459
* Create subject instance.
4560
*
@@ -68,6 +83,8 @@ protected function setUp()
6883
$this->registry = $objectManager->get(Registry::class);
6984
$this->categoryFactory = $objectManager->get(CategoryFactory::class);
7085
$this->fakeFiles = $objectManager->get(CategoryLayoutUpdateManager::class);
86+
$this->scopeConfig = $objectManager->get(ScopeConfigInterface::class);
87+
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
7188
}
7289

7390
/**
@@ -221,4 +238,48 @@ public function testCustomLayoutMeta(): void
221238
sort($list);
222239
$this->assertEquals($expectedList, $list);
223240
}
241+
242+
/**
243+
* Check if existing category page layout will remain unaffected by category page layout default value setting
244+
*
245+
* @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+
*
264+
* @throws NoSuchEntityException
265+
*/
266+
public function testNewCategoryLayoutMatchesDefault(): void
267+
{
268+
$categoryDefaultPageLayout = $this->scopeConfig->getValue(
269+
'web/default_layouts/default_category_layout',
270+
ScopeInterface::SCOPE_STORE,
271+
$this->storeManager->getStore()->getId()
272+
);
273+
274+
/** @var Category $category */
275+
$category = $this->categoryFactory->create();
276+
$category->setName('Net Test Category');
277+
278+
$this->registry->register('category', $category);
279+
$meta = $this->dataProvider->getMeta();
280+
$categoryPageLayout = $meta["design"]["children"]["page_layout"]["arguments"]["data"]["config"]["default"];
281+
$this->registry->unregister('category');
282+
283+
$this->assertEquals($categoryDefaultPageLayout, $categoryPageLayout);
284+
}
224285
}

0 commit comments

Comments
 (0)