How can I extend searchindex (per variant) to contain more data than it has today?
I want to add WareHouseID - InStockQuantity - ErpStatus to easier add a filter for product listning “Only show products in stock”
Litium version: 7.4
How can I extend searchindex (per variant) to contain more data than it has today?
I want to add WareHouseID - InStockQuantity - ErpStatus to easier add a filter for product listning “Only show products in stock”
Litium version: 7.4
(Assuming you are using Lucene.NET)
Quantity for each warehouse and variant is already added into the index. You can add the tag to your query by using TagNames.GetTagNameForWarehouseQuantity(inventorySystemId) to resolve the correct tag name.
So filtering on stock balance when searching could look something like:
var country = _requestModelAccessor.RequestModel.CountryModel;
// get all inventories used for the current country
var inventorySystemIds = _inventoryService.GetAll()
.Where(inventory => inventory.CountryLinks
.Any(x => x.CountrySystemId == country.SystemId))
.Select(x => x.SystemId)
.ToList();
// add an optional clause where the stock balance should be 1-999999 for any of the connected inventories
var inventoryQuantityClause = new OptionalTagClause();
foreach (var inventory in inventorySystemIds)
{
inventoryQuantityClause.Tags.Add(new RangeTag(TagNames.GetTagNameForWarehouseQuantity(inventory), 1, 999999));
}
_request.FilterTags.Add(inventoryQuantityClause);
You can add an IIndexingProviderPreProcessor to add data for ErpStatus into the index. In the Accelerator there’s an example called CampaignIndexingProviderPreProcessor you could have a look at. There’s an older extension method you could use to resolve a fitting name for the tag, TagNames.GetTagNameForWarehouseArticleStatus(inventorySystemId);
Keep in mind that if you’re merging variant data in the index, if any of the merged variant has stock it will be included.