What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Filter variants by metafield

Filter variants by metafield

hennott
Shopify Partner
22 0 9

I tried to use the admin API to get all variants with a special value in a metafield. Okay this isn´t possible with the admin API. Then I tried to do this via the Storefront API because there is an example in the docu, but the filter has no effect.

 

Documentation

Filter products in a collection with the Storefront API (shopify.dev)

 

There is only one variant with "LC" in the metafield "custom.box", but I got 100 products. The filter is ignored.

 

query box {
  collection(handle: "all") {
    handle
    products(
      filters: {productMetafield: {namespace: "custom", key: "box", value: "LC"}}
      first: 100
    ) {
      edges {
        node {
          id
          title
        }
      }
    }
  }
}

It would be very useful to have this kind of filter also in the admin / API and of course filtering correctly.

Replies 4 (4)

serkanboztepe
Shopify Partner
23 0 1

Hi, Have you installed "Shopify Search & Discovery"? If you installed, Did you adjust the settings?

- Need a Shopify developer? Chat on WhatsApp +90-5453606783
- Coffee Tip: Buymeacoffee  | Email: serkanboztepe02@gmail.com
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Best regards,
Serkan Boztepe
hennott
Shopify Partner
22 0 9

No .. but now .. if there is an "textline" "LC" it works now, but because of only a "textline" is possible, I added "LC:Code,MC:Add" .. now I can not filter for "LC" or "LC:" .. or is there an case sensitive way to query for this?

serkanboztepe
Shopify Partner
23 0 1

I know there is no way to do this as a query. But always convert to uppercase when adding a metafield. Convert the word to uppercase when filtering. This way it might be possible.

 

If it is not possible to enter data this way, you can make a shopify app. In this way, you can enter data into products and convert it to uppercase letters in the background.

 

- Need a Shopify developer? Chat on WhatsApp +90-5453606783
- Coffee Tip: Buymeacoffee  | Email: serkanboztepe02@gmail.com
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Best regards,
Serkan Boztepe
hennott
Shopify Partner
22 0 9

I don´t understand what you mean .. it´s not possible?! The content of the metafield "LC:Code,MC:Add" is written in this way, because I only can filter simple textline fields and I need to store an list with 0 to 10 comma separated key-value-pairs. At the end I need to filter based on the key "LC". 
Normally with the admin API. My approach, if it´s not possible, is to do this mapping in a separate database.