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.5k stars 9.31k forks source link

Default store (Root category A) breadcrumbs are being returned for New Store (Root category B) when Product belongs to both root categories. #31253

Closed dpatil-magento closed 2 years ago

dpatil-magento commented 3 years ago

Preconditions (*)

  1. Magento 2.4.1
  2. Two root categories exists in Admin-Categories
  3. Two stores exists with different root categories for each of it
  4. Each Stores should have atleast one store view.
  5. Each Root category should have one sub-category.
  6. Product should belong to both stores. i.e. Assign product to all root and sub categories.

Steps to reproduce (*)

  1. Query -
    {
    "store": "engchildren"
    }
    query {
    products(filter: { url_key: { eq: "gabrielle-micro-sleeve-top"} }){
    items {
      categories {
        name
        id
        url_path
        breadcrumbs {
          category_id
          category_name
          category_level
        }
      }
    } 
    }
    }

Expected result (*)

  1. Store specific data should be returned.

Actual result (*)

  1. Response -
    {
    "data": {
    "products": {
      "items": [
        {
          "categories": [
            {
              "name": "Default Category",
              "id": 2,
              "url_path": null,
              "breadcrumbs": null
            },
            {
              "name": "Women",
              "id": 20,
              "url_path": "women",
              "breadcrumbs": null
            },
            {
              "name": "Tops",
              "id": 21,
              "url_path": "women/tops-women",
              "breadcrumbs": [
                {
                  "category_id": 20,
                  "category_name": "Women",
                  "category_level": 2
                }
              ]
            },
            {
              "name": "Toddlers",
              "id": 51,
              "url_path": "toddlers",
              "breadcrumbs": null
            }
          ]
        }
      ]
    }
    }
    }

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

m2-assistant[bot] commented 3 years ago

Hi @dpatil-magento. 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

m2-assistant[bot] commented 3 years ago

Hi @pronto2000. 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:


pronto2000 commented 3 years ago

I can confirm the issue description and I can add some additional insights here. I created two stores: default (1) and second (2), running the GraphQL query similar to the one above ran the query below:

SELECT `cat_index`.`category_id` FROM `catalog_category_product_index_store1` AS `cat_index`
 INNER JOIN `store` ON store.store_id = 1
 INNER JOIN `store_group` ON store.group_id = store_group.group_id AND cat_index.category_id != store_group.root_category_id WHERE (product_id = 1200)

above is generated in app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductCategories.php

Please note that I created 2 websites, each having it's one store and each store has it's own root category and store_view. For the product (id = 1200) I assigned categories from both websites to it and as a separate option I enabled the first website only.

The query above correctly assumes assumes that default store it 1 and tries to get the information from index_store1 using store_id 1. The result however is wrong because this table contains information from both stores (category 17 is from website 1 and category 34 is from website 2):

+-------------+
| category_id |
+-------------+
|          17 |
|          34 |
+-------------+

Inspecting tabel catalog_category_product_index_store1 reveals that this table contains ALL category / product association and ALL rows have store_id = 1. catalog_category_product_index_store2 exists as well, but it is empty.

here's a sample from catalog_category_product_index_store1

select * from catalog_category_product_index_store1 where product_id = 1200;
+-------------+------------+----------+-----------+----------+------------+
| category_id | product_id | position | is_parent | store_id | visibility |
+-------------+------------+----------+-----------+----------+------------+
|          17 |       1200 |     9999 |         0 |        1 |          4 |
|          34 |       1200 |       -1 |         1 |        1 |          4 |
+-------------+------------+----------+-----------+----------+------------+

while

 select count(*) from catalog_category_product_index_store2;
+----------+
| count(*) |
+----------+
|        0 |
+----------+

It looks like the data stored in those index tables is fundamentally wrong and this is not a problem with GraphQL, but with indexing itself.

Please note that while it's technically possible to filter out correct rows it's going to be a quick and dirty workaround ignoring the core problem which remains there potentially causing additional problem.

sasha19957099 commented 3 years ago

@magento I'm working on this

niklaswolf commented 3 years ago

What's the state of this issue? Seems like there is a PR ready to be merged, but nothing happened since January...

github-jira-sync-bot commented 2 years ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2515 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

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

glo71317 commented 2 years ago

Based on priority I am working on this issue's PR and fixing the PR comments and automation tests

engcom-Alfa commented 2 years ago

Hello @dpatil-magento As I can see this issue got fixed in the scope of the internal Jira ticket AC-2515 by the internal team Related commits: https://github.com/magento/magento2/search?q=AC-2515&type=commits

Based on Jira, target version is 2.4.5