public ShipMethodCollection GetAllShipMethodsDynamicCollection(string whereExpression, string orderBy) { IDBManager dbm = new DBManager(); ShipMethodCollection cols = new ShipMethodCollection(); try { dbm.CreateParameters(2); dbm.AddParameters(0, "@WhereCondition", whereExpression); dbm.AddParameters(1, "@OrderByExpression", orderBy); IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectShipMethodsDynamic"); while (reader.Read()) { ShipMethod SM = new ShipMethod(); SM.ShipMethodID = Int32.Parse(reader["ShipMethodID"].ToString()); SM.Name = reader["Name"].ToString(); SM.ShipBase = decimal.Parse(reader["ShipBase"].ToString()); SM.ShipRate = decimal.Parse(reader["ShipRate"].ToString()); SM.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString()); cols.Add(SM); } } catch (Exception ex) { log.Write(ex.Message, "GetAllShipMethodsDynamicCollection"); throw (ex); } finally { dbm.Dispose(); } return(cols); }
public ShipMethodCollection GetAllShipMethodsCollection() { IDBManager dbm = new DBManager(); ShipMethodCollection cols = new ShipMethodCollection(); try { IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectShipMethodAll"); while (reader.Read()) { ShipMethod SM = new ShipMethod(); SM.ShipMethodID = Int32.Parse(reader["ShipMethodID"].ToString()); SM.Name = reader["Name"].ToString(); SM.ShipBase = decimal.Parse(reader["ShipBase"].ToString()); SM.ShipRate = decimal.Parse(reader["ShipRate"].ToString()); SM.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString()); cols.Add(SM); } } catch (Exception ex) { log.Write(ex.Message, "GetAllShipMethodsCollection"); throw (ex); } finally { dbm.Dispose(); } return(cols); }
/// <summary> /// Indicates whether the given shipmethod is applicable on this BasketShipment or not /// </summary> /// <param name="shipMeth">The ship method to check</param> /// <returns><b>true</b> if ship method is applicable, <b>false</b> otherwise</returns> public bool IsShipMethodApplicable(ShipMethod shipMeth) { ShipMethodCollection shipMeths = this.ApplicableShipMethods; foreach (ShipMethod meth in shipMeths) { if (meth.ShipMethodId == shipMeth.ShipMethodId) return true; } return false; }
// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode public static ShipMethodCollection GetShipMethodCollection() { ISortExpression Sort = new SortExpression(); Sort.Add(ShipMethodFields.ShipRate | SortOperator.Ascending); ShipMethodCollection Methods = new ShipMethodCollection(); Methods.GetMulti(null, 0, Sort); return(Methods); }
public static ShipMethod FindShipMethod(ShipMethodCollection shipMethods, int shipMethodId) { foreach (ShipMethod shipMeth in shipMethods) { if (shipMeth.ShipMethodId == shipMethodId) { return(shipMeth); } } return(null); }
public static ShipMethod FindShipMethod(ShipMethodCollection shipMethods, string sanitizedName) { if (string.IsNullOrEmpty(sanitizedName)) { return(null); } string sanName; foreach (ShipMethod shipMeth in shipMethods) { sanName = AcHelper.SanitizeText(shipMeth.Name); if (sanitizedName.Equals(sanName, StringComparison.InvariantCultureIgnoreCase)) { return(shipMeth); } } return(null); }
public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address) { TraceContext trace = WebTrace.GetTraceContext(); ShippingResult RetVal = new ShippingResult(); RetVal.Shippable = false; CommerceBuilder.Orders.Basket basket = ThisOrder.AcBasket; if (basket == null) { basket = AcHelper.GetAcBasket(ThisOrder.ShoppingCart, true); if (basket != null) { basket.Package(false); } ThisOrder.AcBasket = basket; } if (basket == null || basket.Shipments.Count == 0) { return(RetVal); } ShipMethodCollection shipMethods = ThisOrder.AcShipMethods; if (shipMethods == null) { shipMethods = ShipMethodDataSource.LoadForStore(); ThisOrder.AcShipMethods = shipMethods; } if (shipMethods == null || shipMethods.Count == 0) { return(RetVal); } ShipMethod shipMethod; string methodName = ""; int shipMethodId = AcHelper.ExtractShipMethodId(ShipMethodName, out methodName); if (shipMethodId != 0) { shipMethod = AcHelper.FindShipMethod(shipMethods, shipMethodId); } else { shipMethod = AcHelper.FindShipMethod(shipMethods, methodName); } if (shipMethod == null) { return(RetVal); } CommerceBuilder.Users.Address acAddress = AcHelper.GetAnonAcAddress(basket.User, Address); if (!shipMethod.IsApplicableTo(acAddress)) { return(RetVal); } ShipRateQuote rateQuote; //TODO : should assign a default ship rate RetVal.ShippingRate = 0; bool isValid = true; foreach (Orders.BasketShipment bshipment in basket.Shipments) { bshipment.SetAddress(acAddress); if (!bshipment.IsShipMethodApplicable(shipMethod)) { isValid = false; break; } rateQuote = shipMethod.GetShipRateQuote(bshipment); if (rateQuote != null && rateQuote.TotalRate > 0) { RetVal.ShippingRate += rateQuote.TotalRate; } else if (rateQuote == null) { //this ship method is not applicable isValid = false; break; } } if (isValid) { RetVal.Shippable = true; } return(RetVal); }
public static ShipMethod GetShipMethod(Basket basket) { bool shipMethodNameFound = false; string shipMethName; BasketItem sItem = basket.Items.Find(delegate(BasketItem item) { return(item.OrderItemType == OrderItemType.Shipping); }); if (sItem == null) { shipMethName = "Unknown(GoogleCheckout)"; } else { shipMethName = sItem.Name; shipMethodNameFound = true; } ShipMethodCollection shipMethods = ShipMethodDataSource.LoadForStore(); ShipMethod shipMethod; string methodName = ""; int shipMethodId = ExtractShipMethodId(shipMethName, out methodName); if (shipMethodId != 0) { shipMethod = FindShipMethod(shipMethods, shipMethodId); } else { shipMethod = FindShipMethod(shipMethods, methodName); } if (shipMethod == null && !shipMethName.Equals("Unknown(GoogleCheckout)")) { shipMethod = FindShipMethod(shipMethods, "Unknown(GoogleCheckout)"); } if (shipMethod == null) { //create a new ship method shipMethod = new ShipMethod(); shipMethod.Name = "Unknown(GoogleCheckout)"; shipMethod.ShipMethodType = ShipMethodType.FlatRate; shipMethod.MinPurchase = 999999; shipMethod.Save(); } if (shipMethod.Name.Equals("Unknown(GoogleCheckout)")) { if (shipMethodNameFound) { Logger.Warn(string.Format("Shipping method named '{0}' used by GoogleCheckout could not be matched to any shipping method in the store.", shipMethName)); Logger.Warn("Using 'Unknown(GoogleCheckout)' shipping method."); } else { Logger.Warn("No shipping method found in the GoogleCheckout notification."); Logger.Warn("Using 'Unknown(GoogleCheckout)' shipping method."); } } return(shipMethod); }