Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

custom attribute not able to see in the product filter section in GraphQl #500

Closed
cnu115 opened this issue Mar 20, 2019 · 17 comments
Closed
Labels
bug Something isn't working Component: CatalogGraphQl

Comments

@cnu115
Copy link

cnu115 commented Mar 20, 2019

Preconditions (*)

1.Created custom attribute in magento not reflecting on the GraphQl

Steps to reproduce (*)

1.Created custom attribute ( mostselling ) in magento and it was satisfying the layered navigation and able to see in the front magento storefront
2. That ( mostselling ) attribute not reflecting in the product filter GraphQl Query

Expected result (*)

1.We can able to see in the magento front-end .
2.We can able to see error message from GraphQl .

  1. 4aa94380-c10c-405b-903e-b6387a39bcfa

2.6318f8b0-9ecf-439c-a671-eb5189adbc77

Actual result (*)

1.d9ce1d99-067d-4561-a78c-7ac0a9f94710

@TomashKhamlai
Copy link
Contributor

Could you please add request body, actual and expected result in text format? It would be awesome if you could replace links to images. Unfortunately, I see
image

@cnu115
Copy link
Author

cnu115 commented Mar 20, 2019

@TomashKhamlai Thanks for the reply. I updated the bug.

@TomashKhamlai
Copy link
Contributor

@cnu115 thank you for reporting this issue. The fix for this issue can be delayed for unknown time period. We acknowledged this issue and added to our product backlog.

@sirugh
Copy link

sirugh commented Jul 12, 2019

@TomashKhamlai what about filtering for things such as Fashion Material or size, etc? Those attributes are part of ConfigurableProduct but I wasn't able to filter for them. See magento/pwa-studio#1432

@zetlen
Copy link

zetlen commented Jul 29, 2019

Would it be easier or faster for us to pass a collection of filters expressed in an EAV structure, rather than a complex filter object?

Instead of

products(
  filter: { 
    category_id: { eq: "11" }
    fashion_material: { eq: "39" } # 39 == cotton, but this fails because fashion_material is not a property of ProductFilterInput
  }
)

Some alternate ProductFilterColllection could look like:

products(
  filters: [ 
    { attr_name: "category_id", filter: { eq: "11" }
    { attr_name: "fashion_material", filter: { eq: "39" }
  ]
)

@shakyShane
Copy link

@zetlen this is the only reasonable solution imo since some stores genuinely have hundreds of attributes on which we want to filter.

We'll be implementing this ourselves, and it simply cannot be known keys as part of the query

@sirugh
Copy link

sirugh commented Sep 5, 2019

Zetlen's proposed filter method would fail better as the schema would be less rigid.

@id-mitchell
Copy link

Same issue here, but I also understand that it is nice to have a more fully defined schema.

I'm honestly curious if anybody can speak to a general GraphQL "best practice" around this? It seems that having a fully defined schema is generally preferable, but for dynamic fields it seems brittle? Again, I'd be curious to know if this is something that's been discussed at length outside of the Magento GraphQL world?

@jayankaghosh
Copy link
Contributor

@sirugh I understand that @zetlen 's solution would make the schema less rigid. But why is that a bad thing? In a dynamic data model, it's advisable to use an array of objects with the id and value specified. Similar to how extension_attributes are used for the Magento REST API structure to handle the same problem. I might be wrong here, just curious.

P.S This link might prove useful

@sirugh
Copy link

sirugh commented Oct 30, 2019

But why is that a bad thing

I should have provided some substance to my statement but "fail better" is a good thing :D What I meant is that having filter keys by dynamic attributes cause schema failures in the query if the attributes are not present in the schema. If instead we query with known static props on a "query object" the back end can fail more gracefully.

That's all I was saying, so not a bad thing :)

@lenaorobei
Copy link
Contributor

@TomashKhamlai please verify this on 2.3-develop branch. It should be fixed by internal team for 2.3.4 release. Thanks.

@TomashKhamlai TomashKhamlai added the QA in progress We are checking label Oct 30, 2019
@jayankaghosh
Copy link
Contributor

@sirugh Oh. My bad. Lol

@TomashKhamlai
Copy link
Contributor

It looks like I have some good news 🎉

Request:

{
  productDetail: products(
    filter: {
      mostselling: {
        eq: "1"
      }
    }
  ) {
    items {
      sku
      name
      price_range {
        maximum_price {
          regular_price {
            currency
            value
          }
        }
        minimum_price {
          regular_price {
            currency
            value
          }
        }
      }
      mostselling
      description {
        html
      }
    }
  }
}

Response:

{
  "data": {
    "productDetail": {
      "items": [
        {
          "sku": "Simple Product 1",
          "name": "Simple Product 1",
          "price_range": {
            "maximum_price": {
              "regular_price": {
                "currency": "USD",
                "value": 10.51
              }
            },
            "minimum_price": {
              "regular_price": {
                "currency": "USD",
                "value": 10.51
              }
            }
          },
          "mostselling": 1,
          "description": {
            "html": ""
          }
        }
      ]
    }
  }
}

@cnu115, could you check if this works for you on 2.3-develop branch?

@TomashKhamlai
Copy link
Contributor

🔔 magento/pwa-studio#1432

@TomashKhamlai TomashKhamlai removed the QA in progress We are checking label Oct 31, 2019
@TomashKhamlai
Copy link
Contributor

🔔 @keharper

@keharper
Copy link
Contributor

Ah, I forgot I applied the requires-documentation label here. Since the internal team fixed the underlying issue, it's been documented. It won't appear on devdocs till 2.3.4 ships, but the info is here

https://github.com/magento/devdocs/blob/develop/guides/v2.3/graphql/custom-filters.md
https://github.com/magento/devdocs/blob/develop/guides/v2.3/graphql/queries/products.md

@lenaorobei
Copy link
Contributor

Fixed in 2.3-develop and 2.4-develop.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working Component: CatalogGraphQl
Projects
None yet
Development

No branches or pull requests

10 participants