Skip to content

Product layout based on attribute_set (PR #36244) #39718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3a7cbf3
Update View.php
in-session Mar 7, 2025
6c4d9c4
Update system.xml
in-session Mar 7, 2025
ec86aac
Update config.xml
in-session Mar 7, 2025
e1d6c84
Merge branch '2.4-develop' into patch-12
in-session Mar 7, 2025
345f761
Update system.xml
in-session Mar 7, 2025
d6cb605
Update config.xml
in-session Mar 7, 2025
e31e9f9
Update View.php
in-session Mar 7, 2025
3b704a2
Update View.php
in-session Mar 9, 2025
d984a9f
Merge branch '2.4-develop' into patch-12
in-session Mar 9, 2025
fa7bca7
Update View.php
in-session Mar 10, 2025
ee56fdf
Update system.xml
in-session Mar 10, 2025
2948f2f
Update config.xml
in-session Mar 10, 2025
400050a
Update View.php
in-session Mar 10, 2025
e9ca03a
Update View.php
in-session Mar 10, 2025
21416cb
Update system.xml
in-session Mar 10, 2025
af52faf
Update config.xml
in-session Mar 10, 2025
bf88c74
Update config.xml
in-session Mar 10, 2025
a70f9d9
Update system.xml
in-session Mar 10, 2025
61eb4e2
Update View.php
in-session Mar 10, 2025
7e03737
Update View.php
in-session Mar 10, 2025
be97e8c
Merge branch '2.4-develop' into patch-12
in-session Apr 17, 2025
1c534d6
Merge branch '2.4-develop' into patch-12
engcom-Hotel Apr 22, 2025
12d2d3b
Merge branch '2.4-develop' into patch-12
engcom-Charlie May 20, 2025
70d7148
Merge branch '2.4-develop' into patch-12
engcom-Charlie May 23, 2025
4f32192
Merge branch '2.4-develop' into patch-12
in-session Jun 12, 2025
c877dd8
Merge branch '2.4-develop' into patch-12
in-session Jun 23, 2025
7adf86b
Merge branch '2.4-develop' into patch-12
in-session Jun 24, 2025
e566dd4
Create ViewLayoutHandleTest.php
in-session Jun 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions app/code/Magento/Catalog/Helper/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Catalog\Model\Product\Attribute\LayoutUpdateManager;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Result\Page as ResultPage;
use Magento\Store\Model\ScopeInterface;

/**
* Catalog category helper
Expand Down Expand Up @@ -173,25 +174,57 @@ public function initProductLayout(ResultPage $resultPage, $product, $params = nu
}

$urlSafeSku = rawurlencode($product->getSku());

$enableIdHandle = $this->scopeConfig->isSetFlag(
'catalog/layout_settings/enable_id_handle',
ScopeInterface::SCOPE_STORE
);
$enableAttributeSetHandle = $this->scopeConfig->isSetFlag(
'catalog/layout_settings/enable_attribute_set_handle',
ScopeInterface::SCOPE_STORE
);

// Load default page handles and page configurations
if ($params && $params->getBeforeHandles()) {
foreach ($params->getBeforeHandles() as $handle) {
$resultPage->addPageLayoutHandles(['type' => $product->getTypeId()], $handle, false);
$resultPage->addPageLayoutHandles(['attribute_set' => $product->getAttributeSetId()], $handle, false);
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku], $handle);
if ($enableAttributeSetHandle) {
$resultPage->addPageLayoutHandles(
['attribute_set' => $product->getAttributeSetId()],
$handle,
false
);
}
if ($enableIdHandle) {
$resultPage->addPageLayoutHandles(
['id' => $product->getId(), 'sku' => $urlSafeSku],
$handle
);
}
}
}

$resultPage->addPageLayoutHandles(['type' => $product->getTypeId()], null, false);
$resultPage->addPageLayoutHandles(['attribute_set' => $product->getAttributeSetId()], null, false);
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku]);
if ($enableAttributeSetHandle) {
$resultPage->addPageLayoutHandles(['attribute_set' => $product->getAttributeSetId()], null, false);
}
if ($enableIdHandle) {
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku]);
}

if ($params && $params->getAfterHandles()) {
foreach ($params->getAfterHandles() as $handle) {
$resultPage->addPageLayoutHandles(['type' => $product->getTypeId()], $handle, false);
$resultPage->addPageLayoutHandles(['attribute_set' => $product->getAttributeSetId()], $handle, false);
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku], $handle);
if ($enableAttributeSetHandle) {
$resultPage->addPageLayoutHandles(
['attribute_set' => $product->getAttributeSetId()],
$handle,
false
);
}
if ($enableIdHandle) {
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku], $handle);
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions app/code/Magento/Catalog/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@
<comment>Jpeg quality for resized images 1-100%.</comment>
</field>
</group>
</section>
<section id="dev" translate="label" type="text" sortOrder="500" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Developer</label>
<tab>advanced</tab>
<resource>Magento_Developer::config</resource>
<group id="layout_settings" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Product Layout Handles</label>
<field id="enable_id_handle" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable Layout Handle by Product ID</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_attribute_set_handle" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable Layout Handle by Attribute Set</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
8 changes: 7 additions & 1 deletion app/code/Magento/Catalog/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<datetime>datetime</datetime>
</input_types>
</validator_data>
</general>
</general>
<dev>
<layout_settings>
<enable_id_handle>1</enable_id_handle>
<enable_attribute_set_handle>0</enable_attribute_set_handle>
</layout_settings>
</dev>
</default>
</config>