Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Grouped products have position: 0 for all linked products #242

Closed
didkan opened this issue Mar 19, 2020 · 3 comments
Closed

Grouped products have position: 0 for all linked products #242

didkan opened this issue Mar 19, 2020 · 3 comments

Comments

@didkan
Copy link

didkan commented Mar 19, 2020

Problem
position attribute for Grouped Products is always 0 for all linked products. I.e. the order/position of the products that make up the grouped product are not mirrored in Elasticsearch.

Root cause
In magento2-vsbridge-indexer/src/module-vsbridge-indexer-catalog/Model/ResourceModel/Product/Links.php the function fetchPositionAttributeData() returns a single row from db (first row in result set). The problem is that the where clause used here actually returns multiple rows, ie the position attribute for all link types.
image

We would need to add the link_type_id to the where clause to get the correct product_link_attribute_id to use in the join.

Solution
Add link_type = [current link type] to the where clause here
https://github.com/DivanteLtd/magento2-vsbridge-indexer/blob/3565158727d421013419cc45904a0e00f756a124/src/module-vsbridge-indexer-catalog/Model/ResourceModel/Product/Links.php#L222

I'm not sure exactly how to handle this one myself or if maybe there is a better/simpler solution than the one I proposed. the problem I see is that we actually don't have the link_type yet since we are still building the query when fetchPositionAttributeData() is called if I interpret the code correctly.

@afirlejczyk
Copy link
Contributor

afirlejczyk commented Mar 27, 2020

We could load linked product by type.. and load correct position attribute in fetchPositionAttributeData, but I decided to change logic a little:

#245

@didkan
Copy link
Author

didkan commented Mar 27, 2020

@afirlejczyk Nice! I'll test it for my use cases early next week and report back in the PR.

@afirlejczyk
Copy link
Contributor

Should be OKAY now, previously select return null values, now we got positions in ES:

    "product_links": [
      {
        "sku": "24-WG085_Group",
        "link_type": "associated",
        "linked_product_sku": "24-WG085",
        "linked_product_type": "simple",
        "position": 0
      },
      {
        "sku": "24-WG085_Group",
        "link_type": "associated",
        "linked_product_sku": "24-WG086",
        "linked_product_type": "simple",
        "position": 1
      },
      {
        "sku": "24-WG085_Group",
        "link_type": "associated",
        "linked_product_sku": "24-WG087",
        "linked_product_type": "simple",
        "position": 2
      }
    ],

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants