private void SaveInfoToOrder(bool savePaymentData) { if (chkBillToSame.Checked) { BillToAddress.LoadFromAddress(ShipToAddress.GetAsAddress()); } // Save Information to Cart in Case Save as Order Fails CurrentOrder.BillingAddress = BillToAddress.GetAsAddress(); CurrentOrder.ShippingAddress = ShipToAddress.GetAsAddress(); TagOrderWithUser(); CurrentOrder.UserEmail = EmailAddressTextBox.Text; CurrentOrder.Instructions = txtInstructions.Text.Trim(); // Save Shipping Selection var r = FindSelectedRate(ShippingRatesList.SelectedValue, CurrentOrder); if (r != null) { HccApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(r.UniqueKey, CurrentOrder); } if (savePaymentData) { // Save Payment Information SavePaymentInfo(); } HccApp.CalculateOrderAndSave(CurrentOrder); }
public ActionResult UpdateLineItem() { var lineItemId = long.Parse(Request["lineitemid"]); var lineItem = CurrentCart.Items.SingleOrDefault(li => li.Id == lineItemId); if (lineItem != null) { var product = lineItem.GetAssociatedProduct(HccApp); if (product != null) { var minQuantity = Math.Max(lineItem.FreeQuantity, Math.Max(product.MinimumQty, 1)); var quantity = 0; if (int.TryParse(Request["lineitemquantity"], out quantity)) { if (quantity >= minQuantity) { lineItem.Quantity = quantity; HccApp.CalculateOrderAndSave(CurrentCart); } } } } return(Redirect(Url.RouteHccUrl(HccRoute.Cart))); }
public ActionResult AjaxSignIn() { var username = Request.Form["username"] ?? string.Empty; var password = Request.Form["password"] ?? string.Empty; var validated = new ValidateModelResponse(); var errorMessage = string.Empty; string userId = null; if (HccApp.MembershipServices.LoginUser(username, password, out errorMessage, out userId)) { if (CurrentCart != null) { var custAcc = HccApp.MembershipServices.Customers.Find(userId); CurrentCart.UserEmail = custAcc != null?custAcc.Email.Trim() : null; CurrentCart.UserID = userId; HccApp.CalculateOrderAndSave(CurrentCart); } validated.Success = true; } else { validated.ResultMessages.Add(errorMessage); validated.Success = false; } return(new PreJsonResult(Web.Json.ObjectToJson(validated))); }
public ActionResult AddCoupon() { var code = Request["couponcode"] ?? string.Empty; CurrentCart.AddCouponCode(code.Trim()); HccApp.CalculateOrderAndSave(CurrentCart); return(Redirect(Url.RouteHccUrl(HccRoute.Cart))); }
public ActionResult GetRatesAsRadioButtons(FormCollection form) { var result = new ShippingRatesJsonModel(); var country = form["country"] ?? string.Empty; var firstname = form["firstname"] ?? string.Empty; var lastname = form["lastname"] ?? string.Empty; var address = form["address"] ?? string.Empty; var city = form["city"] ?? string.Empty; var state = form["state"] ?? string.Empty; var zip = form["zip"] ?? string.Empty; var orderid = form["orderid"] ?? string.Empty; var order = HccApp.OrderServices.Orders.FindForCurrentStore(orderid); order.ShippingAddress.FirstName = firstname; order.ShippingAddress.LastName = lastname; order.ShippingAddress.Line1 = address; order.ShippingAddress.City = city; order.ShippingAddress.PostalCode = zip; var c = HccApp.GlobalizationServices.Countries.Find(country); if (c != null) { order.ShippingAddress.CountryBvin = country; var region = c.Regions. FirstOrDefault(r => r.Abbreviation == state); if (region != null) { order.ShippingAddress.RegionBvin = region.Abbreviation; } } var rates = HccApp.OrderServices.FindAvailableShippingRates(order); if (rates != null && rates.Count > 0) { var selectedRate = rates. OfType <ShippingRateDisplay>(). FirstOrDefault(r => r.UniqueKey == order.ShippingMethodUniqueKey); if (selectedRate == null) { selectedRate = rates[0]; } HccApp.OrderServices.OrdersRequestShippingMethod(selectedRate, order); } else { order.ClearShippingPricesAndMethod(); } result.rates = HtmlRendering.ShippingRatesToRadioButtons(rates, 300, order.ShippingMethodUniqueKey); HccApp.CalculateOrderAndSave(order); return(new PreJsonResult(Web.Json.ObjectToJson(result))); }
public ActionResult RemoveCoupon() { var couponid = Request["couponid"] ?? string.Empty; long tempid = 0; long.TryParse(couponid, out tempid); CurrentCart.RemoveCouponCode(tempid); HccApp.CalculateOrderAndSave(CurrentCart); return(Redirect(Url.RouteHccUrl(HccRoute.Cart))); }
public ActionResult RemoveLineItem() { var lineItemId = long.Parse(Request["lineitemid"]); var lineItem = CurrentCart.Items.SingleOrDefault(li => li.Id == lineItemId); if (lineItem != null) { CurrentCart.Items.Remove(lineItem); HccApp.CalculateOrderAndSave(CurrentCart); } return(Redirect(Url.RouteHccUrl(HccRoute.Cart))); }
private void UpdateCartCustomerInfo() { // TODO: Replace this with an event hook when the CMS has the Login/Logout event hooks added // This is a workaround to re-calculate the cart in the event that the user has logged in or logged off if (HccApp.CurrentCustomer != null && !string.IsNullOrEmpty(HccApp.CurrentCustomer.Bvin)) { CurrentCart.UserID = HccApp.CurrentCustomer.Bvin; CurrentCart.UserEmail = HccApp.CurrentCustomer.Email; } else { CurrentCart.UserID = string.Empty; CurrentCart.UserEmail = string.Empty; } HccApp.CalculateOrderAndSave(CurrentCart); }
private void LoadValuesFromForm(CheckoutViewModel model) { // Agree to Terms var agreedValue = Request.Form["agreed"]; if (!string.IsNullOrEmpty(agreedValue)) { model.AgreedToTerms = true; } var o = model.CurrentOrder; if (o.HasShippingItems && model.CurrentOrder.CustomProperties["ViaCheckout"] != null && model.CurrentOrder.CustomProperties["ViaCheckout"].Value == "1") { o.ShippingAddress.CopyTo(o.BillingAddress); } HccApp.CalculateOrderAndSave(o); LoadShippingMethodsForOrder(o); }
protected void btnUpdateQuantities_Click(object sender, EventArgs e) { var gridView = CurrentOrder.IsRecurring ? gvSubscriptions : gvItems; foreach (GridViewRow row in gridView.Rows) { if (row.RowType != DataControlRowType.DataRow) { continue; } var itemId = (long)gridView.DataKeys[row.RowIndex].Value; var txtQty = row.FindControl("txtQty") as TextBox; var li = CurrentOrder.GetLineItem(itemId); var quantity = int.Parse(txtQty.Text.Trim()); var opResult = HccApp.OrderServices.OrdersUpdateItemQuantity(itemId, quantity, CurrentOrder); if (!string.IsNullOrEmpty(opResult.Message)) { ucMessageBox.ShowError(opResult.Message); } } var result = HccApp.CheckForStockOnItems(CurrentOrder); if (!result.Success) { ucMessageBox.ShowWarning(result.Message); } HccApp.CalculateOrderAndSave(CurrentOrder); var handler = OrderEdited; if (handler != null) { handler(this, EventArgs.Empty); } }
private RedirectResult HandleActionParams() { //1. AddSKU - this is the sku that should be added to the cart automatically //2. AddSKUQTY - this is the quantity of the provided sku that should be added. //3. CouponCode - the coupon that should automatically be applied, if valid. //4. RedirectToCheckout=True - redirects the user automatically to the checkout. if (ModuleContext == null || ModuleContext.Configuration.DesktopModule.ModuleName != "Hotcakes.Cart") { return(null); } var clearCart = (string)RouteData.Values["ClearCart"]; var addSKU = (string)RouteData.Values["AddSKU"]; var addSKUQTY = (string)RouteData.Values["AddSKUQTY"]; var CouponCode = (string)RouteData.Values["CouponCode"]; var RedirectToCheckout = (string)RouteData.Values["RedirectToCheckout"]; if (!string.IsNullOrWhiteSpace(addSKU) || !string.IsNullOrWhiteSpace(addSKUQTY) || !string.IsNullOrWhiteSpace(CouponCode)) { HccApp.OrderServices.EnsureShoppingCart(); } if (!string.IsNullOrWhiteSpace(clearCart)) { var clear = bool.Parse(clearCart); if (clear) { HccApp.ClearOrder(CurrentCart); } } string[] SKUs = null; string[] SKUQTYs = null; if (!string.IsNullOrWhiteSpace(addSKU)) { SKUs = addSKU.Split(','); } if (!string.IsNullOrWhiteSpace(addSKUQTY)) { SKUQTYs = addSKUQTY.Split(','); } if (addSKU == null) { return(null); } if (SKUQTYs == null) { SKUQTYs = new string[SKUs.Length]; } if (SKUQTYs != null && SKUs.Length != SKUQTYs.Length) { FlashFailure(Localization.GetString("ParamsCountMismatch")); return(null); } var errorsPresent = false; for (var i = 0; i < SKUs.Length; i++) { var sku = SKUs[i]; var skuQty = SKUQTYs[i]; var qty = 1; if (!string.IsNullOrEmpty(skuQty)) { if (!int.TryParse(skuQty, out qty)) { errorsPresent = true; FlashFailure(Localization.GetFormattedString("QuantityParsingError", skuQty)); } } var p = HccApp.CatalogServices.Products.FindBySku(sku); if (p != null) { // TODO: check for products with options AddSingleProduct(p, qty); } else { errorsPresent = true; FlashFailure(Localization.GetFormattedString("SKUNotExists", sku)); } } if (!string.IsNullOrWhiteSpace(CouponCode)) { CurrentCart.AddCouponCode(CouponCode.Trim()); HccApp.CalculateOrderAndSave(CurrentCart); } if (!errorsPresent) { if (!string.IsNullOrWhiteSpace(RedirectToCheckout)) { var redirect = bool.Parse(RedirectToCheckout); if (redirect) { Response.Redirect(Url.RouteHccUrl(HccRoute.Checkout)); } } return(Redirect(Url.RouteHccUrl(HccRoute.Cart))); } return(null); }