Cant fetch OrderCarrier from users session, when checking stockstatus?

Hi from inside the ProductIndexDocumentBuilder i use _stockService.HasStock(variant);

And this fails duing the index rebuild with the error: {“Cant fetch OrderCarrier from users session.”}
What is going on there and how can i fix it? :slight_smile:

Litium version: 7.3

When the StockService are directly using the CartAccessor.Cart.OrderCarrier and that method is only working if the execution is in a web request with session state enabled.

If you should execute this from the search indexing you need to set the website and country on the StockStatusCalculatorArgs from something else.

Thanks, this code worked:

if (discontinued)
				{
					_stockStatusCalculator.GetStockStatuses(new StockStatusCalculatorArgs
					{
						WebSiteSystemId = channel.WebsiteSystemId,
						CountrySystemId = channel.CountryLinks.FirstOrDefault().CountrySystemId
					}, new StockStatusCalculatorItemArgs
					{
						VariantSystemId = variant.SystemId,
						Quantity = 1
					}).TryGetValue(variant.SystemId, out var stockStatus);


					//if stock status is not returned or the actual stock level is zero or below.
					return (stockStatus?.InStockQuantity.GetValueOrDefault(0) ?? -1) < 1;
				}

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