예제 #1
0
        //GET: /{*slug}
        public ActionResult Index(string slug)
        {
            // Basic Setup
            ProductPageViewModel model = IndexSetup(slug);

            // Load an line item specific values
            LoadLineItemValues(model);

            // Render Options
            model.PreRenderedOptions = HtmlRendering.ProductOptions(model.LocalProduct.Options, model.Selections);

            // Record and Return view
            PersonalizationServices.RecordProductViews(model.LocalProduct.Bvin, MTApp);
            return(View(model));
        }
예제 #2
0
        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));
        }