protected void PopulateRecommendations(CartModel model, List <Recommendation> recommendedProductsForCart, int maxCount = 6) { if (model.LineItems.Any()) { List <ProductListViewModel> recommendedProductList = new List <ProductListViewModel>(); if (recommendedProductsForCart.Any()) { foreach (var recommendation in recommendedProductsForCart.Where(x => x != null && x.ContentLink != ContentReference.EmptyReference) .Take(3)) { var product = _contentLoader.Get <CatalogContentBase>(recommendation.ContentLink); IProductListViewModelInitializer modelInitializer = product as IProductListViewModelInitializer; if (modelInitializer != null) { var viewModel = _productService.GetProductListViewModel(modelInitializer); viewModel.RecommendationId = recommendation.RecommendationId.ToString(); // viewModel.TrackingName = recommendedProductsForCart.RecommenderName; recommendedProductList.Add(viewModel); } } model.Recommendations = recommendedProductList; // model.RecommendationsTrackingName = recommendedProductsForCart.RecommenderName; } } }
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; } } }
public virtual List <ProductListViewModel> GetSearchResults(string language) { IContentLoader loader = ServiceLocator.Current.GetInstance <IContentLoader>(); ProductService productService = ServiceLocator.Current.GetInstance <ProductService>(); ReferenceConverter refConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); SearchResults <FindProduct> results = GetResults(language); List <ProductListViewModel> searchResult = new List <ProductListViewModel>(); foreach (SearchHit <FindProduct> searchHit in results.Hits) { ContentReference contentLink = refConverter.GetContentLink(searchHit.Document.Id, CatalogContentType.CatalogEntry, 0); // The content can be deleted from the db, but still exist in the index IContentData content = null; if (loader.TryGet(contentLink, out content)) { IProductListViewModelInitializer modelInitializer = content as IProductListViewModelInitializer; if (modelInitializer != null) { searchResult.Add(productService.GetProductListViewModel(modelInitializer)); } } } return(searchResult); }
//public ProductListViewModel GetProductListViewModel(WineSKUContent wineSkuContent) //{ // IProductListViewModelInitializer modelInitializer = wineSkuContent as IProductListViewModelInitializer; // if (modelInitializer != null) // return modelInitializer.Populate(); // return null; //} public ProductListViewModel GetProductListViewModel(IProductListViewModelInitializer productContent) { if (productContent != null) { return(productContent.Populate(_currentMarket.GetCurrentMarket())); } return(null); }
public ActionResult Index(NodeContent currentContent) { SetLanguage(); string language = Language; var client = SearchClient.Instance; IContentLoader loader = ServiceLocator.Current.GetInstance <IContentLoader>(); ProductService productService = ServiceLocator.Current.GetInstance <ProductService>(); ReferenceConverter refConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); try { SearchResults <FindProduct> results = client.Search <FindProduct>() .Filter(x => x.ParentCategoryId.Match(currentContent.ContentLink.ID)) .Filter(x => x.Language.Match(language)) .StaticallyCacheFor(TimeSpan.FromMinutes(1)) .GetResult(); List <ProductListViewModel> searchResult = new List <ProductListViewModel>(); foreach (SearchHit <FindProduct> searchHit in results.Hits) { ContentReference contentLink = refConverter.GetContentLink(searchHit.Document.Id, CatalogContentType.CatalogEntry, 0); // The content can be deleted from the db, but still exist in the index IContentData content = null; if (loader.TryGet(contentLink, out content)) { IProductListViewModelInitializer modelInitializer = content as IProductListViewModelInitializer; if (modelInitializer != null) { searchResult.Add(productService.GetProductListViewModel(modelInitializer)); } } } return(PartialView("Blocks/NodeContentPartial", searchResult)); } catch (Exception) { return(PartialView("Blocks/NodeContentPartial", null)); } }
public virtual List <ProductListViewModel> GetSearchResults(string language) { IContentLoader loader = ServiceLocator.Current.GetInstance <IContentLoader>(); ProductService productService = ServiceLocator.Current.GetInstance <ProductService>(); ReferenceConverter refConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); SearchResults <FindProduct> results = GetResults(language); List <ProductListViewModel> searchResult = new List <ProductListViewModel>(); foreach (SearchHit <FindProduct> searchHit in results.Hits) { ContentReference contentLink = refConverter.GetContentLink(searchHit.Document.Id, CatalogContentType.CatalogEntry, 0); var content = loader.Get <IContentData>(contentLink); IProductListViewModelInitializer modelInitializer = content as IProductListViewModelInitializer; if (modelInitializer != null) { searchResult.Add(productService.GetProductListViewModel(modelInitializer)); } } return(searchResult); }