コード例 #1
0
        [HttpPost] // POST: /checkout/applyshipping
        public ActionResult ApplyShipping()
        {
            ApplyShippingResponse result = new ApplyShippingResponse();

            string rateKey = Request.Form["MethodId"];
            string orderid = Request.Form["OrderId"];

            if (rateKey == null)
            {
                rateKey = "";
            }
            if (orderid == null)
            {
                orderid = "";
            }


            Order o = MTApp.OrderServices.Orders.FindForCurrentStore(orderid);

            MTApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(rateKey, o, MTApp.CurrentStore);
            MTApp.CalculateOrderAndSave(o);
            SessionManager.SaveOrderCookies(o, MTApp.CurrentStore);

            result.totalsastable = o.TotalsAsTable();

            return(new PreJsonResult(MerchantTribe.Web.Json.ObjectToJson(result)));
        }
コード例 #2
0
        public ActionResult RemoveLineItem()
        {
            string ids = Request["lineitemid"] ?? string.Empty;
            long   Id  = 0;

            long.TryParse(ids, out Id);

            string orderBvin = Request["orderbvin"] ?? string.Empty;

            Order Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);

            if (Basket != null)
            {
                if (Basket.bvin == orderBvin)
                {
                    var li = Basket.Items.Where(y => y.Id == Id).SingleOrDefault();
                    if (li != null)
                    {
                        Basket.Items.Remove(li);
                        MTApp.CalculateOrderAndSave(Basket);
                        SessionManager.SaveOrderCookies(Basket, MTApp.CurrentStore);
                    }
                }
            }
            return(Redirect("~/cart"));
        }
コード例 #3
0
        private void LoadShippingMethodsForOrder(CheckoutViewModel model)
        {
            Order o = model.CurrentOrder;

            o.ShippingAddress.CopyTo(o.BillingAddress);
            MTApp.CalculateOrderAndSave(o);
            SessionManager.SaveOrderCookies(o, MTApp.CurrentStore);
            LoadShippingMethodsForOrder(o);
        }
コード例 #4
0
        public ActionResult AddCoupon()
        {
            Order  Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);
            string code   = Request["couponcode"] ?? string.Empty;

            Basket.AddCouponCode(code.Trim());
            MTApp.CalculateOrderAndSave(Basket);
            SessionManager.SaveOrderCookies(Basket, MTApp.CurrentStore);
            return(Redirect("~/cart"));
        }
コード例 #5
0
        public ActionResult RemoveCoupon()
        {
            string couponid = Request["couponid"] ?? string.Empty;
            long   tempid   = 0;

            long.TryParse(couponid, out tempid);

            Order Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);

            Basket.RemoveCouponCode(tempid);
            MTApp.CalculateOrderAndSave(Basket);
            SessionManager.SaveOrderCookies(Basket, MTApp.CurrentStore);

            return(Redirect("~/cart"));
        }
コード例 #6
0
        private SystemOperationResult SaveOrder()
        {
            SystemOperationResult result = new SystemOperationResult(false, "");

            Order o = MTApp.OrderServices.Orders.FindForCurrentStore(this.BvinField.Value);

            if (o == null)
            {
                result.Success = false;
                result.Message = "Unable to reload order.";
                return(result);
            }

            o.UserID       = this.UserIdField.Value;
            o.UserEmail    = this.UserPicker1.UserName;
            o.Instructions = this.InstructionsField.Text.Trim();

            o.BillingAddress  = this.BillingAddressEditor.GetAsAddress();
            o.ShippingAddress = this.ShippingAddressEditor.GetAsAddress();

            SystemOperationResult modifyResult = ModifyQuantities(o);

            if (!modifyResult.Success)
            {
                result.Message = modifyResult.Message;
            }

            // Save Shipping Selection
            string shippingRateKey = Request.Form["shippingrate"];

            MTApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(shippingRateKey, o);

            // Shipping Override
            if (this.ShippingOverride.Text.Trim().Length < 1)
            {
                o.TotalShippingBeforeDiscountsOverride = -1m;
            }
            else
            {
                decimal shipOverride = o.TotalShippingBeforeDiscountsOverride;
                decimal.TryParse(this.ShippingOverride.Text, System.Globalization.NumberStyles.Currency, System.Threading.Thread.CurrentThread.CurrentUICulture, out shipOverride);
                o.TotalShippingBeforeDiscountsOverride = shipOverride;
            }

            result.Success = MTApp.CalculateOrderAndSave(o);

            return(result);
        }
コード例 #7
0
        protected void ItemGridView_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            this.MessageBox1.ClearMessage();

            long Id = (long)ItemsGridView.DataKeys[e.RowIndex].Value;

            if (o != null)
            {
                var li = o.Items.Where(y => y.Id == Id).SingleOrDefault();
                if (li != null)
                {
                    o.Items.Remove(li);
                    MTApp.CalculateOrderAndSave(o);
                }
                ClearShipping();
                LoadOrder(o.bvin);
            }
        }
