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

Breaking BC changes in the product list block #32268

Closed
1 of 5 tasks
tzyganu opened this issue Feb 24, 2021 · 7 comments · Fixed by #32390
Closed
1 of 5 tasks

Breaking BC changes in the product list block #32268

tzyganu opened this issue Feb 24, 2021 · 7 comments · Fixed by #32390
Assignees
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@tzyganu
Copy link
Contributor

tzyganu commented Feb 24, 2021

Summary (*)

The \Magento\Catalog\Block\Product\ListProduct::getLoadedProductCollection is breaking BC (feel free to challenge it) in the 2.4 version.
In 2.4 the method looks like this:

    public function getLoadedProductCollection()
    {
        $collection = $this->_getProductCollection();

        $categoryId = $this->getLayer()->getCurrentCategory()->getId();
        foreach ($collection as $product) {
            $product->setData('category_id', $categoryId);
        }

        return $collection;
    }

In 2.3 and before it looked like this:

    public function getLoadedProductCollection()
    {
        return $this->_getProductCollection();
    }

The collection iteration inside the method in 2.4 causes the collection to load the db data so any after plugin or around plugin that calls the original method and tries to affect the collection does nothing to it in 2.4.

Examples (*)

Let's consider this plugin.

public function afterGetLoadedProductCollection(
    \Magento\Catalog\Block\Product\ListProduct $subject, 
    \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
) {
    return $collection->addAttributeToFilter('some_attribute_code', 'some_value');
}

In 2.3 and before, this would cause the product list to filter only products that have the value some_value for the attribute with code some_attribute_code (beside the default filters).
In 2.4 this filter has no effect because the collection is already loaded when adding the filter.

Proposed solution

Move the assign operation of category ids to products to the _beforeToHtml method in the same class after

        if (!$collection->isLoaded()) {
            $collection->load();
        }

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 with no 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”.
@tzyganu tzyganu added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Feb 24, 2021
@m2-assistant
Copy link

m2-assistant bot commented Feb 24, 2021

Hi @tzyganu. 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

@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Feb 24, 2021
@m2-community-project m2-community-project bot added Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. labels Mar 6, 2021
@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Apr 6, 2021
@gabrieldagama gabrieldagama removed the Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. label May 4, 2021
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog May 4, 2021
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board May 4, 2021
@gabrieldagama gabrieldagama added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels May 4, 2021
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @gabrieldagama
Thank you for verifying the issue. Based on the provided information internal tickets MC-42162 were created

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

@gabrieldagama
Copy link
Contributor

Hi @tzyganu. Thank you for your report.
The issue has been fixed in #32390 by @mrtuvn in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.3 release.

@gabrieldagama gabrieldagama added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Jun 25, 2021
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in High Priority Backlog Jun 25, 2021
@m2-community-project m2-community-project bot moved this from Done to Pull Request In Progress in High Priority Backlog Jun 25, 2021
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Ready for Development in High Priority Backlog Aug 24, 2021
@m2-community-project m2-community-project bot moved this from Ready for Development to Done in High Priority Backlog Aug 24, 2021
@mihaimatei
Copy link

Hi @tzyganu. Thank you for your report. The issue has been fixed in #32390 by @mrtuvn in 2.4-develop branch Related commit(s):

The fix will be available with the upcoming 2.4.3 release.

Fix was merged into 2.4-develop, but still not in any of the current 2.4.3 releases.

@rickbakker
Copy link

rickbakker commented Feb 2, 2022

So i was researching a problem with a template i'm using on one of my clients websites, and after some time i figured out it was this exact problem. The issue was that after upgrading to Magento 2.4.0 the pager seemed to do nothing anymore. It just did not work. It just loaded all products that are added to the category. You could see the pagination, you could click on the pages, but the products shown was always the same: All of them.

So i found out that this template has a affiliate marketing template in it, which loads the current loaded product collection via the function described. Once I removed that part, the pagination and everything started to function as normal again. Then i went on Google and started looking into this and found out this post on Git. Thanks a lot!

Question remains, is this patched in any recent version yet or is it still only available in the 2.4-develop branch? Is there a different way to patch this in? I know i can override core files but i don't really see that as a solution. Could bring up problems in the future.

@hostep
Copy link
Contributor

hostep commented Feb 9, 2022

I can see that the code from #32390 is included in Magento 2.4.4-beta4, so expect this to become available in 2.4.4 once it gets released in about a month.

@rickbakker: take a look at either https://github.com/cweagans/composer-patches or https://github.com/vaimo/composer-patches/ and this documentation around custom patches, those might help you further 🙂

@Keivanph
Copy link

Keivanph commented Nov 13, 2022

So i was researching a problem with a template i'm using on one of my clients websites, and after some time i figured out it was this exact problem. The issue was that after upgrading to Magento 2.4.0 the pager seemed to do nothing anymore. It just did not work. It just loaded all products that are added to the category. You could see the pagination, you could click on the pages, but the products shown was always the same: All of them.

So i found out that this template has a affiliate marketing template in it, which loads the current loaded product collection via the function described. Once I removed that part, the pagination and everything started to function as normal again. Then i went on Google and started looking into this and found out this post on Git. Thanks a lot!

Question remains, is this patched in any recent version yet or is it still only available in the 2.4-develop branch? Is there a different way to patch this in? I know i can override core files but i don't really see that as a solution. Could bring up problems in the future.

Hi @rickbakker , out of curiosity what was that "affiliate marketing template" ? I am facing very same problem with loading all of the products when ever I touch the collection in any level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

Successfully merging a pull request may close this issue.

9 participants