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 32 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
32 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
47bfbed
Merge branch '2.4-develop' into patch-12
engcom-Hotel Jun 25, 2025
fae653e
Update ViewLayoutHandleTest.php
in-session Jun 26, 2025
79ea1c3
Merge branch '2.4-develop' into patch-12
engcom-Charlie Jul 8, 2025
2177ddb
Merge branch '2.4-develop' into patch-12
engcom-Charlie Jul 9, 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
56 changes: 48 additions & 8 deletions app/code/Magento/Catalog/Helper/Product/View.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2011 Adobe
* Copyright 2025 Adobe
* All Rights Reserved.
*/

Expand All @@ -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 @@ -174,24 +175,63 @@ 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);
$resultPage->addPageLayoutHandles(
['type' => $product->getTypeId()],
$handle,
false
);

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
22 changes: 20 additions & 2 deletions app/code/Magento/Catalog/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
Expand Down Expand Up @@ -240,6 +240,24 @@
<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>
12 changes: 9 additions & 3 deletions app/code/Magento/Catalog/etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These copyrights are incorrect and were reverted previously. They are gone in 2.4.8-beta and 2.4.8-develop, but still present in 2.4.7-develop (on which this PR is branched).
Maybe @sidolov you can double check whether this propietary copyright notice does not end up in an actual release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be nice if there was a clear statement about which copyright to use. My last status was the changes in the PR.
2.4.8-beta2: https://github.com/magento/magento2/blob/2.4.8-beta2/app/code/Magento/Catalog/etc/di.xml#L2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct format should be:

/**
 * Copyright [first year code created] Adobe
 * All rights reserved.
 */

Source: https://developer.adobe.com/commerce/contributor/guides/code-contributions/backward-compatibility-policy/#adding-a-constructor-parameter

So the year 2025 should be replaced with 2013 over here.

Same remark around the other files changed in this PR, please don't use the year 2025 unless it's a new file.

@wigman: is this what you were after? Or did I misunderstood?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hostep no, that was not wat I was after :) the copyright notice is not supposed to change to "all rights reserved", unless the decision to roll that change back has been reversed, and I need to check with Adobe core team if that can be prevented.

Copy link
Contributor

@hostep hostep Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it changes from * Copyright © Magento, Inc. All rights reserved. to Copyright 2013 Adobe * All Rights Reserved.

All rights reserved has always been there as far as I know (example from 10 years ago). It's just that it was previously 'Magento', then 'Magento, Inc', which may no longer exist, and is now 'Adobe'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are completely right. I misread. It thought it was a partial return of these changes, which were quite severe 😅 24ce222 thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. You may be interested in magento/magento-coding-standard#492 then.

*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
Expand Down 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>