public ActionResult AddToCart(long itemid) { string customerId = SessionManager.GetCurrentUserId(MTApp.CurrentStore); WishListItem wi = MTApp.CatalogServices.WishListItems.Find(itemid); if (wi != null) { if (wi.CustomerId == customerId) { // Add to Cart Product p = MTApp.CatalogServices.Products.Find(wi.ProductId); bool IsPurchasable = ValidateSelections(p, wi); if ((IsPurchasable)) { LineItem li = MTApp.CatalogServices.ConvertProductToLineItem(p, wi.SelectionData, 1, MTApp); Order Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore); if (Basket.UserID != SessionManager.GetCurrentUserId(MTApp.CurrentStore)) { Basket.UserID = SessionManager.GetCurrentUserId(MTApp.CurrentStore); } MTApp.AddToOrderWithCalculateAndSave(Basket, li); SessionManager.SaveOrderCookies(Basket, MTApp.CurrentStore); return(Redirect("~/cart")); } } } return(RedirectToAction("index")); }
private void AddSingleProduct(Product p, int quantity) { int qty = quantity; if (qty < 1) { qty = 1; } if (p != null) { Order o = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore); LineItem li = MTApp.CatalogServices.ConvertProductToLineItem(p, new OptionSelectionList(), qty, MTApp); li.Quantity = qty; MTApp.AddToOrderWithCalculateAndSave(o, li); SessionManager.SaveOrderCookies(o, MTApp.CurrentStore); } }
public ActionResult IndexPost(string slug) { ProductPageViewModel model = IndexSetup(slug); // see if we're editing a line item instead of a new add string lineItemString = Request.Form["lineitemid"]; if (!string.IsNullOrEmpty(lineItemString)) { if (model.LineItemId == string.Empty) { model.LineItemId = lineItemString; } } ParseSelections(model); if (Request.Form["savelaterbutton.x"] != null) { // Save for Later MTApp.CatalogServices.SaveProductToWishList(model.LocalProduct, model.Selections, 1, MTApp); return(Redirect("~/account/saveditems")); } else { // Add to Cart bool IsPurchasable = ValidateSelections(model); if ((IsPurchasable)) { DetermineQuantityToAdd(model); if (model.Quantity > 0) { LineItem li = MTApp.CatalogServices.ConvertProductToLineItem(model.LocalProduct, model.Selections, model.Quantity, MTApp); Order Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore); if (Basket.UserID != MTApp.CurrentCustomerId) { Basket.UserID = MTApp.CurrentCustomerId; } if (model.LineItemId.Trim().Length > 0) { long lineItemId = 0; long.TryParse(model.LineItemId, out lineItemId); var toRemove = Basket.Items.Where(y => y.Id == lineItemId).SingleOrDefault(); if (toRemove != null) { Basket.Items.Remove(toRemove); } } MTApp.AddToOrderWithCalculateAndSave(Basket, li); SessionManager.SaveOrderCookies(Basket, MTApp.CurrentStore); return(Redirect("~/cart")); } } } // Load Selections from form here // Do checks and add model.PreRenderedOptions = HtmlRendering.ProductOptions(model.LocalProduct.Options, model.Selections); return(View(model)); }