protected void Page_Init(object sender, System.EventArgs e) { _ShipMethodId = AlwaysConvert.ToInt(Request.QueryString["ShipMethodId"]); _ShipMethod = ShipMethodDataSource.Load(_ShipMethodId); if (_ShipMethod == null) { RedirectMe(); } //BIND TAX CODES IList <TaxCode> taxCodes = AbleContext.Current.Store.TaxCodes; TaxCode.DataSource = taxCodes; TaxCode.DataBind(); ListItem item = TaxCode.Items.FindByValue(_ShipMethod.TaxCodeId.ToString()); if (item != null) { TaxCode.SelectedIndex = TaxCode.Items.IndexOf(item); } SurchargeTaxCode.DataSource = taxCodes; SurchargeTaxCode.DataBind(); item = SurchargeTaxCode.Items.FindByValue(_ShipMethod.SurchargeTaxCodeId.ToString()); if (item != null) { SurchargeTaxCode.SelectedIndex = SurchargeTaxCode.Items.IndexOf(item); } }
protected void ShipMethods_Databound(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; if (ddl != null) { int shipmentId = AlwaysConvert.ToInt(ddl.Attributes["ShipmentId"]); BasketShipment shipment = _basket.Shipments.Find(a => a.Id == shipmentId); if (shipment != null) { if (shipment.ShipMethod != null) { ListItem item = ddl.Items.FindByValue(shipment.ShipMethodId.ToString()); if (item != null) { item.Selected = true; } } else { if (ddl.Items.Count > 0) { var shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ddl.Items[0].Value)); if (shipMethod != null) { shipment.ShipMethod = shipMethod; shipment.Save(); } } } } } }
protected void ShipMethod_SelectedIndexChanged(object sender, EventArgs e) { int currentShipMethod = AlwaysConvert.ToInt(ShipMethodsList.SelectedValue); CommerceBuilder.Shipping.ShipMethod method = ShipMethodDataSource.Load(currentShipMethod); if (method != null) { // set all shipments to the right shipping method Basket basket = AbleContext.Current.User.Basket; foreach (BasketShipment shipment in basket.Shipments) { shipment.ShipMethod = method; } basket.Save(); IBasketService service = AbleContext.Resolve <IBasketService>(); service.Recalculate(basket); PaymentPanel.Visible = true; BindBasketGrid(); MethodInfo widgetMethod = _AmazonProvider.GetType().GetMethod("GetPaymentWidget"); string eventHandler = "document.getElementById('" + PlaceOrderButton.ClientID + "').style.display = 'block';"; //string eventHandler = "alert('payment chosen');"; object[] parameters = new object[] { AbleContext.Current.User.Basket, eventHandler, false }; PlaceHolder paymentWidget = (PlaceHolder)widgetMethod.Invoke(_AmazonProvider, parameters); this.phPaymentWidget.Controls.Add(paymentWidget); } }
protected void ContinueButton_Click(object sender, EventArgs e) { //LOOP SHIPMENTS, GET SHIPPING METHODS Basket basket = AbleContext.Current.User.Basket; IList <BasketShipment> shipments = basket.Shipments; _ShipmentIndex = 0; bool allMethodsValid = true; foreach (BasketShipment shipment in shipments) { // shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(Request.Form["ShipMethod" + _ShipmentIndex])); RadioButtonList ShipMethodsList = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMethodsList") as RadioButtonList; shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ShipMethodsList.SelectedValue)); TextBox shipMessage = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMessage") as TextBox; if (shipMessage != null && !string.IsNullOrEmpty(shipMessage.Text)) { shipMessage.Text = StringHelper.StripHtml(shipMessage.Text.Trim()); if (shipMessage.Text.Length > 255) { shipMessage.Text = shipMessage.Text.Substring(0, 255); } shipment.ShipMessage = shipMessage.Text; } else { shipment.ShipMessage = ""; } shipment.Save(); if (shipment.ShipMethod == null) { allMethodsValid = false; } _ShipmentIndex++; } if (allMethodsValid) { Response.Redirect("Payment.aspx"); } else { ShipmentRepeater.DataSource = AbleContext.Current.User.Basket.Shipments; ShipmentRepeater.DataBind(); //HANDLE ERROR MESSAGE (UNEXPECTED) InvalidShipMethodPanel.Visible = true; } }
protected void MultipleRowDelete_Click(object sender, EventArgs e) { // Looping through all the rows in the GridView foreach (GridViewRow row in ShipMethodGrid.Rows) { CheckBox checkbox = (CheckBox)row.FindControl("DeleteCheckbox"); if ((checkbox != null) && (checkbox.Checked)) { // Retreive the GiftCertificateId int shipMethodId = Convert.ToInt32(ShipMethodGrid.DataKeys[row.RowIndex].Value); ShipMethod sm = ShipMethodDataSource.Load(shipMethodId); if (sm != null) { sm.Delete(); } } } ShipMethodGrid.DataBind(); }
private bool UpdateShipments() { //LOOP SHIPMENTS, GET SHIPPING METHODS Basket basket = AbleContext.Current.User.Basket; IList <BasketShipment> shipments = basket.Shipments; _ShipmentIndex = 0; bool allMethodsValid = true; foreach (BasketShipment shipment in shipments) { // shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(Request.Form["ShipMethod" + _ShipmentIndex])); DropDownList ShipMethodsList = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMethodsList") as DropDownList; shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ShipMethodsList.SelectedValue)); TextBox shipMessage = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMessage") as TextBox; if (shipMessage != null && !string.IsNullOrEmpty(shipMessage.Text)) { shipMessage.Text = StringHelper.StripHtml(shipMessage.Text.Trim()); if (shipMessage.Text.Length > 255) { shipMessage.Text = shipMessage.Text.Substring(0, 255); } shipment.ShipMessage = shipMessage.Text; } else { shipment.ShipMessage = ""; } shipment.Save(); if (shipment.ShipMethod == null) { allMethodsValid = false; } _ShipmentIndex++; } return(allMethodsValid); }
protected void ShipMethodsList_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = sender as DropDownList; int shipmentId = AlwaysConvert.ToInt(ddl.Attributes["ShipmentId"]); var shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ddl.SelectedValue)); if (shipMethod == null) { return; } foreach (BasketShipment shipment in _basket.Shipments) { if (shipment.Id == shipmentId) { shipment.ShipMethodId = shipMethod.Id; shipment.Save(); _basketService.Recalculate(_basket); _CurrentBasketHash = _basket.GetContentHash(OrderItemType.Product); break; } } _basket.Save(); }
protected void ChangeShipMethodOKButton_Click(object source, EventArgs e) { int shipmentId = AlwaysConvert.ToInt(Request.Form[ChangeShipMethodShipmentId.UniqueID]); int index = _Order.Shipments.IndexOf(shipmentId); if (index > -1) { // WE FOUND THE TARGET SHIPMENT. REMOVE OLD SHIPPING LINE ITEMS OrderShipment shipment = _Order.Shipments[index]; for (int i = shipment.OrderItems.Count - 1; i >= 0; i--) { OrderItemType itemType = shipment.OrderItems[i].OrderItemType; if (itemType == OrderItemType.Shipping || itemType == OrderItemType.Handling) { shipment.OrderItems.DeleteAt(i); } } // SEE IF WE HAVE A NEW SELECTED SHIPMETHOD int shipMethodId = AlwaysConvert.ToInt(Request.Form[NewShipMethod.UniqueID]); ShipMethod shipMethod = ShipMethodDataSource.Load(shipMethodId); if (shipMethod != null) { ShipRateQuote rate = shipMethod.GetShipRateQuote(shipment); if (rate != null) { // ADD NEW SHIPPING LINE ITEMS TO THE ORDER OrderItem shipRateLineItem = new OrderItem(); shipRateLineItem.OrderId = _Order.Id; shipRateLineItem.OrderItemType = OrderItemType.Shipping; shipRateLineItem.OrderShipmentId = shipmentId; shipRateLineItem.Name = shipMethod.Name; shipRateLineItem.Price = rate.Rate; shipRateLineItem.Quantity = 1; shipRateLineItem.TaxCodeId = shipMethod.TaxCodeId; shipRateLineItem.Save(); shipment.OrderItems.Add(shipRateLineItem); if (rate.Surcharge > 0) { shipRateLineItem = new OrderItem(); shipRateLineItem.OrderId = _Order.Id; shipRateLineItem.OrderItemType = OrderItemType.Handling; shipRateLineItem.OrderShipmentId = shipmentId; shipRateLineItem.Name = shipMethod.Name; shipRateLineItem.Price = rate.Surcharge; shipRateLineItem.Quantity = 1; shipRateLineItem.TaxCodeId = shipMethod.TaxCodeId; shipRateLineItem.Save(); shipment.OrderItems.Add(shipRateLineItem); } //Add the Tracking Number ShipGateway shipGateway = shipMethod.ShipGateway; foreach (TrackingNumber tn in shipment.TrackingNumbers) { tn.ShipGateway = shipGateway; } } } // UPDATE THE SHIPMENT WITH NEW METHOD ASSOCIATION shipment.ShipMethodId = shipMethodId; shipment.ShipMethodName = (shipMethod != null ? shipMethod.Name : string.Empty); shipment.Save(); // RELOAD ORDER AND REBIND THE PAGE FOR UPDATED INFO _Order = OrderDataSource.Load(_Order.Id); BindShipmentsGrid(); } }
/// <summary> /// Apply a ship method to this basket shipment /// </summary> /// <param name="shipMethodId">Id of the ship method to apply</param> public void ApplyShipMethod(int shipMethodId) { ApplyShipMethod(ShipMethodDataSource.Load(shipMethodId)); }
protected int SaveCoupon() { if (Page.IsValid) { // VALIDATE IF A PROPER END DATE IS SELECTED if (EndDate.SelectedEndDate != DateTime.MinValue && DateTime.Compare(EndDate.SelectedEndDate, StartDate.SelectedEndDate) < 0) { CustomValidator dateValidator = new CustomValidator(); dateValidator.ControlToValidate = "Name"; // THIS SHOULD BE "EndDate" CONTROL, BUT THAT CANNOT BE VALIDATED dateValidator.Text = "*"; dateValidator.ErrorMessage = "End date can not be earlier than start date."; dateValidator.IsValid = false; phEndDateValidator.Controls.Add(dateValidator); return(0); } Coupon existingCoupon = CouponDataSource.LoadForCouponCode(CouponCode.Text); if (existingCoupon != null) { CustomValidator codeValidator = new CustomValidator(); codeValidator.ControlToValidate = "CouponCode"; codeValidator.Text = "*"; codeValidator.ErrorMessage = "The coupon code " + CouponCode.Text + " is already in use."; codeValidator.IsValid = false; phCouponCodeValidator.Controls.Add(codeValidator); return(0); } Coupon _Coupon = new Coupon(); _Coupon.CouponType = this.CouponType; _Coupon.Name = Name.Text; _Coupon.CouponCode = CouponCode.Text; _Coupon.DiscountAmount = AlwaysConvert.ToDecimal(DiscountAmount.Text); _Coupon.IsPercent = (DiscountType.SelectedIndex == 0); //QUANTITY SETTINGS (PRODUCT COUPON) if (_Coupon.CouponType == CouponType.Product) { _Coupon.MinQuantity = AlwaysConvert.ToInt16(Quantity.Text); if (RepeatCoupon.Checked) { _Coupon.MaxQuantity = 0; _Coupon.QuantityInterval = _Coupon.MinQuantity; } else { _Coupon.MaxQuantity = _Coupon.MinQuantity; _Coupon.QuantityInterval = 0; } _Coupon.MaxValue = 0; _Coupon.MinPurchase = 0; } //PURCHASE RESTRICTIONS (ORDER AND SHIPPING COUPONS) else { _Coupon.MaxValue = AlwaysConvert.ToDecimal(MaxValue.Text); _Coupon.MinPurchase = AlwaysConvert.ToDecimal(MinPurchase.Text); _Coupon.MinQuantity = 0; _Coupon.MaxQuantity = 0; _Coupon.QuantityInterval = 0; } //SET START DATE _Coupon.StartDate = StartDate.SelectedDate; //SET END DATE _Coupon.EndDate = EndDate.SelectedEndDate; //MAX USES _Coupon.MaxUsesPerCustomer = AlwaysConvert.ToInt16(MaximumUsesPerCustomer.Text); _Coupon.MaxUses = AlwaysConvert.ToInt16(MaximumUses.Text); //COMBINE RULE _Coupon.AllowCombine = AllowCombine.Checked; //PRODUCT (OR SHIPPING) RULE if (_Coupon.CouponType != CouponType.Shipping) { _Coupon.ProductRule = (CouponRule)ProductRule.SelectedIndex; } else { _Coupon.ProductRule = (CouponRule)ShipMethodRule.SelectedIndex; _Coupon.ShipMethods.Clear(); _Coupon.Save(); if (_Coupon.ProductRule != CouponRule.All) { foreach (ListItem item in ShipMethodList.Items) { ShipMethod shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { _Coupon.ShipMethods.Add(shipMethod); } } } } //GROUP RESTRICTION if (UseGroupRestriction.SelectedIndex > 0) { _Coupon.Groups.Clear(); _Coupon.Save(); foreach (ListItem item in GroupList.Items) { Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { _Coupon.Groups.Add(group); } } } _Coupon.Save(); return(_Coupon.Id); } return(0); }