2

I'm developing a headless solution using Magento as a product catalogue and i'm facing a small challenge (i'm pretty sure that is not challenging at all, for people that have experience with Magento framework, that is not my case). I'm using the 2.3.3 version of Magento btw.

I have to add a custom filter to the existent GraphQL products query (store_id, that represents the website id in Magento) and i'm a bit lost on how to implement that.

Basically i will have multiple stores created (e.g Portugal, United Kingdom) in Magento and i want to retrieve for example only the products that belongs to the Portugal Store (that is given by this new store_id filter). Can anyone help me?

I have seen this solution somewhere: http://www.mujahidh.com/how-to-filter-product-collection-with-default-graphql-products-query/

But it doesn't work at all for me, the products query is returning an Internal error and after some debugging i have found this error: Warning: Invalid argument supplied for foreach() in magento2\lib\internal\Magento\Framework\GraphQl\Query\Resolver\Argument\AstConverter.php

Any ideas on how to overcome that? What am i missing?

Thanks in advance.

2
  • any update on this? – Devidas Feb 4 at 11:39
  • @Devidas please see my answer below. – hdias Feb 5 at 12:46
0

Found the answer for that!

Regarding the specific question that I made here (related with filtering the products for a specific store using GraphQl products query) you that capability in Magento out of the box.

All you need to do is add a 'store' HTTP header to your request having the specific store code in the value:

POST /graphql HTTP/1.1
Host: magento2.docker
store: de
Content-Type: application/json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.