/// <summary> /// Binds the data. /// </summary> private void BindData() { if (Order != null && Order.OrderForms != null && Order.OrderForms.Count > 0) { DataBind(); OrderPaymentProcessed.Text = GetOrderPaymentStatus(); // find billing address OrderForm oForm = Order.OrderForms[0]; if (!String.IsNullOrEmpty(oForm.BillingAddressId)) { OrderAddressCollection addresses = Order.OrderAddresses; OrderAddress billingAddress = null; foreach (OrderAddress tmpAddress in addresses) { if (String.Compare(tmpAddress.Name, oForm.BillingAddressId, true) == 0) { billingAddress = tmpAddress; break; } } if (billingAddress != null) { OrderEmail.Text = billingAddress.Email; } } // Hide skus list if shipments already exist /*if (Order.Shipments.Length > 0) * { * SkusPurchased.Visible = false; * } * else * { * SkusPurchased.Visible = true; * }*/ } }
/// <summary> /// Returns the package option array when method id and package that needs to be send is passed. /// Use passed message string to pass errors back to the application if any occured. /// </summary> /// <param name="methodId"></param> /// <param name="items">The items.</param> /// <param name="message">The message.</param> /// <returns>empty array if no results found</returns> public ShippingRate GetRate(Guid methodId, LineItem[] items, ref string message) { if (items == null || items.Length == 0) { return(null); } ShippingRate rate = null; ShippingMethodDto methodDto = ShippingManager.GetShippingMethod(methodId); if (methodDto != null && methodDto.ShippingMethod.Count > 0) { ShippingMethodDto.ShippingMethodRow method = methodDto.ShippingMethod[0]; if (items[0].Parent != null && items[0].Parent.Parent != null) { // find shipping address OrderAddress shippingAddress = null; OrderAddressCollection addresses = items[0].Parent.Parent.OrderAddresses; foreach (OrderAddress address in addresses) { if (String.Compare(address.Name, items[0].ShippingAddressId, StringComparison.OrdinalIgnoreCase) == 0) { shippingAddress = address; break; } } if (shippingAddress != null) { // calculate total item weight decimal weight = 0; foreach (LineItem item in items) { if (!String.IsNullOrEmpty(item.CatalogEntryId)) { CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntryDto(item.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (dto.CatalogEntry.Count > 0) { CatalogEntryDto.VariationRow[] variationRows = dto.CatalogEntry[0].GetVariationRows(); if (variationRows != null && variationRows.Length > 0) { weight += (decimal)variationRows[0].Weight * item.Quantity; } } } } // get shipping method cases DataTable casesTable = ShippingManager.GetShippingMethodCases(methodId, shippingAddress.CountryCode, shippingAddress.State, shippingAddress.PostalCode, shippingAddress.RegionCode, null, shippingAddress.City, weight); // get the row with the greatest weight ; the rows all contain weights less than the order weight double?shippingPrice = null; double maxWeight = 0; object objprice; foreach (DataRow caseRow in casesTable.Rows) { object obj = caseRow["Total"]; if (obj != null && obj != DBNull.Value) { double rowweight = (double)obj; if (maxWeight < rowweight) { maxWeight = rowweight; objprice = caseRow["Charge"]; if (objprice != null && objprice != DBNull.Value) { shippingPrice = (double)objprice; } } else if (maxWeight == rowweight) { //if the weight is the same, take the lower price objprice = caseRow["Charge"]; if (objprice != null && objprice != DBNull.Value) { double newprice = (double)objprice; if ((shippingPrice == null) || (newprice < shippingPrice)) { shippingPrice = newprice; } } } } } if (shippingPrice == null) { shippingPrice = 0; } rate = new ShippingRate(methodId, method.DisplayName, method.BasePrice + (decimal)shippingPrice, method.Currency); } } } else { message = "The shipping method could not be loaded."; return(null); } return(rate); }