protected void PopulateRecommendations(CartModel model, int maxCount = 6) { if (model.LineItems.Any()) { var recommendedProductsForCart = _recommendationService.GetRecommendedProductsForCart(_currentCustomerService.GetCurrentUserId(), model.LineItems.Select(x => x.Code).ToList(), maxCount, _currentMarket.GetCurrentMarket().DefaultLanguage ); List <ProductListViewModel> recommendedProductList = new List <ProductListViewModel>(); if (recommendedProductsForCart != null && recommendedProductsForCart.Products != null) { foreach (var product in recommendedProductsForCart.Products) { IProductListViewModelInitializer modelInitializer = product as IProductListViewModelInitializer; if (modelInitializer != null) { var viewModel = _productService.GetProductListViewModel(modelInitializer); recommendedProductList.Add(viewModel); // Track HttpContext.AddRecommendationExposure(new TrackedRecommendation() { ProductCode = viewModel.Code, RecommenderName = recommendedProductsForCart.RecommenderName }); } } model.Recommendations = recommendedProductList; model.RecommendationsTrackingName = recommendedProductsForCart.RecommenderName; } } }