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

Why do we need parent identities on frontend? #35546

Open
madonzy opened this issue May 27, 2022 · 28 comments
Open

Why do we need parent identities on frontend? #35546

madonzy opened this issue May 27, 2022 · 28 comments
Labels
Area: Framework Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: ready for dev Reported on 2.3.6 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@madonzy
Copy link

madonzy commented May 27, 2022

I've noticed that we have plugin \Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender::afterGetIdentities that is responsible to add parent tags for each child product. For example, that makes the product listing page much slower because we need to load the parent for each product on the page.

Why do we really need that on frontend? I tested and it PURGE cache for all child products when configurable product is saved.

@m2-assistant
Copy link

m2-assistant bot commented May 27, 2022

Hi @madonzy. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

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

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

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

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ 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, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ 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 May 27, 2022
@madonzy madonzy changed the title Why do we need parent identities on product listing page? Why do we need parent identities on frontend? May 27, 2022
@engcom-November engcom-November added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label May 30, 2022
@engcom-Hotel engcom-Hotel self-assigned this Jun 3, 2022
@m2-assistant
Copy link

m2-assistant bot commented Jun 3, 2022

Hi @engcom-Hotel. 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.

@engcom-Hotel
Copy link
Contributor

Hello @madonzy,

Thanks for the reporting and collaboration!

We request you to more elaborate on the issue so that we can reproduce it. Please provide us the below information:

  • Environment information
  • Steps to reproduce
  • Expected and Actual result
  • In case a specific use case, please provide those also
  • Any screencast or screenshot

Thanks

@engcom-Hotel engcom-Hotel added the Issue: needs update Additional information is require, waiting for response label Jun 3, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Jun 3, 2022
@hostep
Copy link
Contributor

hostep commented Jun 5, 2022

Quoting from @sivaschenko's remark in another thread:

child products affect parent product representation while parent products do not affect child products representation on the frontend, so in order to be sure that the cache is valid - the cache of pages with parent products should be invalidated when a child product is changed.

For example, when a child product becomes out of stock or back in stock or is being enabled/disabled, it might influence how the parent product is being displayed on the frontend.

Does that answer your question @madonzy?

@madonzy
Copy link
Author

madonzy commented Jun 5, 2022

@hostep not really. When child products become out of stock or enabled/disabled then child product cache tags are purged, and that means the cache of the category page will be purged. There's nothing to do with parent product in your examples.

@hostep
Copy link
Contributor

hostep commented Jun 5, 2022

I think I start to see your point, trying to fetch the parent products on the frontend makes not so much sense. But the afterGetIdentities method is also being called when a product is saved in the backoffice for example, and then it starts to make sense that for both the child and parent the caches are being purged, correct?

So if there is a performance problem here, it's that these lines should not be executed on the frontend, am I understanding this correctly?

@madonzy
Copy link
Author

madonzy commented Jun 5, 2022

@hostep yeap. I think just disabling the plugin in the frontend scope di.xml will be a clean solution.

@engcom-Hotel
Copy link
Contributor

@hostep thanks for helping us in understanding the issue.

Hello @madonzy,

We have looked into the code written here and tried to reproduce the issue by the following way:

  1. Have some code changes to debug the issue as follows in the file named ProductIdentitiesExtender.php in line no.: 58:
$parentsidsbychild = $this->getParentIdsByChild($subject->getId());
        foreach ($parentsidsbychild as $parentId) {
            $parentProduct = $this->productRepository->getById($parentId);
            $parentProductsIdentities[] = $parentProduct->getIdentities();
        }
  1. Search for the configurable product from Frontend i.e. Chaz Kangeroo Hoodie
  2. Add a breakpoint in line no. 59 to check the value for the $parentsidsbychild variable, made in step 1.
  3. It has been observed that code has not reached in foreach loop because the value of $parentsidsbychild is empty.
  4. Even if we have tried it for the product detail page.
  5. But the method afterGetIdentities is calling every time.

In the next scenario we have tried to check the performance of the page by enabling and disabling the plugin and we have seen the below difference in them. Please have a look at the below screenshot:

With Plugin:

Screenshot 2022-06-06 at 5 07 22 PM

Without Plugin

Screenshot 2022-06-06 at 6 33 56 PM

I just need to confirm if we are on the correct path or if we can reproduce the issue in some other way.

Thanks

@madonzy
Copy link
Author

madonzy commented Jun 6, 2022

@engcom-Hotel first of all it's totally strange that you did not get the parent product id from the child product. The second is that you measure not only the request but everything that is not needed :)

Make sure that getParentIdsByChild is returning you the value and then got to the browser and test only document request time. Go to Network -> Document -> Select main loaded document -> Timing

P.S: Also, make sure you do not use any cache like Varnish or Built-in FPC in front

@engcom-Hotel
Copy link
Contributor

Thanks @madonzy for the quick response. Let me try this and get back to you. :-)

@engcom-Hotel
Copy link
Contributor

Hello @madonzy,

We have tried to reproduce the issue by searching for a configurable product in the frontend like Chaz Kangeroo Hoodie-XS-Black but we are always getting the Parent product id in the frontend, not the child product id. Please have a look at the below screenshot for the reference:

image

Instead, If I can get the Child id i.e. 53 in this case, I think we can get the Parent id. Can you please suggest the product for which we can get the child product in the frontend?

Thanks

@hostep
Copy link
Contributor

