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

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

Open
1 of 5 tasks
ericmorand opened this issue Oct 26, 2020 · 20 comments
Open
1 of 5 tasks
Assignees
Labels
Component: CatalogWidget Component: Framework/View Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: dev in progress Reported on 2.3.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.

Comments

@ericmorand
Copy link

ericmorand commented Oct 26, 2020

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.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Oct 26, 2020

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

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

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

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

@ghost ghost added this to Ready for Confirmation in Issue Confirmation and Triage Board Oct 26, 2020
@ericmorand
Copy link
Author

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
Copy link
Contributor

mrtuvn commented Oct 27, 2020

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
Copy link
Author

ericmorand commented Oct 27, 2020

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:

  • You set a specific theme named "MyProductTheme" for the Product 123456
  • You add a widget expected to be displayed on all the product pages using the theme "MyProductTheme"
  • You load the product 123456 page, the "MyProductTheme" is used but the widget is not displayed

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.

@sdzhepa sdzhepa added the Reported on 2.3.5 Indicates original Magento version for the Issue report. label Nov 11, 2020
@mrtuvn
Copy link
Contributor

mrtuvn commented Jan 11, 2021

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

@engcom-Delta engcom-Delta self-assigned this Jan 28, 2021
@m2-assistant
Copy link

m2-assistant bot commented Jan 28, 2021

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@mrtuvn
Copy link
Contributor

mrtuvn commented Jan 28, 2021

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
Copy link
Contributor

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 ?

@engcom-Delta engcom-Delta added the Issue: needs update Additional information is require, waiting for response label Jan 28, 2021
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Jan 28, 2021
@mrtuvn
Copy link
Contributor

mrtuvn commented Jan 29, 2021

@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

@m2-community-project m2-community-project bot added the Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. label Feb 4, 2021
@engcom-Delta engcom-Delta removed the Issue: needs update Additional information is require, waiting for response label Feb 26, 2021
@m2-community-project m2-community-project bot moved this from Needs Update to Ready for Confirmation in Issue Confirmation and Triage Board Feb 26, 2021
@engcom-Delta engcom-Delta removed their assignment Feb 26, 2021
@mrtuvn
Copy link
Contributor

mrtuvn commented Apr 10, 2021

This issue may can reproducible in latest codebase

@mrtuvn mrtuvn added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: ready for confirmation labels Apr 24, 2021
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Confirmed in Issue Confirmation and Triage Board Apr 24, 2021
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Confirmed in Issue Confirmation and Triage Board Apr 24, 2021
@mrtuvn
Copy link
Contributor

mrtuvn commented Apr 24, 2021

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
3. Save widget
4. Clear cache
5. Go to homepage first (Verify theme luma applied) OK it's work fine
6. 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
Copy link
Contributor

mrtuvn commented May 18, 2021

Seem issue fixed in this commit 76ff97e#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-community-project m2-community-project bot moved this from Pull Request In Progress to Ready for Development in High Priority Backlog May 24, 2021
@mrtuvn mrtuvn added Fixed in 2.4.x The issue has been fixed in 2.4-develop branch and removed Fixed in 2.4.x The issue has been fixed in 2.4-develop branch labels May 27, 2021
@m2-assistant
Copy link

m2-assistant bot commented May 28, 2021

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:

    1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
    1. If the issue is not relevant or is not reproducible any more, feel free to close it.

@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in High Priority Backlog May 28, 2021
@mrtuvn
Copy link
Contributor

mrtuvn commented May 28, 2021

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

@mrtuvn
Copy link
Contributor

mrtuvn commented May 28, 2021

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

@mrtuvn
Copy link
Contributor

mrtuvn commented Sep 20, 2021

#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

@magento magento deleted a comment from tuna2smc Sep 20, 2021
@magento magento deleted a comment from tuna2smc Sep 20, 2021
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Dev In Progress in High Priority Backlog Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CatalogWidget Component: Framework/View Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: dev in progress Reported on 2.3.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
High Priority Backlog
  
Dev In Progress
Development

Successfully merging a pull request may close this issue.

6 participants