Skip to content
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

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

Open
wants to merge 20 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
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
@@ -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
@@ -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);
}
}
}

20 changes: 18 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 2013 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">
@@ -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>
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 2013 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">
@@ -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>