/// <summary> /// Renders the Basket View where the data is populated via an AJAX call given below /// </summary> /// <returns></returns> public ActionResult Index() { var basket = _basketApi.GetBasketData("")?.Result; if (Request.UrlReferrer != null) { ViewBag.PrevPage = Request.UrlReferrer.ToString(); } else { ViewBag.PrevPage = SiteViewTypes.Home; } SetDataLayerVariables(basket, WebhookEventTypes.BasketViewed); return(View(CustomViews.BASKET, basket ?? new BasketModel { })); }
protected BasketModel GetIndexBasketData(string basketId = "") { var basket = _basketApi.GetBasketData(basketId)?.Result; if (!string.IsNullOrEmpty(basketId) && basket != null) { // capture the campaign UpdateBasketCampaign(Guid.Parse(basketId)); } if (Request.UrlReferrer != null) { ViewBag.PrevPage = Request.UrlReferrer.ToString(); } else { ViewBag.PrevPage = SiteViewTypes.Home; } SetDataLayerVariables(basket, WebhookEventTypes.BasketViewed); return(basket); }
public JsonResult GetItemRecommendations(string itemId, List <string> recentViewedProductList, string recommedType, string modelId, int noOfItems, string userId) { var resp = new List <RecommendationResult>(); if (recommedType == RecommendationTypes.RecentView.ToString()) { if (recentViewedProductList != null && !recentViewedProductList.Any()) { return(JsonSuccess("", JsonRequestBehavior.AllowGet)); } resp = (from o in recentViewedProductList select new RecommendationResult { RecommendedItemId = o }).ToList(); } else { _recommendationSettings = _sessionContext.CurrentSiteConfig.RecommendationSettings; _recommendationClient = new RecommendationsAPI(new Uri(_recommendationSettings.ApiEndPoint)); _recommendationClient.HttpClient.DefaultRequestHeaders.Add("x-api-key", _recommendationSettings.RecommederKey); // string userId = string.Empty; string visitorId = string.Empty; if (string.IsNullOrEmpty(userId)) { userId = string.Empty; if (_sessionContext.CurrentUser != null) { userId = _sessionContext.CurrentUser.UserId.ToString(); } else { visitorId = _sessionContext.DeviceId; } } if (string.IsNullOrEmpty(modelId)) { modelId = GetRecommendationModelId(recommedType); } var modelGuId = Guid.Empty; Guid.TryParse(modelId, out modelGuId); var usageEvent = new List <UsageEvent>(); if (recommedType == RecommendationTypes.Basket.ToString()) { var basket = _basketApi.GetBasketData("")?.Result; if (basket != null && basket.LineItems != null && basket.LineItems.Any()) { itemId = string.Join(",", basket.LineItems.Select(x => x.ProductId)); } } if (!string.IsNullOrEmpty(itemId)) { if (modelGuId == Guid.Empty) { resp = _recommendationClient.Models.GetItemRecommendationsFromDefaultModel(itemId, noOfItems)?.ToList(); } else { resp = _recommendationClient.Models.GetItemRecommendations(modelGuId, itemId, noOfItems)?.ToList(); } } else { if (modelGuId == Guid.Empty) { resp = _recommendationClient.Models.GetPersonalizedRecommendationsFromDefaultModel(usageEvent, userId != string.Empty ? userId : visitorId, noOfItems)?.ToList(); } else { resp = _recommendationClient.Models.GetPersonalizedRecommendations(modelGuId, usageEvent, userId != string.Empty ? userId : visitorId, noOfItems)?.ToList(); } } } if (resp != null && resp.Count > 0) { SearchRequestModel criteria = new SearchRequestModel { Filters = new List <SearchFilter>() }; foreach (var data in resp) { var searchFilter = new SearchFilter { Key = "recordId", Value = data.RecommendedItemId }; criteria.Filters.Add(searchFilter); } var response = _productApi.GetProducts(criteria); if (response != null && response.Result != null) { return(JsonSuccess(response.Result.Results, JsonRequestBehavior.AllowGet)); } } return(JsonSuccess("", JsonRequestBehavior.AllowGet)); }