public static ShipMethod Load(Int32 shipMethodId, bool useCache) { if (shipMethodId == 0) { return(null); } ShipMethod shipMethod = null; string key = "ShipMethod_" + shipMethodId.ToString(); if (useCache) { shipMethod = ContextCache.GetObject(key) as ShipMethod; if (shipMethod != null) { return(shipMethod); } } shipMethod = new ShipMethod(); if (shipMethod.Load(shipMethodId)) { if (useCache) { ContextCache.SetObject(key, shipMethod); } return(shipMethod); } return(null); }
/// <summary> /// Loads a ship method for given ship method name /// </summary> /// <param name="shipMethodName">Name of the ship method to load</param> /// <returns>The loaded ship method or null if no ship method with given name could be found</returns> public static ShipMethod LoadForShipMethodName(string shipMethodName) { //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT "); selectQuery.Append(ShipMethod.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_ShipMethods"); selectQuery.Append(" WHERE ac_ShipMethods.Name = @shipMethodName"); selectQuery.Append(" AND StoreId = @storeId"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@shipMethodName", System.Data.DbType.String, shipMethodName); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); using (IDataReader dr = database.ExecuteReader(selectCommand)) { if (dr.Read()) { ShipMethod shipMeth = new ShipMethod(); ShipMethod.LoadDataReader(shipMeth, dr); return(shipMeth); } dr.Close(); } return(null); }
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); } }
public static bool Delete(Int32 shipMethodId) { ShipMethod shipMethod = new ShipMethod(); if (shipMethod.Load(shipMethodId)) { return(shipMethod.Delete()); } return(false); }
/// <summary> /// Recalculates shipping charges for the given basket. /// </summary> /// <param name="basket">The basket to calculate shipping charges for.</param> public static void Calculate(Basket basket) { ClearExistingShipping(basket); foreach (BasketShipment shipment in basket.Shipments) { if (shipment.Warehouse != null) { ShipMethod shipMethod = shipment.ShipMethod; if (shipMethod != null) { ShipRateQuote rate = shipMethod.GetShipRateQuote(shipment); if (rate != null) { BasketItem shipRateLineItem = new BasketItem(); shipRateLineItem.BasketId = basket.BasketId; shipRateLineItem.OrderItemType = OrderItemType.Shipping; shipRateLineItem.BasketShipmentId = shipment.BasketShipmentId; shipRateLineItem.Name = shipMethod.Name; shipRateLineItem.Price = rate.Rate; shipRateLineItem.Quantity = 1; shipRateLineItem.TaxCodeId = shipMethod.TaxCodeId; shipRateLineItem.Save(); basket.Items.Add(shipRateLineItem); if (rate.Surcharge > 0) { shipRateLineItem = new BasketItem(); shipRateLineItem.BasketId = basket.BasketId; shipRateLineItem.OrderItemType = OrderItemType.Handling; shipRateLineItem.BasketShipmentId = shipment.BasketShipmentId; shipRateLineItem.Name = shipMethod.Name; shipRateLineItem.Price = rate.Surcharge; shipRateLineItem.Quantity = 1; shipRateLineItem.TaxCodeId = shipMethod.SurchargeTaxCodeId; shipRateLineItem.Save(); basket.Items.Add(shipRateLineItem); } } else { //rate quote could not be obtained for some reason. Logger.Warn("Failed to obtain rate quote for the given ship method '" + shipMethod.Name + "'"); //here we need to communicate back to the caller that the selected ship method can't be used shipment.ShipMethodId = 0; shipment.Save(); } } } } }
public static ShipMethodCollection LoadForWarehouse(Int32 warehouseId, int maximumRows, int startRowIndex, string sortExpression) { //DEFAULT SORT EXPRESSION if (string.IsNullOrEmpty(sortExpression)) { sortExpression = "OrderBy"; } //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + ShipMethod.GetColumnNames("ac_ShipMethods")); selectQuery.Append(" FROM ac_ShipMethods, ac_ShipMethodWarehouses"); selectQuery.Append(" WHERE ac_ShipMethods.ShipMethodId = ac_ShipMethodWarehouses.ShipMethodId"); selectQuery.Append(" AND ac_ShipMethodWarehouses.WarehouseId = @warehouseId"); selectQuery.Append(" AND StoreId = @storeId"); selectQuery.Append(" ORDER BY " + sortExpression); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@warehouseId", System.Data.DbType.Int32, warehouseId); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); //EXECUTE THE COMMAND ShipMethodCollection results = new ShipMethodCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { ShipMethod shipMethod = new ShipMethod(); ShipMethod.LoadDataReader(shipMethod, dr); results.Add(shipMethod); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
public static ShipMethodCollection LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression) { //DEFAULT SORT EXPRESSION if (string.IsNullOrEmpty(sortExpression)) { sortExpression = "OrderBy"; } //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + ShipMethod.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_ShipMethods"); string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria; selectQuery.Append(whereClause); selectQuery.Append(" ORDER BY " + sortExpression); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); //EXECUTE THE COMMAND ShipMethodCollection results = new ShipMethodCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { ShipMethod shipMethod = new ShipMethod(); ShipMethod.LoadDataReader(shipMethod, dr); results.Add(shipMethod); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
/// <summary> /// Loads the given ShipMethod object from the given database data reader. /// </summary> /// <param name="shipMethod">The ShipMethod object to load.</param> /// <param name="dr">The database data reader to read data from.</param> public static void LoadDataReader(ShipMethod shipMethod, IDataReader dr) { //SET FIELDS FROM ROW DATA shipMethod.ShipMethodId = dr.GetInt32(0); shipMethod.StoreId = dr.GetInt32(1); shipMethod.ShipMethodTypeId = dr.GetInt16(2); shipMethod.Name = dr.GetString(3); shipMethod.Surcharge = dr.GetDecimal(4); shipMethod.ShipGatewayId = NullableData.GetInt32(dr, 5); shipMethod.ServiceCode = NullableData.GetString(dr, 6); shipMethod.MinPurchase = dr.GetDecimal(7); shipMethod.SurchargeIsVisible = dr.GetBoolean(8); shipMethod.SurchargeIsPercent = NullableData.GetBoolean(dr, 9); shipMethod.TaxCodeId = NullableData.GetInt32(dr, 10); shipMethod.SurchargeTaxCodeId = NullableData.GetInt32(dr, 11); shipMethod.OrderBy = dr.GetInt16(12); shipMethod.IsDirty = false; }
public static SaveResult Update(ShipMethod shipMethod) { return(shipMethod.Save()); }
public static SaveResult Insert(ShipMethod shipMethod) { return(shipMethod.Save()); }
public static bool Delete(ShipMethod shipMethod) { return(shipMethod.Delete()); }
/// <summary> /// Loads a collection of ShipMethod objects for given BasketShipment /// </summary> /// <param name="shipment">BasketShipment to load the ship methods for</param> /// <returns>A collection of ShipMethod objects for given BasketShipment</returns> public static ShipMethodCollection LoadForShipment(IShipment shipment) { //GET ALL SHIP METHODS THAT CAN APPLY TO THIS SHIPMENT ShipMethodCollection shipMethodCollection = new ShipMethodCollection(); //FIRST DETERMINE THE SHIP ZONE(S) FOR THE SHIPMENT ShipZoneCollection shipmentZoneCollection = shipment.ShipZones; //BUILD A LIST OF ZONEIDS FOR QUERY CRITERIA //NOW QUERY ANY SHIP METHODS THAT CAN SHIP FROM THIS WAREHOUSE TO ANY ZONE OR ONE OF THE ASSOCIATED ZONES //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT DISTINCT " + ShipMethod.GetColumnNames("ac_ShipMethods")); selectQuery.Append(" FROM ((ac_ShipMethods LEFT JOIN ac_ShipMethodWarehouses ON ac_ShipMethods.ShipMethodId = ac_ShipMethodWarehouses.ShipMethodId)"); selectQuery.Append(" LEFT JOIN ac_ShipMethodShipZones ON ac_ShipMethods.ShipMethodId = ac_ShipMethodShipZones.ShipMethodId)"); selectQuery.Append(" LEFT JOIN ac_ShipMethodGroups ON ac_ShipMethods.ShipMethodId = ac_ShipMethodGroups.ShipMethodId"); selectQuery.Append(" WHERE StoreId = @storeId"); //PROCESS MINPURCHASE EXCLUSION selectQuery.Append(" AND MinPurchase <= @shipmentValue"); //PROCESS WAREHOUSE EXCLUSION selectQuery.Append(" AND (ac_ShipMethodWarehouses.WarehouseId IS NULL OR ac_ShipMethodWarehouses.WarehouseId = @warehouseId)"); //PROCESS SHIPZONE EXCLUSION selectQuery.Append(" AND (ac_ShipMethodShipZones.ShipZoneId IS NULL"); for (int i = 0; i < shipmentZoneCollection.Count; i++) { selectQuery.Append(" OR ac_ShipMethodShipZones.ShipZoneId = @shipZoneId" + i.ToString()); } selectQuery.Append(")"); //PROCESS GROUP EXCLUSION selectQuery.Append(" AND (ac_ShipMethodGroups.GroupId IS NULL"); User user = UserDataSource.LoadForShipment(shipment); if (user != null) { for (int i = 0; i < user.UserGroups.Count; i++) { selectQuery.Append(" OR ac_ShipMethodGroups.GroupId = @groupId" + i.ToString()); } } selectQuery.Append(")"); //ORDER ACCORDING TO MERCHANT RULES //selectQuery.Append(" ORDER BY ac_ShipMethods.OrderBy"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); //ADD IN MINPURCHASE PARAMETER database.AddInParameter(selectCommand, "@shipmentValue", System.Data.DbType.Decimal, shipment.GetItems().TotalProductPrice()); //ADD IN WAREHOUSE PARAMETER database.AddInParameter(selectCommand, "@warehouseId", System.Data.DbType.Int32, shipment.WarehouseId); //ADD IN NUMBERED ZONE PARAMETERS for (int i = 0; i < shipmentZoneCollection.Count; i++) { database.AddInParameter(selectCommand, "@shipZoneId" + i.ToString(), System.Data.DbType.Int32, shipmentZoneCollection[i].ShipZoneId); } //ADD IN NUMBERED GROUP PARAMETERS for (int i = 0; i < user.UserGroups.Count; i++) { database.AddInParameter(selectCommand, "@groupId" + i.ToString(), System.Data.DbType.Int32, user.UserGroups[i].GroupId); } //EXECUTE THE COMMAND using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { ShipMethod shipMethod = new ShipMethod(); ShipMethod.LoadDataReader(shipMethod, dr); shipMethodCollection.Add(shipMethod); } dr.Close(); } //SORT THE ITEMS (NOT DONE IN QUERY BECAUSE OF DISTINCT CLAUSE) shipMethodCollection.Sort("OrderBy"); return(shipMethodCollection); }