protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { var gridView = sender as GridView; var Id = (long)gridView.DataKeys[e.RowIndex].Value; var lineItem = CurrentOrder.Items.SingleOrDefault(y => y.Id == Id); if (lineItem != null) { // Before removing lineitem try to cancel subscription if (CurrentOrder.IsRecurring && !lineItem.RecurringBilling.IsCancelled) { var payManager = new OrderPaymentManager(CurrentOrder, HccApp); var res = payManager.RecurringSubscriptionCancel(lineItem.Id); } lineItem.QuantityReserved = lineItem.Quantity; HccApp.CatalogServices.InventoryLineItemUnreserveInventory(lineItem); CurrentOrder.Items.Remove(lineItem); HccApp.CalculateOrder(CurrentOrder); HccApp.OrderServices.EvaluatePaymentStatus(CurrentOrder); HccApp.OrderServices.Orders.Update(CurrentOrder); } var handler = OrderEdited; if (handler != null) { handler(this, EventArgs.Empty); } }
private void SaveShippingSelections(CheckoutViewModel model) { //Shipping var shippingRateKey = Request.Form["shippingrate"]; HccApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(shippingRateKey, model.CurrentOrder); // Save Values so far in case of later errors HccApp.CalculateOrder(model.CurrentOrder); // Save all the changes to the order HccApp.OrderServices.Orders.Update(model.CurrentOrder); }
/// <summary> /// Allows the REST API to create or update an order /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the order ID (bvin) and that this is an update, otherwise it assumes to create an /// order. /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the OrderDTO object</param> /// <returns>CategoryDTO - Serialized (JSON) version of the order</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var bvin = FirstParameter(parameters); var paramRecalc = querystring["recalc"]; var isRecalc = paramRecalc != null && paramRecalc.Trim() == "1"; OrderDTO postedItem = null; try { postedItem = Json.ObjectFromJson <OrderDTO>(postdata); } catch (Exception ex) { return(JsonApiResponseException(ex)); } var item = new Order(); if (!string.IsNullOrEmpty(bvin)) { item = HccApp.OrderServices.Orders.FindForCurrentStore(bvin); if (item != null) { item.FromDTO(postedItem); if (isRecalc) { HccApp.CalculateOrder(item); } HccApp.OrderServices.Orders.Update(item); } } else { item.FromDTO(postedItem); item.StoreId = HccApp.CurrentStore.Id; if (isRecalc) { HccApp.CalculateOrder(item); } HccApp.OrderServices.Orders.Create(item); } return(JsonApiResponse(item)); }
private bool SaveOrder() { CurrentOrder.UserID = UserIdField.Value; CurrentOrder.UserEmail = ucUserPicker.UserName; CurrentOrder.Instructions = txtInstructions.Text.Trim(); var newBillingAddress = ucBillingAddress.GetAsAddress(); var isBillingAddressChanged = !CurrentOrder.BillingAddress.IsEqualTo(newBillingAddress); CurrentOrder.BillingAddress = newBillingAddress; if (CurrentOrder.HasShippingItems) { CurrentOrder.ShippingAddress = ucShippingAddress.GetAsAddress(); } if (!ucOrderItems.UpdateQuantities()) { return(false); } // Save Shipping Selection var shippingRateKey = Request.Form["shippingrate"]; HccApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(shippingRateKey, CurrentOrder); // Shipping Override if (string.IsNullOrWhiteSpace(ShippingOverride.Text)) { CurrentOrder.TotalShippingBeforeDiscountsOverride = -1m; } else { var shipOverride = CurrentOrder.TotalShippingBeforeDiscountsOverride; decimal.TryParse(ShippingOverride.Text, NumberStyles.Currency, Thread.CurrentThread.CurrentUICulture, out shipOverride); CurrentOrder.TotalShippingBeforeDiscountsOverride = Money.RoundCurrency(shipOverride); } HccApp.CalculateOrder(CurrentOrder); HccApp.OrderServices.EvaluatePaymentStatus(CurrentOrder); var success = HccApp.OrderServices.Orders.Upsert(CurrentOrder); if (CurrentOrder.IsRecurring && isBillingAddressChanged) { var allSucceeded = true; var paymentManager = new OrderPaymentManager(CurrentOrder, HccApp); foreach (var li in CurrentOrder.Items) { if (!li.RecurringBilling.IsCancelled) { var result = paymentManager.RecurringSubscriptionUpdate(li.Id, null); allSucceeded &= result.Succeeded; if (!result.Succeeded) { ucMessageBox.ShowError(string.Format(Localization.GetString("lblSubscriptionUpdateFall"), li.ProductName)); } } } } if (success) { RunOrderEditedWorkflow(); } return(true); }
private void AddProductBySku() { SwitchProductPicker(false); if (string.IsNullOrWhiteSpace(NewSkuField.Text)) { ucMessageBox.ShowWarning("Please enter a sku first."); return; } var p = HccApp.CatalogServices.Products.FindBySku(NewSkuField.Text.Trim()); if (p != null && p.Sku.Length > 0) { if (CurrentOrder.Items.Count > 0 && p.IsRecurring != CurrentOrder.IsRecurring) { ucMessageBox.ShowError( "You can not mix recurring products with regular products within the same order"); return; } if (p.HasOptions() || p.IsUserSuppliedPrice || p.IsBundle) { ShowProductOptions(p); } else { if (CurrentOrder != null) { var quantity = 1; if (!p.HideQty) { int.TryParse(NewProductQuantity.Text, out quantity); } var selections = new OptionSelections(); var li = p.ConvertToLineItem(HccApp, quantity, selections); if (!CheckValidQty(CurrentOrder, li)) { return; } if (li.IsGiftCard) { if (IsGiftCardView.Value.ToLower() != "true") { RenderGiftCardDetails(li); IsGiftCardView.Value = "true"; btnAddProductBySku.Visible = false; return; } li.CustomPropGiftCardEmail = GiftCardRecEmail.Text; li.CustomPropGiftCardName = GiftCardRecName.Text; li.CustomPropGiftCardMessage = GiftCardMessage.Text; decimal gcAmount = 0; if (string.IsNullOrEmpty(lstAmount.SelectedValue)) { if (decimal.TryParse(GiftCardAmount.Text, out gcAmount)) { li.BasePricePerItem = Money.RoundCurrency(gcAmount); } } else { if (decimal.TryParse(lstAmount.SelectedValue, out gcAmount)) { li.BasePricePerItem = Money.RoundCurrency(gcAmount); } } } foreach (var item in CurrentOrder.Items) { item.QuantityReserved = item.Quantity; } HccApp.OrderServices.AddItemToOrder(CurrentOrder, li); HccApp.CalculateOrder(CurrentOrder); HccApp.OrderServices.EvaluatePaymentStatus(CurrentOrder); HccApp.OrderServices.Orders.Upsert(CurrentOrder); // Update Inventory only. li.Quantity = quantity; HccApp.CatalogServices.InventoryLineItemReserveInventory(li); ucMessageBox.ShowOk("Product Added!"); ProductAdded(this, EventArgs.Empty); IsGiftCardView.Value = "false"; ClearGiftCardDetails(); } } } else { ucMessageBox.ShowWarning("That SKU could not be located. Please try again."); } }
protected void btnAddVariant_Click(object sender, EventArgs e) { SwitchProductPicker(false); var product = HccApp.CatalogServices.Products.Find(AddProductSkuHiddenField.Value); if (product != null && product.Sku.Trim().Length > 0) { var quantity = 1; if (!product.HideQty) { int.TryParse(NewProductQuantity.Text, out quantity); } var selections = ParseSelections(product); if (ValidateSelections(product, selections)) { decimal?userPrice = null; if (product.IsUserSuppliedPrice) { decimal up = 0; if (decimal.TryParse(txtUserPrice.Text, out up)) { userPrice = Money.RoundCurrency(up); } else { userPrice = null; } } if (CurrentOrder != null) { var li = product.ConvertToLineItem(HccApp, quantity, selections, userPrice); if (!CheckValidQty(CurrentOrder, li)) { return; } HccApp.OrderServices.AddItemToOrder(CurrentOrder, li); HccApp.CalculateOrder(CurrentOrder); HccApp.OrderServices.EvaluatePaymentStatus(CurrentOrder); HccApp.OrderServices.Orders.Upsert(CurrentOrder); li.Quantity = quantity; HccApp.CatalogServices.InventoryLineItemReserveInventory(li); ucMessageBox.ShowOk("Product Added!"); AddProductSkuHiddenField.Value = string.Empty; ProductAdded(this, EventArgs.Empty); } } else { litMessage.Text = "That combination of choices/options is not available at the moment. Please select proper choices/options."; if (product != null && product.Sku.Trim().Length > 0) { if (product.HasOptions() || product.IsUserSuppliedPrice || product.IsBundle) { NewSkuField.Enabled = false; btnAddProductBySku.Visible = false; mvPanels.SetActiveView(vwProductChoices); } } } } }