Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top