magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

\Magento\Framework\View\Model\Layout\Merge stores the theme at construct time #30656

Open ericmorand opened 4 years ago

ericmorand commented 4 years ago

Preconditions (*)

Magento 2.3.5

Steps to reproduce (*)

  1. Set a specific theme for a Product
  2. Add a widget expected to be displayed on all the product pages using the specific theme above
  3. Load the page of the Product that you set a specific theme at step 1

Expected result (*)

The specific theme is used and the widget is displayed.

Actual result (*)

The specific theme is used but the widget is not displayed.

Explanation

\Magento\Framework\View\Model\Layout\Merge stores the theme at construct time.

This creates a major issue with the rendering process, when one of the actor wants to change the theme - like for example the Magento_Catalog module. Since the theme is stored at construct time, would it be changed later, the Merge instance would always use the former theme stored at construct time to fetch layout updates.

The most spectacuar issues it creates is when trying to assign widgets for catalog layout handles (like catalog_product_view). Since the Merge instance always uses the default theme to fetch the layout updates, it never gets the chance to fetch the ones that are assigned to the widget if the theme of the product is not set to the default theme of the website. The only way for the widget to get grabbed is for it to be assigned to the default theme of the website, whatever the custom theme applied to the products.

Fortunately it should be easy to write a plugin that intercepts getTheme from the Merge instance to return the current theme instead of the one set at construct time.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 4 years ago

Hi @ericmorand. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

ericmorand commented 4 years ago

I confirm that a plugin solves the issue:

<?php

namespace {Vendor}\{Module}\Plugin\Framework\View\Model\Layout;

use Magento\Framework\View\DesignInterface;

class Merge
{
    /** @var DesignInterface */
    protected $_design;

    public function __construct(DesignInterface $design)
    {
        $this->_design = $design;
    }

    public function afterGetTheme(\Magento\Framework\View\Model\Layout\Merge $subject) {
        return $this->_design->getDesignTheme();
    }
}
mrtuvn commented 4 years ago

Hi This class seem only have responsible to merge all xml files across code base (themes, magento core modules, 3rd-party modules) follow order in app/etc/config.php base xml will always load first then follow by specific area (frontend, adminhtml) then follow modules . Current theme active will have load priority at last, parent will load first

ericmorand commented 4 years ago

It is also responsible to load handle updates stored in database - for example widgets set in the back office, through this function:

    public function getDbUpdateString($handle)
    {
        return null;
    }

This function is intercepted by a plugin (Magento\Widget\Model\ResourceModel\Layout\Plugin) to actually retrieve the widget updates from the database.

The issue here is that at that point, the theme has already been loaded by the Merge singleton , and thus when the updates are fetched from the database, they are fetched using the id of the theme that was loaded at construct time - i.e. the default theme of the website. Even if the theme is changed later, the DB updates for that theme won't be grabbed.

You end up with the following situation:

It is expected since when Merge singleton is created, it is created with the default theme of your website. The Catalog controller later set the custom theme of the Product 123456 but the theme used by Merge singleton to fetch the database updates will always be the default theme.

It's what my plugin above fixes. But it should be fixed in the core code base.

mrtuvn commented 3 years ago

Widget dynamic type such as (list, link..) only visible after clean cache. If after setup widget we don't clear cache widget will never show. Widget type block will show without need clean cache Test in Open source 2.4.0 similar your case. But no use any customises (clean setup) No varnish setup only default magento cache

Screen Shot 2021-01-11 at 11 31 52

Interesting use case! So in your specific case widget will not show ? have try clear cache ? @ericmorand

m2-assistant[bot] commented 3 years ago

Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

mrtuvn commented 3 years ago

Maybe we should target on widget plugin ? Obviously that widget should get current theme instead singleton instance CC: @ihor-sviziev maybe he know this

engcom-Delta commented 3 years ago

Hi @ericmorand thank you for your report. If set Schedule Design Update->New Theme=Magento Luma for product and Design Package/Theme=Magento Luma for widget withType=Catalog Product List, widget is correctly displayed on product page image

Could you clarify how you set specific theme for the Product ?

mrtuvn commented 3 years ago

@engcom-Delta Have you check the test case specific product set for schedule update theme luma and widget set for all product display at blank theme for example.? Expected result widget should not visible when we visit product

mrtuvn commented 3 years ago

This issue may can reproducible in latest codebase

magento-engcom-team commented 3 years ago

@mrtuvn Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

Once all required information is added, please add label "Issue: Confirmed" again. Thanks!

magento-engcom-team commented 3 years ago

@mrtuvn Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

Once all required information is added, please add label "Issue: Confirmed" again. Thanks!

magento-engcom-team commented 3 years ago

@m2-community-project[bot] Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

Once all required information is added, please add label "Issue: Confirmed" again. Thanks!

magento-engcom-team commented 3 years ago

:white_check_mark: Confirmed by @mrtuvn Thank you for verifying the issue. Based on the provided information internal tickets MC-42043 were created

Issue Available: @mrtuvn, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

mrtuvn commented 3 years ago

Reproducible case with luma theme setup with default sampledata

Pre-config Setup theme config default for store => luma theme

Product named "Joust Duffle Bag" 1.Go to admin -> Change Schedule Design Update : New theme: Choose blank theme 2.Create widget show products list type for blank theme and display only in product detail for "Joust Duffle Bag" 2.1 Type: Catalog Products List 2.2 Design Package/Theme: Blank theme 2.3 Assign to Store Views: All Store Views 2.4 Layout Updates: All product types Specific Products: choose "Joust Duffle Bag" Contianer: Main Container Bottom Widget options: Choose default to make sure all critieria meet and valid widget to show

  1. Save widget
  2. Clear cache
  3. Go to homepage first (Verify theme luma applied) OK it's work fine
  4. Go to frontend visit page product "Joust Duffle Bag". Theme blank applied ok and expect widget created previously should visible 7.After page loaded see results. Theme blank show but widget not visible

Actual Widget not show (because magento still get theme luma default from initialized, Actually in the update layout theme applied use should be blank) Theme blank applied (Correct display)

Expected Widget should show and Theme blank applied (Correct display)

cc: @engcom-Delta @engcom-Oscar

mrtuvn commented 3 years ago

Seem issue fixed in this commit https://github.com/magento/magento2/commit/76ff97efcc6352019f3775e2e7f62260fb8b0679#diff-d036d544db88cf91738bb3b56dbe89e156d4043e4cb7062af1eda9d20911d672R196 (lastest recently merged 2.4-develop) Can you verify it again ? @ericmorand Not sure this fix satisfied you or not (for your specific case)

m2-assistant[bot] commented 3 years ago

Hi @engcom-Echo. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


mrtuvn commented 3 years ago

Hi @engcom-Echo can you help re-verify this case ?

mrtuvn commented 3 years ago

based on update from 2.4-develop as i mentioned previously above message

mrtuvn commented 3 years ago

30656 (comment)

@ericmorand can you re-verify your use cases one more time ? At latest 2.4-develop branch. Or add new test case that you believe can reproduce problem