# Show only products in stock

**URL:** <https://forum.litium.com/t/show-only-products-in-stock/1278>\
**Category:** Questions\
**Created:** [January 14, 2020, 2:06pm UTC](https://forum.litium.com/t/show-only-products-in-stock/1278 "2020-01-14T14:06:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuel.helmner](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@samuel.helmner](https://forum.litium.com/u/samuel.helmner)\
**Post date:** [January 14, 2020, 2:06pm UTC](https://forum.litium.com/t/show-only-products-in-stock/1278/1 "2020-01-14T14:06:57Z")

</div>

Is there an easy way to hide products that’s not in stock and just display in stock products in product lists and search?

Litium version: 7.2

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [January 14, 2020, 2:55pm UTC](https://forum.litium.com/t/show-only-products-in-stock/1278/2 "2020-01-14T14:55:22Z")

</div>

Yes, you could modify the search by adding filters that any connected inventory needs to have at least 1 in stock. Try the below, I took it from something similar so it’s not properly tested, but should be a starting point if not.

Add this method to `SearchQueryBuilder`:

```auto
public void ApplyInStockFilterTags()
{
	var country = _requestModelAccessor.RequestModel.CountryModel.Country;

	var inventorySystemIds = _inventoryService.GetAll()
		.Where(inventory => inventory.CountryLinks
			.Any(x => x.CountrySystemId == country.SystemId))
		.Select(x => x.SystemId)
		.ToList();

	var inventoryQuantityClause = new OptionalTagClause();

	foreach (var inventory in inventorySystemIds)
	{
		inventoryQuantityClause.Tags.Add(new RangeTag(TagNames.GetTagNameForWarehouseQuantity(inventory), 1, 999999));
	}
	
	_request.FilterTags.Add(inventoryQuantityClause);
}

```

And then in `ProductSearchService`, for the `Search` method add:

```auto
searchQueryBuilder.ApplyInStockFilterTags();

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [February 11, 2020, 2:55pm UTC](https://forum.litium.com/t/show-only-products-in-stock/1278/3 "2020-02-11T14:55:24Z")

</div>

Closed on February 11, 2020, 2:55pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
