private ShippingMethodAndRate GetSelectedShippingMethod() { ShippingMethodAndRate selectedShippingMethod = null; foreach (RepeaterItem shippingMethod in rptShippingMethods.Items) { GlobalRadioButton rdo = shippingMethod.FindControl("rdoChooseShipping") as GlobalRadioButton; if (rdo != null && rdo.Checked) { //this is the selected method. Get the related shipping method id and return HiddenField hiddenShippingMethodId = shippingMethod.FindControl("hiddenShippingMethodId") as HiddenField; HiddenField hiddenShippingMethodName = shippingMethod.FindControl("hiddenShippingMethodName") as HiddenField; HiddenField hiddenRate = shippingMethod.FindControl("hiddenRate") as HiddenField; if (hiddenShippingMethodId != null && hiddenShippingMethodName != null) { Guid methodId = new Guid(hiddenShippingMethodId.Value); string methodName = hiddenShippingMethodName.Value; decimal rate = 0m; if (decimal.TryParse(hiddenRate.Value, out rate)) { selectedShippingMethod = new ShippingMethodAndRate(methodName, string.Empty, rate, methodId); } break; } } } return(selectedShippingMethod); }
private ShippingMethodAndRate GetShippingRateInfo(ShippingMethodDto.ShippingMethodRow row, Shipment shipment) { ShippingMethodAndRate returnRate = null; string nameAndRate = string.Empty; // Check if package contains shippable items, if it does not use the default shipping method instead of the one specified Type type = Type.GetType(row.ShippingOptionRow.ClassName); if (type == null) { throw new TypeInitializationException(row.ShippingOptionRow.ClassName, null); } string outputMessage = string.Empty; IShippingGateway provider = (IShippingGateway)Activator.CreateInstance(type); if (shipment != null) { ShippingRate rate = provider.GetRate(row.ShippingMethodId, shipment, ref outputMessage); nameAndRate = string.Format("{0} : {1}", row.Name, rate.Money.Amount.ToString("C")); returnRate = new ShippingMethodAndRate(row.Name, nameAndRate, rate.Money.Amount, row.ShippingMethodId); } return(returnRate); }
private void SaveSetShippingMethod() { if (CartHelper.Cart.OrderForms[0].Shipments != null && CartHelper.Cart.OrderForms[0].Shipments.Count > 0) { Shipment shipment = CartHelper.Cart.OrderForms[0].Shipments[0]; ShippingMethodAndRate selectedShippingMethod = GetSelectedShippingMethod(); if (selectedShippingMethod != null) { shipment.ShippingMethodId = selectedShippingMethod.ShippingMethodId; shipment.ShippingMethodName = selectedShippingMethod.ShippingMethodName; CartHelper.Cart.AcceptChanges(); } } }
protected void ShippingMethods_ItemDataBound(object sender, RepeaterItemEventArgs e) { Literal displayText = e.Item.FindControl("litShippingNameAndPrice") as Literal; HiddenField hiddenMethodId = e.Item.FindControl("hiddenShippingMethodId") as HiddenField; HiddenField hiddenMethodName = e.Item.FindControl("hiddenShippingMethodName") as HiddenField; HiddenField hiddenRate = e.Item.FindControl("hiddenRate") as HiddenField; ShippingMethodAndRate dataItem = e.Item.DataItem as ShippingMethodAndRate; if (displayText != null && hiddenMethodId != null && hiddenMethodName != null && dataItem != null) { displayText.Text = dataItem.ShippingMethodNameAndRate; hiddenMethodId.Value = dataItem.ShippingMethodId.ToString(); hiddenMethodName.Value = dataItem.ShippingMethodName; hiddenRate.Value = dataItem.ShippingRate.ToString(); } }