I’m having a custom route in a custom module where I’d like to list a subset of products for a specific search criteria. I’d like to include here just for this action the out of stock products. BUT I don’t want to show out of stock products on the whole shop generally so this config option is not the way to go.

In my custom view model I got something like the following to query products.

$products = $this->productRepository->getList($searchCriteria);

This does work fine and the returned product list matches my search criteria but it doesn’t include the out of stock ones which also would match the criteria.

Is there a way to include them without using the production collection directly?

It seems pretty odd that the framework here always excludes the out of stock ones due to a plugin on the collections load function.

I thought about adding another collection processor to the ProductRepository but I can't manage to do it.

In the end the only thing to do would be $collection->setFlag('has_stock_status_filter', true); which disables the plugin behavior excluding the out of stock products.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.