magento2: Custom theme doesn't apply XML layout updates when applied to a product

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

Magento 2.1.2, PHP 5.6.24
Environment: Windows XAMPP / Windows WSL
Developer Mode

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.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="page.main.title" remove="true"/>
</body>
</page>
  1. Deploy static content for the ‘Purenet Client’ theme:
  2. bin/magento setup:static:deploy --theme=“Purenet/Client” en_GB
  3. Apply the ‘Purenet Client’ theme to a category via Products > Catalog > Actual Product > Schedule Design Update > Set Dates & New theme to be Purenet/Client. Save Product.

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 within lib/internal/Magento/Framework/View/Model/Layout/Merge.php doesn’t capture the XML that contains the handle updates. I found moving the XML into catalog_product_prices made it added as an update, however, it was still not removed.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 19 (5 by maintainers)

Commits related to this issue

Most upvoted comments

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.

Here is the main code of the plugin I use, on Magento\Catalog\Controller\Product\View :

    /**
     * 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;
    }