public ActionResult AddToCart(long itemid) { var customerId = HccApp.CurrentCustomerId; var wi = HccApp.CatalogServices.WishListItems.Find(itemid); if (wi == null || wi.CustomerId != customerId) { return(Redirect(Url.RouteHccUrl(HccRoute.WishList))); } // Add to Cart var p = HccApp.CatalogServices.Products.FindWithCache(wi.ProductId); var isPurchasable = ValidateSelections(p, wi.SelectionData); var isNotRecurringMixed = ValidateRecurringItems(p); if (isPurchasable && isNotRecurringMixed) { var li = p.ConvertToLineItem(HccApp, 1, wi.SelectionData); HccApp.OrderServices.EnsureShoppingCart(); HccApp.AddToOrderWithCalculateAndSave(CurrentCart, li); return(Redirect(Url.RouteHccUrl(HccRoute.Cart))); } var items = HccApp.CatalogServices.WishListItems.FindByCustomerIdPaged(HccApp.CurrentCustomerId, 1, 50); var model = PrepItems(items); if (model.Count < 1) { FlashInfo(Localization.GetString("WishListEmpty")); } return(View("Index", model)); }
private bool AddToCart(ProductPageViewModel model) { var isValidSelections = ValidateSelections(model); var isValidQty = DetermineQuantityToAdd(model); var isValidUserPrice = ValidateUserPrice(model); var isValidGiftCardPrice = ValidateGiftCardAmount(model); var isNotRecurringMixed = ValidateRecurringItems(model); if (isValidSelections && isValidQty && isValidUserPrice && isValidGiftCardPrice && isNotRecurringMixed) { var li = ConvertProductToLineItem(model); var currentCart = HccApp.OrderServices.EnsureShoppingCart(); RemovePreviousLineItem(model, currentCart); return(HccApp.AddToOrderWithCalculateAndSave(currentCart, li)); } return(false); }
private void AddSingleProduct(Product p, int quantity) { var qty = quantity; if (qty < 1) { qty = 1; } if (p != null) { var li = p.ConvertToLineItem(HccApp, qty); var cart = CurrentCart; if (cart == null) { cart = HccApp.OrderServices.EnsureShoppingCart(); } li.Quantity = qty; HccApp.AddToOrderWithCalculateAndSave(cart, li); } }