public ActionResult Checkout() { SiteInfo si; if (!WebSession.Current.TryGetSiteInfo(out si)) { return(HttpNotFound()); } var redirectUri = _cartApi.GetWebCheckoutUrlAsync(_cartApi.GetCartAsync().Result, si.DrThemeId).Result; return(Redirect(redirectUri.AbsoluteUri)); }
private MiniCartViewModel GetViewModel() { var model = new MiniCartViewModel(); var quantityProperty = WebSession.Current.GetPersistentProperty(WebSession.ShoppingCartCount); if (!String.IsNullOrEmpty(quantityProperty)) { model.Quantity = Convert.ToInt32(quantityProperty); } else { var cart = _cartApi.GetCartAsync().Result; if (cart != null) { model.Quantity = cart.TotalItemsInCart; } WebSession.Current.SetPersistentProperty(WebSession.ShoppingCartCount, model.Quantity.ToString(CultureInfo.InvariantCulture)); } SiteInfo siteInfo; if (WebSession.Current.TryGetSiteInfo(out siteInfo) && siteInfo.IsCartHandledBySite) { model.IsCartHandledBySite = true; model.CartLink = _linkGenerator.GenerateShoppingCartLink(); } else { model.IsCartHandledBySite = false; model.CartLink = siteInfo.DrShoppingCartUrl; } return(model); }
public async Task <ShoppingCartViewModel> GetShoppingCartViewModelAsync() { Jungo.Models.ShopperApi.Cart.Cart cart; try { cart = await _cartApi.GetCartAsync().ConfigureAwait(false); } catch (Exception) { cart = new Jungo.Models.ShopperApi.Cart.Cart { TotalItemsInCart = 0 }; } return(MakeShoppingCartViewModel(cart)); }
public async Task <CustomerCart> GetCartAsync(string userId) { return(await cartApi.GetCartAsync(userId)); }
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)); } }