-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Custom theme doesn't apply XML layout updates when applied to a product #7710
Comments
I can confirm this bug : the new Theme is correctly set by \Magento\Catalog\Helper\Product\View::initProductLayout ; yet, only templates are changed and layout XML updates are ignored... |
Also, I didn't manage to use my theme in the "Schedule a design update" in product form (outside of any category configuration...) |
I saw the line "Custom themes now inherit parent XML configuration information as expected." in Magento's 2.1.3 release notes, but after upgrading to 2.1.3 and cleaning every cache, it's still not working. |
I may have fixed it in my codebase... I used a before plugin on the execute method of catalog/product/view controller. The idea is to set the code bellow as soon as possible (from \Magento\Catalog\Helper\Product\View::initProductLayout). $settings = $this->_catalogDesign->getDesignSettings($product);
if ($settings->getCustomDesign()) {
$this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
} The bug is due to the layout being loaded before the custom design is set. It happens twice :
|
@shavounet I've tried your solution however it doesn't seem to work? Could you expand on this more please? |
Here is the main code of the plugin I use, on /**
* Custom fix for https://github.com/magento/magento2/issues/7710
* It allows to use a custom them for product page
* @see \Magento\Catalog\Controller\Product\View::execute
* @param View $subject
*/
public function beforeExecute(View $subject)
{
$productId = (int) $subject->getRequest()->getParam('id');
$categoryId = (int) $subject->getRequest()->getParam('category', false);
$product = $this->initProduct($productId, $categoryId);
if($product) {
$settings = $this->_catalogDesign->getDesignSettings($product);
if ($settings->getCustomDesign()) {
$this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
}
}
}
/**
* Get the product with the given ID, and optionally set the category, if given
* @param $productId
* @param $categoryId
* @return \Magento\Catalog\Model\Product|ProductInterface|bool
*/
protected function initProduct($productId, $categoryId)
{
try {
$product = $this->productRepository->getById($productId, false, $this->storeManager->getStore()->getId());
} catch (NoSuchEntityException $e) {
return false;
}
try {
$category = $this->categoryRepository->get($categoryId);
$product->setCategory($category);
} catch (NoSuchEntityException $e) {
// Do nothing
}
return $product;
} |
I have this problem to. I've been stuck on it for 4 days! Thank so much for the solution. Initially I thought I had made a mistake in the theme layout but no matter what I did to the xml file, it would not render. |
So i would like to know that this bug will close in 2.1.7 or not? |
Go to your database. select theme table. Check custom theme record. If the value of the type field is 1 change it to 0. This fixed my issue. |
Internal ticket was created for this issue: MAGETWO-69709 |
hi shavounet, i have been struggling with this. i cannot figure out how to implement your fix to try it out. i have a child theme (myfirsttheme) with Magento/blank as parent. |
@elghana I have a module that you can add to your site that solves this problem using the solution above. |
My solution: Override\Override\etc\di.xml <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Helper\Product\View" type="Override\Override\Model\View"/>
</config> Override\Override\Model\View.php <?php
namespace Override\Override\Model;
use Magento\Framework\View\Result\Page as ResultPage;
class View extends \Magento\Catalog\Helper\Product\View
{
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Catalog\Model\Session $catalogSession,
\Magento\Catalog\Model\Design $catalogDesign,
\Magento\Catalog\Helper\Product $catalogProduct,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
array $messageGroups = []
) {
parent::__construct(
$context,
$catalogSession,
$catalogDesign,
$catalogProduct,
$coreRegistry,
$messageManager,
$categoryUrlPathGenerator
);
}
public function initProductLayout(ResultPage $resultPage, $product, $params = null)
{
$settings = $this->_catalogDesign->getDesignSettings($product);
$pageConfig = $resultPage->getConfig();
if ($settings->getCustomDesign()) {
$this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
}
// Apply custom page layout
if ($settings->getPageLayout()) {
$pageConfig->setPageLayout($settings->getPageLayout());
}
$urlSafeSku = rawurlencode($product->getSku());
// Load default page handles and page configurations
if ($params && $params->getBeforeHandles()) {
foreach ($params->getBeforeHandles() as $handle) {
$resultPage->addPageLayoutHandles(
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()],
$handle
);
}
}
$resultPage->addPageLayoutHandles(
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()]
);
if ($params && $params->getAfterHandles()) {
foreach ($params->getAfterHandles() as $handle) {
$resultPage->addPageLayoutHandles(
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()],
$handle
);
}
}
// Apply custom layout update once layout is loaded
$update = $resultPage->getLayout()->getUpdate();
$layoutUpdates = $settings->getLayoutUpdates();
// NEW CODE
$category_ids = $product->getData('category_ids');
if (is_array($category_ids) && count($category_ids)) {
foreach($category_ids as $category_id) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$model = $objectManager->create('Magento\Catalog\Api\CategoryRepositoryInterface');
$category = $model->get($category_id);
if($category->getData('custom_apply_to_products')) {
$layoutUpdates[] = $category->getData('custom_layout_update');
}
}
}
if ($layoutUpdates) {
if (is_array($layoutUpdates)) {
foreach ($layoutUpdates as $layoutUpdate) {
$update->addUpdate($layoutUpdate);
}
}
}
$currentCategory = $this->_coreRegistry->registry('current_category');
$controllerClass = $this->_request->getFullActionName();
if ($controllerClass != 'catalog-product-view') {
$pageConfig->addBodyClass('catalog-product-view');
}
$pageConfig->addBodyClass('product-' . $product->getUrlKey());
if ($currentCategory instanceof \Magento\Catalog\Model\Category) {
$pageConfig->addBodyClass('categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($currentCategory))
->addBodyClass('category-' . $currentCategory->getUrlKey());
}
return $this;
}
} |
@chickenland, thank you for your report. |
Same as #8333 |
I provided reference fast patch within #8333 |
Hi @chickenland. Thank you for your report.
The fix will be available with the upcoming 2.3.1 release. |
@magento-engcom-team The issue still exists in 2.3.2, updating the type field in the theme table to 0 fixed it in my case, need a more substantial fix. Half of those commits referenced are just comments |
@shavounet thank you for providing the plugin code you used - that was the ONLY one that worked for a Cloud 2.3.3 instance! |
L3 bugfix delivery
I was looking to open this issue, but thought I'd try and find one before I did. I think this issue is linked to #7503, but is manifesting is achieved in a different way
We have a theme that does not inherit, and it's XML updates appear to be ignored.
Preconditions
Steps to reproduce
Set the theme for a specific storeview to Purenet/Theme (our default theme for the store) via Content > Design > Configuration > Edit.
Create and install a theme that has no inheritence. Add layout changes. For this example, I created a theme with a
catalog_product_view.xml
file that removes the main title for the product as Purenet/Client.Expected result
When checking the the product page, you should not see the main product title.
Actual result
On the Product Page, the main product title is displayed.
Setting a similar XML layout file on a category in the same manner appears to work.
Investigation
So far, it looks like
_fetchPackageLayoutUpdates
withinlib/internal/Magento/Framework/View/Model/Layout/Merge.php
doesn't capture the XML that contains the handle updates. I found moving the XML intocatalog_product_prices
made it added as an update, however, it was still not removed.The text was updated successfully, but these errors were encountered: