예제 #1
0
        /// <summary>
        /// Gets a collection of ship rate quotes for the given shipment
        /// </summary>
        /// <param name="shipment">The basket shipment for which to get the rate quotes</param>
        /// <returns>A collection of ship rate quotes</returns>
        public static Collection <ShipRateQuote> QuoteForShipment(IShipment shipment)
        {
            Collection <ShipRateQuote> rateQuotes = new Collection <ShipRateQuote>();
            //GET ALL OF THE POSSIBLE SHIPMETHODS
            ShipMethodCollection shipMethods = ShipMethodDataSource.LoadForShipment(shipment);

            foreach (ShipMethod method in shipMethods)
            {
                ShipRateQuote quote = method.GetShipRateQuote(shipment);
                if (quote != null)
                {
                    rateQuotes.Add(quote);
                }
            }
            return(rateQuotes);
        }
예제 #2
0
        /// <summary>
        /// Gets an array of ship rate quotes for the given basket
        /// </summary>
        /// <param name="basket">The basket for which to get the ship rate quotes</param>
        /// <param name="destination">The destination address for which to get the rates</param>
        /// <returns>An array of ShipRateQuote objects</returns>
        public static ShipRateQuote[] QuoteForBasket(Basket basket, Address destination)
        {
            //*******
            //SUMMARY: LOOP ALL SHIPMENTS IN BASKET AND GET QUOTES FOR EACH
            //ADD QUOTES TOGETHER FOR SERVICES IN COMMON TO ALL SHIPMENTS AND RETURN TOTALS
            //*******
            //CREATE A DICTIONARY TO HOLD QUOTED RATES
            Dictionary <int, ShipRateQuoteStack> rateQuotes = new Dictionary <int, ShipRateQuoteStack>();

            foreach (BasketShipment shipment in basket.Shipments)
            {
                //GET ALL OF THE POSSIBLE SHIPMETHODS
                Address tempAddress = shipment.Address;
                shipment.SetAddress(destination);
                ShipMethodCollection shipMethods = ShipMethodDataSource.LoadForShipment(shipment);
                foreach (ShipMethod method in shipMethods)
                {
                    ShipRateQuote quote = method.GetShipRateQuote(shipment);
                    if (quote != null)
                    {
                        if (rateQuotes.ContainsKey(method.ShipMethodId))
                        {
                            rateQuotes[method.ShipMethodId].Add(quote);
                        }
                        else
                        {
                            rateQuotes.Add(method.ShipMethodId, new ShipRateQuoteStack(quote));
                        }
                    }
                }
                shipment.SetAddress(tempAddress);
            }
            //NOW BUILD LIST OF QUOTES VALID FOR ALL SHIPMENTS
            List <ShipRateQuote> validQuotes = new List <ShipRateQuote>();

            foreach (ShipRateQuoteStack item in rateQuotes.Values)
            {
                if (item.ShipmentCount == basket.Shipments.Count)
                {
                    validQuotes.Add(item.ShipRateQuote);
                }
            }
            return(validQuotes.ToArray());
        }
 public static ShipMethod Load(Int32 shipMethodId)
 {
     return(ShipMethodDataSource.Load(shipMethodId, true));
 }
 public static ShipMethodCollection LoadForWarehouse(Int32 warehouseId, int maximumRows, int startRowIndex)
 {
     return(ShipMethodDataSource.LoadForWarehouse(warehouseId, maximumRows, startRowIndex, string.Empty));
 }
 public static ShipMethodCollection LoadForWarehouse(Int32 warehouseId, string sortExpression)
 {
     return(ShipMethodDataSource.LoadForWarehouse(warehouseId, 0, 0, sortExpression));
 }
 public static ShipMethodCollection LoadForWarehouse(Int32 warehouseId)
 {
     return(ShipMethodDataSource.LoadForWarehouse(warehouseId, 0, 0, string.Empty));
 }
 public static ShipMethodCollection LoadForShipZone(Int32 shipZoneId, int maximumRows, int startRowIndex)
 {
     return(ShipMethodDataSource.LoadForShipZone(shipZoneId, maximumRows, startRowIndex, string.Empty));
 }
 public static ShipMethodCollection LoadForShipZone(Int32 shipZoneId, string sortExpression)
 {
     return(ShipMethodDataSource.LoadForShipZone(shipZoneId, 0, 0, sortExpression));
 }
 public static ShipMethodCollection LoadForShipZone(Int32 shipZoneId)
 {
     return(ShipMethodDataSource.LoadForShipZone(shipZoneId, 0, 0, string.Empty));
 }
 public static ShipMethodCollection LoadForGroup(Int32 groupId, int maximumRows, int startRowIndex)
 {
     return(ShipMethodDataSource.LoadForGroup(groupId, maximumRows, startRowIndex, string.Empty));
 }
 public static ShipMethodCollection LoadForGroup(Int32 groupId, string sortExpression)
 {
     return(ShipMethodDataSource.LoadForGroup(groupId, 0, 0, sortExpression));
 }
 public static ShipMethodCollection LoadForGroup(Int32 groupId)
 {
     return(ShipMethodDataSource.LoadForGroup(groupId, 0, 0, string.Empty));
 }
 public static ShipMethodCollection LoadForCoupon(Int32 couponId, string sortExpression)
 {
     return(ShipMethodDataSource.LoadForCoupon(couponId, 0, 0, sortExpression));
 }
 public static ShipMethodCollection LoadForCoupon(Int32 couponId)
 {
     return(ShipMethodDataSource.LoadForCoupon(couponId, 0, 0, string.Empty));
 }
예제 #15
0
        /// <summary>
        /// Saves this ShipMethod object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        public virtual SaveResult Save()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

                //SET EMPTY STOREID TO CURRENT CONTEXT
                if (this.StoreId == 0)
                {
                    this.StoreId = Token.Instance.StoreId;
                }
                if (this.ShipMethodId == 0)
                {
                    recordExists = false;
                }

                if (this.OrderBy < 0)
                {
                    this.OrderBy = ShipMethodDataSource.GetNextOrderBy();
                }

                if (recordExists)
                {
                    //verify whether record is already present
                    StringBuilder selectQuery = new StringBuilder();
                    selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_ShipMethods");
                    selectQuery.Append(" WHERE ShipMethodId = @ShipMethodId");
                    using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()))
                    {
                        database.AddInParameter(selectCommand, "@ShipMethodId", System.Data.DbType.Int32, this.ShipMethodId);
                        if ((int)database.ExecuteScalar(selectCommand) == 0)
                        {
                            recordExists = false;
                        }
                    }
                }

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_ShipMethods SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", ShipMethodTypeId = @ShipMethodTypeId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", Surcharge = @Surcharge");
                    updateQuery.Append(", ShipGatewayId = @ShipGatewayId");
                    updateQuery.Append(", ServiceCode = @ServiceCode");
                    updateQuery.Append(", MinPurchase = @MinPurchase");
                    updateQuery.Append(", SurchargeIsVisible = @SurchargeIsVisible");
                    updateQuery.Append(", SurchargeIsPercent = @SurchargeIsPercent");
                    updateQuery.Append(", TaxCodeId = @TaxCodeId");
                    updateQuery.Append(", SurchargeTaxCodeId = @SurchargeTaxCodeId");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE ShipMethodId = @ShipMethodId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@ShipMethodId", System.Data.DbType.Int32, this.ShipMethodId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@ShipMethodTypeId", System.Data.DbType.Int16, this.ShipMethodTypeId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@Surcharge", System.Data.DbType.Decimal, this.Surcharge);
                        database.AddInParameter(updateCommand, "@ShipGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.ShipGatewayId));
                        database.AddInParameter(updateCommand, "@ServiceCode", System.Data.DbType.String, NullableData.DbNullify(this.ServiceCode));
                        database.AddInParameter(updateCommand, "@MinPurchase", System.Data.DbType.Decimal, this.MinPurchase);
                        database.AddInParameter(updateCommand, "@SurchargeIsVisible", System.Data.DbType.Boolean, this.SurchargeIsVisible);
                        database.AddInParameter(updateCommand, "@SurchargeIsPercent", System.Data.DbType.Boolean, NullableData.DbNullify(this.SurchargeIsPercent));
                        database.AddInParameter(updateCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(updateCommand, "@SurchargeTaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.SurchargeTaxCodeId));
                        database.AddInParameter(updateCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_ShipMethods (StoreId, ShipMethodTypeId, Name, Surcharge, ShipGatewayId, ServiceCode, MinPurchase, SurchargeIsVisible, SurchargeIsPercent, TaxCodeId, SurchargeTaxCodeId, OrderBy)");
                    insertQuery.Append(" VALUES (@StoreId, @ShipMethodTypeId, @Name, @Surcharge, @ShipGatewayId, @ServiceCode, @MinPurchase, @SurchargeIsVisible, @SurchargeIsPercent, @TaxCodeId, @SurchargeTaxCodeId, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@ShipMethodId", System.Data.DbType.Int32, this.ShipMethodId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@ShipMethodTypeId", System.Data.DbType.Int16, this.ShipMethodTypeId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@Surcharge", System.Data.DbType.Decimal, this.Surcharge);
                        database.AddInParameter(insertCommand, "@ShipGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.ShipGatewayId));
                        database.AddInParameter(insertCommand, "@ServiceCode", System.Data.DbType.String, NullableData.DbNullify(this.ServiceCode));
                        database.AddInParameter(insertCommand, "@MinPurchase", System.Data.DbType.Decimal, this.MinPurchase);
                        database.AddInParameter(insertCommand, "@SurchargeIsVisible", System.Data.DbType.Boolean, this.SurchargeIsVisible);
                        database.AddInParameter(insertCommand, "@SurchargeIsPercent", System.Data.DbType.Boolean, NullableData.DbNullify(this.SurchargeIsPercent));
                        database.AddInParameter(insertCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(insertCommand, "@SurchargeTaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.SurchargeTaxCodeId));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result             = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._ShipMethodId = result;
                    }
                }
                this.SaveChildren();

                //OBJECT IS DIRTY IF NO RECORDS WERE UPDATED OR INSERTED
                this.IsDirty = (result == 0);
                if (this.IsDirty)
                {
                    return(SaveResult.Failed);
                }
                else
                {
                    return(recordExists ? SaveResult.RecordUpdated : SaveResult.RecordInserted);
                }
            }

            //SAVE IS SUCCESSFUL IF OBJECT IS NOT DIRTY
            return(SaveResult.NotDirty);
        }