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 25 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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>