In Magento 2, it's not possible to add a store_id
filter to a product collection directly. Instead, you need to use the addStoreFilter
method, which adds a special "product limitation filter". It appears that addFieldToFilter
is meant for attributes specific to a particular collection, and the product limitation filters are meant for attributes that might be shared globally across collections (store_id, website_id, category_id, etc).
Given that, is is possible to create a filter for a product repository to get a list of products filtered by store_id
? Attempting to use a filter like this with a repository
/* @var $filterBuilder \Magento\Framework\Api\FilterBuilder */
$this->filterBuilder->setField('store_id')
->setValue('1')
->setConditionType('eq')
->create();
produces the following error
Invalid attribute name: store_id
i.e. the repository attempts to create a filter on the underlying collection with the addFieldToFilter
method.