hostep commented Jun 7, 2022

If I'm not mistaken, you need to find a simple product on the frontend which is also a child of a configurable product and that simple product needs to be marked as Visible so it shows up on the frontend.

You'd probably be better of when setting up your own product data instead of using the sample data, it's going to be easier to test I think...

@engcom-Hotel
Copy link
Contributor

Hello @hostep,

I have tried this as well. But still, the issue is not reproducible for us. We have followed the below steps:

  1. Create a configurable product with one configuration:
    image

  2. Edit the configured product and mark the visibility as catalog, search:
    image

  3. Cleared the cache

  4. Check in the frontend, but for us, the function afterGetIdentities is only called for the parent product but not for the child product. For us the parent product id is 2049 and the child product id is 2050. Please refer to the screencast for reference:

CompressedScreenRecording2022-06-08at8.40.05.PM.mp4

Let us know in case we have missed anything.

Thanks

@hostep
Copy link
Contributor

hostep commented Jun 9, 2022

Hmm, I'm getting confused, just tried understanding the code again:

  • So the if checks if a product is of type configurable or something else, in case of something else, it just returns the current $identities
  • In case it's of type configurable the code continues and tries to find the parents of this configurable and then appends their identities

So uhm, I'm confused now, since when can configurable products in Magento have parents?

@madonzy: what do you make of this? Do you have a case where a configurable product has parent products somehow (is this possible with grouped or bundled products maybe, I don't think so...)?
Or how were you able to trigger this code?

@madonzy
Copy link
Author

madonzy commented Jun 10, 2022

There's a method that is called on product listing: \Magento\Catalog\Block\Product\ListProduct::getIdentities

There is a loop you can see fetching the identities of all products and merging it. Just make sure this method is called and all product are loaded.

@hostep
Copy link
Contributor

hostep commented Jun 13, 2022

Yes, but that's expected I think, otherwise the caching system in Magento can't invalidate such pages in case one of the products displayed on them gets changed.
Also, those products get loaded anyway to be able to display them, so it shouldn't really cause performance problems.

@madonzy
Copy link
Author

madonzy commented Jun 13, 2022

@hostep You can archive this behavior by setting all the configurable product "Visible" attribute to be "Not Visible Individually" and you set the simple product "Visible" attribute to be "Catalog, Search". Then you'll see an unneeded performance impact.

@hostep
Copy link
Contributor

hostep commented Jun 13, 2022

That's really strange, because the return in these three lines of code will trigger when it's a simple product. So this should not cause performance problems.

The code further in the method will only trigger when a configurable product is being loaded on the frontend and will try to load parents of the configurable product, which makes not much sense to me.

Have you already debugged this piece of a code a bit yourself? Does the code make sense why and how it triggers in your specific case?

@madonzy
Copy link
Author

madonzy commented Jun 13, 2022

@hostep first of all, that is a new version, there's no such if in 2.3.6 for example https://github.com/magento/magento2/blob/2.3.6/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php

Also, I do not really understand the sense of that if statement... If the product is configurable then it will never have a parent product,(method getParentIdsByChild will always return an empty array) so what is the purpose of that plugin?

@hostep
Copy link
Contributor

hostep commented Jun 14, 2022

Ah this is the first time you mention your Magento version (please next time do this in the opening post, it will make issue handling faster 😉 )

Indeed, the code in 2.3.6 is very different, it was changed significantly in #30746 (which got included in Magento 2.4.2 and higher)

As to why the plugin still exists, I have no idea, either it can be thrown away, or a bug was introduced in #30746, it's hard to say.

@engcom-Echo or @viktorpetryk: do you guys remember something about that Pull Request?

@engcom-Hotel
Copy link
Contributor

Hello @madonzy,

It seems the issue has been fixed in the latest development branch i.e. 2.4-develop. Shall we close this issue?

Thanks

@madonzy
Copy link
Author

madonzy commented Jun 17, 2022

@engcom-Hotel shell we remove that plugin at so?

@hostep
Copy link
Contributor

hostep commented Jun 17, 2022

There's a discussion about this going on in Slack:

Screenshot 2022-06-17 at 17 57 42

So it's being looked into I hope 🙂

@engcom-Hotel
Copy link
Contributor

Hello @madonzy,

We are confirming this issue as per the below comments:

#35546 (comment)
#35546 (comment)

We can remove this plugin from here as it is not in use.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Priority: P3 May be fixed according to the position in the backlog. Reported on 2.3.6 Indicates original Magento version for the Issue report. Area: Framework labels Aug 23, 2022
@m2-community-project m2-community-project bot added this to Dev In Progress in Low Priority Backlog Aug 23, 2022
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-6469 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Aug 23, 2022

✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in Low Priority Backlog Aug 23, 2022
@aholovan
Copy link
Contributor

It's likely the same funny code in "add_bundle_parent_identities" plugin

@engcom-Hotel engcom-Hotel removed the Issue: needs update Additional information is require, waiting for response label Jan 30, 2023
@hostep
Copy link
Contributor

hostep commented Feb 15, 2023

#36529 got merged yesterday, it changes some logic in the ProductIdentitiesExtender::afterGetIdentities method. I haven't tried to understand it yet, because it's quite complicated, but maybe it resolves this issue here @madonzy ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: ready for dev Reported on 2.3.6 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Low Priority Backlog
  
Ready for Development
Development

No branches or pull requests

6 participants