protected virtual ProductModel GetProductModel(IVisitorContext visitorContext, Item productItem)
        {
            Assert.ArgumentNotNull(visitorContext, nameof(visitorContext));

            if (productItem == null)
            {
                return(null);
            }

            var variantEntityList = new List <Variant>();

            if (productItem.HasChildren)
            {
                variantEntityList = this.LoadVariants(productItem);
            }

            var product = new Product(productItem, variantEntityList);

            product.CatalogName = this.StorefrontContext.CatalogName;

            product.CustomerAverageRating = this.CatalogManager.GetProductRating(productItem);

            this.CatalogManager.GetProductPrice(product);
            this.CatalogManager.GetStockInfo(product, this.StorefrontContext.ShopName);

            var renderingModel = new ProductModel(productItem);

            renderingModel.CurrencySymbol        = this.CurrencyProvider.GetCurrencySymbolByCode(product.CurrencyCode);
            renderingModel.ListPrice             = product.ListPrice;
            renderingModel.AdjustedPrice         = product.AdjustedPrice;
            renderingModel.StockStatusName       = product.StockStatusName;
            renderingModel.CustomerAverageRating = product.CustomerAverageRating;

            foreach (var renderingModelVariant in renderingModel.Variants)
            {
                var variant = product.Variants.FirstOrDefault(x => x.VariantId == renderingModelVariant.ProductVariantId);
                if (variant == null)
                {
                    continue;
                }

                renderingModelVariant.CurrencySymbol        = this.CurrencyProvider.GetCurrencySymbolByCode(variant.CurrencyCode);
                renderingModelVariant.ListPrice             = variant.ListPrice;
                renderingModelVariant.AdjustedPrice         = variant.AdjustedPrice;
                renderingModelVariant.StockStatusName       = variant.StockStatusName;
                renderingModelVariant.CustomerAverageRating = variant.CustomerAverageRating;
            }

            return(renderingModel);
        }
        protected IList <ProductModel> AdjustProductPriceAndStockStatus(
            IVisitorContext visitorContext,
            SearchResults searchResult,
            Item currentCategory)
        {
            var result   = new List <ProductModel>();
            var products = new List <Product>();

            if ((searchResult.SearchResultItems != null) && (searchResult.SearchResultItems.Count > 0))
            {
                foreach (var searchResultItem in searchResult.SearchResultItems)
                {
                    var variants = new List <Variant>();
                    var product  = new Product(searchResultItem, variants);
                    product.CatalogName           = this.StorefrontContext.CatalogName;
                    product.CustomerAverageRating = this.CatalogManager.GetProductRating(searchResultItem);
                    products.Add(product);
                }

                this.CatalogManager.GetProductBulkPrices(products);

                // this.InventoryManager.GetProductsStockStatus(products, currentStorefront.UseIndexFileForProductStatusInLists);
                foreach (var product in products)
                {
                    var productModel = new ProductModel(product.Item);
                    productModel.CurrencySymbol        = this.CurrencyProvider.GetCurrencySymbolByCode(product.CurrencyCode);
                    productModel.ListPrice             = product.ListPrice;
                    productModel.AdjustedPrice         = product.AdjustedPrice;
                    productModel.StockStatusName       = product.StockStatusName;
                    productModel.CustomerAverageRating = product.CustomerAverageRating;
                    result.Add(productModel);
                }
            }

            return(result);
        }