コード例 #8
0
        public ActionResult AjaxSignIn()
        {
            string email    = Request.Form["email"] ?? string.Empty;
            string password = Request.Form["password"] ?? string.Empty;

            SignInViewModel posted = new SignInViewModel()
            {
                Email    = email,
                Password = password
            };

            ValidateModelResponse validated = ValidateLoginModel(posted, false);

            if (validated.Success)
            {
                string errorMessage = string.Empty;
                string userId       = string.Empty;
                if (MTApp.MembershipServices.LoginCustomer(posted.Email.Trim(),
                                                           posted.Password.Trim(),
                                                           ref errorMessage,
                                                           this.Request.RequestContext.HttpContext,
                                                           ref userId, MTApp))
                {
                    MerchantTribe.Commerce.Orders.Order cart = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);
                    if (cart != null && !string.IsNullOrEmpty(cart.bvin))
                    {
                        cart.UserEmail = posted.Email.Trim();
                        cart.UserID    = userId;
                        MTApp.CalculateOrderAndSave(cart);
                        SessionManager.SaveOrderCookies(cart, MTApp.CurrentStore);
                    }
                    validated.Success = true;
                }
                else
                {
                    validated.ResultMessages.Add(errorMessage);
                    validated.Success = false;
                }
            }

            return(new PreJsonResult(MerchantTribe.Web.Json.ObjectToJson(validated)));
        }
コード例 #9
0
        private bool SaveInfoToOrder(bool savePaymentData)
        {
            bool result = true;

            if (o != null)
            {
                if (this.chkBillToSame.Checked == true)
                {
                    this.BillToAddress.LoadFromAddress(this.ShipToAddress.GetAsAddress());
                }

                // Save Information to Basket in Case Save as Order Fails
                o.BillingAddress  = this.BillToAddress.GetAsAddress();
                o.ShippingAddress = this.ShipToAddress.GetAsAddress();
                TagOrderWithUser();

                o.UserEmail = this.EmailAddressTextBox.Text;

                // Save Shipping Selection
                ShippingRateDisplay r = FindSelectedRate(this.ShippingRatesList.SelectedValue, o);
                if (r != null)
                {
                    MTApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(r.UniqueKey, o);
                }

                if (savePaymentData)
                {
                    // Save Payment Information
                    SavePaymentInfo(o);
                }

                MTApp.CalculateOrderAndSave(o);
            }

            else
            {
                result = false;
            }

            return(result);
        }
コード例 #10
0
        public ActionResult SignInPost(SignInViewModel posted)
        {
            SignInSetup();

            if (Request.QueryString["mode"] != null)
            {
                posted.Mode = Request.QueryString["mode"];
            }

            ValidateModelResponse validated = ValidateLoginModel(posted, false);

            if (validated.Success == false)
            {
                foreach (string s in validated.ResultMessages)
                {
                    FlashWarning(s);
                }
            }
            else
            {
                string errorMessage = string.Empty;
                string userId       = string.Empty;
                if (MTApp.MembershipServices.LoginCustomer(posted.Email.Trim(),
                                                           posted.Password.Trim(),
                                                           ref errorMessage,
                                                           this.Request.RequestContext.HttpContext,
                                                           ref userId, MTApp))
                {
                    MerchantTribe.Commerce.Orders.Order cart = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);
                    if (cart != null && !string.IsNullOrEmpty(cart.bvin))
                    {
                        cart.UserEmail = posted.Email.Trim();
                        cart.UserID    = userId;
                        MTApp.CalculateOrderAndSave(cart);
                        SessionManager.SaveOrderCookies(cart, MTApp.CurrentStore);
                    }

                    // if we got here from checkout, return to checkout
                    if (posted.Mode.Trim().ToLowerInvariant() == "checkout")
                    {
                        return(Redirect("~/checkout"));
                    }
                    // otherwise send to account home
                    return(Redirect("~/account"));
                }
                else
                {
                    string errorMessage2 = string.Empty;
                    // Failed to Login as Customer, Try admin account
                    if (MTApp.AccountServices.LoginAdminUser(posted.Email.Trim(),
                                                             posted.Password.Trim(),
                                                             ref errorMessage2,
                                                             this.Request.RequestContext.HttpContext,
                                                             MTApp))
                    {
                        return(Redirect("~/bvadmin"));
                    }
                    this.FlashWarning(errorMessage);
                }
            }

            return(View(posted));
        }
