//[Authorize] public ActionResult Index(PropertiesQuery query) { var builder = new OffersViewModelBuilder(_context); var viewModel = builder.Build(query, User.Identity.GetUserId()); return(View(viewModel)); }
public ActionResult GetUpdatedCrossSell(string viewName, string promotionId, string emptyCartPromotionId, string title, int maxNumberOfProducts) { var cart = _cartApi.GetCartAsync().Result; CrossSellViewModel vm = null; var lineItem = (cart.LineItems == null || cart.LineItems.LineItem == null) ? null : cart.LineItems.LineItem.FirstOrDefault(); if (lineItem != null) { vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(promotionId, lineItem.Product, _linkGenerator.GenerateShoppingCartLink()).Result; } // If there are no driving products, then try the empty cart promotion, as the CrossSellPartController does if (vm == null || vm.Offers.Count == 0) { vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(!string.IsNullOrEmpty(emptyCartPromotionId) ? emptyCartPromotionId : promotionId, _linkGenerator.GenerateShoppingCartLink()).Result; } OffersViewModelBuilder.RemoveCartItemsFromOffers(vm, cart); if (vm == null) { vm = new CrossSellViewModel { Offers = new List <CrossSellOfferViewModel>() } } ; vm.Title = title; vm.PromotionId = promotionId; vm.EmptyCartPromotionId = emptyCartPromotionId; vm.MaxNumberOfProducts = maxNumberOfProducts; return(PartialView(viewName, vm)); }
public override ActionResult Index() { CrossSellViewModel vm = null; var promotionId = CurrentItem.PromotionId; int?maxNumberOfProducts = 0; // We are on a shopping cart page. Try to build the cross-sell data with the items in the cart. string emptyCartPromotionId = null; if (CurrentItem != null) { emptyCartPromotionId = CurrentItem.EmptyCartPromotionId; maxNumberOfProducts = CurrentItem.MaxNumberOfProducts; } //todo: Get the cart from session?? var cartViewModel = WebSession.Current.Get <ShoppingCartViewModel>(WebSession.ShoppingCartSlot); var cart = cartViewModel == null?_cartApi.GetCartAsync().Result : cartViewModel.Cart; if (cart.LineItems.LineItem != null) { foreach (var li in cart.LineItems.LineItem) { if (li.Product != null) { vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(promotionId, li.Product, _linkGenerator.GenerateShoppingCartLink()).Result; } if (vm != null) { break; } } } // If nothing is in the cart, or if no Offers were returned for this product, try to use the default offers. if (vm == null || vm.Offers == null || vm.Offers.Count == 0) { vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(promotionId, _linkGenerator.GenerateShoppingCartLink()).Result; } // Set the empty cart promotion Id, which is used by an Ajax call to the ShoppingCartPart.GetUpdatedCrossSell() if (vm != null) { vm.EmptyCartPromotionId = emptyCartPromotionId; } OffersViewModelBuilder.RemoveCartItemsFromOffers(vm, cart); if (vm == null) { vm = new CrossSellViewModel { Offers = new List <CrossSellOfferViewModel>() } } ; vm.Name = CurrentItem.Name; vm.Title = CurrentItem.Title; vm.PromotionId = promotionId; vm.MaxNumberOfProducts = maxNumberOfProducts ?? 0; return(PartialView(vm)); } }
public override ActionResult Index() { CrossSellViewModel vm = null; var promotionId = CurrentItem.PromotionId; int?maxNumberOfProducts = 0; if (CurrentItem is CrossSellInterstitialPart) { var siteRoot = CmsFinder.FindSitePageFromSiteId(WebSession.Current.SiteId); if (siteRoot != null && !string.IsNullOrEmpty(siteRoot.PromotionId)) { promotionId = siteRoot.PromotionId; } } if (CurrentPage is ShoppingCartPage) { // We are on a shopping cart page. Try to build the cross-sell data with the items in the cart. string emptyCartPromotionId = null; var part = CurrentItem as CandyRackPart; if (part != null) { emptyCartPromotionId = part.EmptyCartPromotionId; maxNumberOfProducts = part.MaxNumberOfProducts; } //todo: Get the cart from session?? var cartViewModel = WebSession.Current.Get <ShoppingCartViewModel>(WebSession.ShoppingCartSlot); var cart = cartViewModel == null?_cartApi.GetCartAsync().Result : cartViewModel.Cart; if (cart.LineItems.LineItem != null) { foreach (var li in cart.LineItems.LineItem) { if (li.Product != null) { vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(promotionId, li.Product, _linkGenerator.GenerateShoppingCartLink()).Result; } if (vm != null) { break; } } } // If nothing is in the cart, or if no Offers were returned for this product, try to use the default offers. if (vm == null || vm.Offers == null || vm.Offers.Count == 0) { vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(promotionId, _linkGenerator.GenerateShoppingCartLink()).Result; } // Set the empty cart promotion Id, which is used by an Ajax call to the ShoppingCartPart.GetUpdatedCrossSell() if (vm != null) { vm.EmptyCartPromotionId = emptyCartPromotionId; } OffersViewModelBuilder.RemoveCartItemsFromOffers(vm, cart); } else if (CurrentPage is ProductPage || CurrentPage is ShoppingCartInterstitialPage) { ProductDetailPageViewModel product; if (WebSession.Current.TryGet(WebSession.CurrentProductSlot, out product)) { if (product != null) { var crossSellProduct = product.Product; var scip = CurrentPage as ShoppingCartInterstitialPage; if (scip != null && scip.ProductID != null) { var scipPid = long.Parse(scip.ProductID); crossSellProduct = product.Product.Variations.Product.FirstOrDefault(p => p.Id == scipPid); } vm = _offersViewModelBuilder.GetCrossSellViewModelAsync(promotionId, crossSellProduct, _linkGenerator.GenerateShoppingCartLink()).Result; maxNumberOfProducts = 999; } } } if (vm == null) { vm = new CrossSellViewModel { Offers = new List <CrossSellOfferViewModel>() } } ; vm.Name = CurrentItem.Name; vm.Title = CurrentItem.Title; vm.PromotionId = promotionId; vm.MaxNumberOfProducts = maxNumberOfProducts ?? 0; return(PartialView(vm)); } }