Skip to content

Commit 6e57300

Browse files
committed
Merge remote-tracking branch 'origin/imported-magento-magento2-32217' into 2.4-develop-pr127
2 parents 5854e9b + 14212e3 commit 6e57300

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

app/code/Magento/Catalog/Model/Design.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ protected function _mergeSettings($categorySettings, $productSettings)
201201
$update = array_merge($categorySettings->getLayoutUpdates(), $productSettings->getLayoutUpdates());
202202
$categorySettings->setLayoutUpdates($update);
203203
}
204+
if ($categorySettings->getPageLayoutHandles()) {
205+
$handles = [];
206+
foreach ($categorySettings->getPageLayoutHandles() as $key => $value) {
207+
$handles[$key] = [
208+
'handle' => 'catalog_category_view',
209+
'value' => $value,
210+
];
211+
}
212+
$categorySettings->setPageLayoutHandles($handles);
213+
}
214+
if ($productSettings->getPageLayoutHandles()) {
215+
$handle = array_merge($categorySettings->getPageLayoutHandles(), $productSettings->getPageLayoutHandles());
216+
$categorySettings->setPageLayoutHandles($handle);
217+
}
218+
204219
return $categorySettings;
205220
}
206221
}

dev/tests/integration/testsuite/Magento/Catalog/Model/DesignTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\TranslateInterface;
1414
use Magento\Framework\View\Design\ThemeInterface;
1515
use Magento\Framework\View\DesignInterface;
16+
use Magento\Framework\View\Result\Page;
1617
use Magento\TestFramework\Helper\Bootstrap;
1718
use Magento\Theme\Model\Theme;
1819
use PHPUnit\Framework\TestCase;
@@ -117,6 +118,34 @@ public function getDesignSettingsForProductWithScheduleDesignTest(): array
117118
];
118119
}
119120

121+
/**
122+
* Verify ability to add category inherited page layout handles for product.
123+
*
124+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
125+
* @return void
126+
*/
127+
public function testAddCategoryPageLayoutHandlesForProduct(): void
128+
{
129+
$resultPage = Bootstrap::getObjectManager()->create(Page::class);
130+
$product = $this->productRepository->get('simple');
131+
$category = $this->getMockBuilder(Category::class)
132+
->disableOriginalConstructor()
133+
->onlyMethods(['getParentDesignCategory'])
134+
->getMock();
135+
$category->expects(self::once())->method('getParentDesignCategory')->willReturnSelf();
136+
$category->setId(1);
137+
$category->setCustomLayoutUpdateFile('testFile');
138+
$category->setCustomApplyToProducts(1);
139+
$product->setCategory($category);
140+
$settings = $this->model->getDesignSettings($product);
141+
$resultPage->addPageLayoutHandles($settings->getPageLayoutHandles());
142+
$handles = $resultPage->getLayout()->getUpdate()->getHandles();
143+
self::assertEquals(
144+
'catalog_category_view_selectable_1_testFile',
145+
$handles[1]
146+
);
147+
}
148+
120149
/**
121150
* @return array
122151
*/

lib/internal/Magento/Framework/View/Result/Page.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public function addPageLayoutHandles(array $parameters = [], $defaultHandle = nu
223223
$handle = $defaultHandle ? $defaultHandle : $this->getDefaultLayoutHandle();
224224
$pageHandles = [$handle];
225225
foreach ($parameters as $key => $value) {
226+
$handle = $value['handle'] ?? $handle;
227+
$value = $value['value'] ?? $value;
226228
$pageHandle = $handle . '_' . $key . '_' . $value;
227229
$pageHandles[] = $pageHandle;
228230
if ($entitySpecific) {

0 commit comments

Comments
 (0)