コード例 #11
0
        public ActionResult GetRatesAsRadioButtons(FormCollection form)
        {
            ShippingRatesJsonResponse result = new ShippingRatesJsonResponse();

            string country   = form["country"] ?? string.Empty;
            string firstname = form["firstname"] ?? string.Empty;
            string lastname  = form["lastname"] ?? string.Empty;
            string address   = form["address"] ?? string.Empty;
            string city      = form["city"] ?? string.Empty;
            string state     = form["state"] ?? string.Empty;
            string zip       = form["zip"] ?? string.Empty;
            string orderid   = form["orderid"] ?? string.Empty;

            Order o = MTApp.OrderServices.Orders.FindForCurrentStore(orderid);

            o.ShippingAddress.FirstName  = firstname;
            o.ShippingAddress.LastName   = lastname;
            o.ShippingAddress.Line1      = address;
            o.ShippingAddress.City       = city;
            o.ShippingAddress.PostalCode = zip;
            Country c = Country.FindByBvin(country);

            if ((c != null))
            {
                o.ShippingAddress.CountryBvin = country;
                o.ShippingAddress.CountryName = c.DisplayName;
                foreach (Region r in c.Regions)
                {
                    if ((r.Abbreviation == state))
                    {
                        o.ShippingAddress.RegionBvin = r.Abbreviation;
                        o.ShippingAddress.RegionName = r.Name;
                    }
                }
            }

            SortableCollection <ShippingRateDisplay> rates = MTApp.OrderServices.FindAvailableShippingRates(o);

            string rateKey         = o.ShippingMethodUniqueKey;
            bool   rateIsAvailable = false;

            // See if rate is available
            if ((rateKey.Length > 0))
            {
                foreach (MerchantTribe.Commerce.Shipping.ShippingRateDisplay r in rates)
                {
                    if ((r.UniqueKey == rateKey))
                    {
                        rateIsAvailable = true;
                        MTApp.OrderServices.OrdersRequestShippingMethod(r, o);
                    }
                }
            }

            // if it's not availabe, pick the first one or default
            if ((rateIsAvailable == false))
            {
                if ((rates.Count > 0))
                {
                    MTApp.OrderServices.OrdersRequestShippingMethod(rates[0], o);
                    rateKey = rates[0].UniqueKey;
                }
                else
                {
                    o.ClearShippingPricesAndMethod();
                }
            }

            result.rates = HtmlRendering.ShippingRatesToRadioButtons(rates, 300, o.ShippingMethodUniqueKey);

            MTApp.CalculateOrderAndSave(o);
            SessionManager.SaveOrderCookies(o, MTApp.CurrentStore);

            result.totalsastable = o.TotalsAsTable();

            //System.Threading.Thread.Sleep(500)
            return(new PreJsonResult(MerchantTribe.Web.Json.ObjectToJson(result)));
        }
コード例 #12
0
        private void CheckForQuickAdd()
        {
            if (this.Request.QueryString["quickaddid"] != null)
            {
                string  bvin = Request.QueryString["quickaddid"];
                Product prod = MTApp.CatalogServices.Products.Find(bvin);
                if (prod != null)
                {
                    int quantity = 1;
                    if (this.Request.QueryString["quickaddqty"] != null)
                    {
                        int val = 0;
                        if (int.TryParse(Request.QueryString["quickaddqty"], out val))
                        {
                            quantity = val;
                        }
                    }
                    AddSingleProduct(prod, quantity);
                }
            }
            else if (this.Request.QueryString["quickaddsku"] != null)
            {
                string  sku  = Request.QueryString["quickaddsku"];
                Product prod = MTApp.CatalogServices.Products.FindBySku(sku);
                if (prod != null)
                {
                    int quantity = 1;
                    if (this.Request.QueryString["quickaddqty"] != null)
                    {
                        int val = 0;
                        if (int.TryParse(Request.QueryString["quickaddqty"], out val))
                        {
                            quantity = val;
                        }
                    }
                    AddSingleProduct(prod, quantity);
                }
            }
            else if (this.Request.QueryString["multi"] != null)
            {
                string[] skus       = Request.QueryString["multi"].Split(';');
                Order    Basket     = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);
                bool     addedParts = false;

                foreach (string s in skus)
                {
                    string[] skuparts = s.Split(':');
                    string   newsku   = skuparts[0];
                    string   bvin     = string.Empty;
                    Product  p        = MTApp.CatalogServices.Products.FindBySku(newsku);
                    if (p != null)
                    {
                        if (p.Bvin.Trim().Length > 0)
                        {
                            int qty = 1;
                            if (skuparts.Length > 1)
                            {
                                int.TryParse(skuparts[1], out qty);
                            }
                            if (qty < 1)
                            {
                                qty = 1;
                            }
                            AddSingleProduct(p, qty);
                            addedParts = true;
                        }
                    }
                }
                if (addedParts)
                {
                    MTApp.CalculateOrderAndSave(Basket);
                    SessionManager.SaveOrderCookies(Basket, MTApp.CurrentStore);
                }
            }
        }