示例#1
0
 public FixedRateShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IShippingFixedRateTable rateTable)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     RateTable  = new ShippingFixedRateTable(shipMethod.Key);
     _quoteType = GatewayResource.ServiceCode == FixedRateShippingGatewayProvider.VaryByWeightPrefix ? QuoteType.VaryByWeight : QuoteType.VaryByPrice;
     RateTable  = rateTable;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedRateShippingGatewayMethod"/> class.
 /// </summary>
 /// <param name="gatewayResource">
 /// The gateway resource.
 /// </param>
 /// <param name="shipMethod">
 /// The ship method.
 /// </param>
 /// <param name="shipCountry">
 /// The ship country.
 /// </param>
 /// <param name="rateTable">
 /// The rate table.
 /// </param>
 public FixedRateShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IShippingFixedRateTable rateTable)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     RateTable = new ShippingFixedRateTable(shipMethod.Key);
     _quoteType = GatewayResource.ServiceCode == FixedRateShippingGatewayProvider.VaryByWeightPrefix ? QuoteType.VaryByWeight : QuoteType.VaryByPrice;
     RateTable = rateTable;
 }
        /// <summary>
        /// Maps changes made in the <see cref="ShipFixedRateTableDisplay"/> to the <see cref="IShippingFixedRateTable"/>
        /// </summary>
        /// <param name="shipFixedRateTableDisplay">The <see cref="ShipFixedRateTableDisplay"/> to map</param>
        /// <param name="destination">The <see cref="IShippingFixedRateTable"/> to have changes mapped to</param>
        /// <returns>The updated <see cref="IShippingFixedRateTable"/></returns>
        /// <remarks>
        /// 
        /// Note: after calling this mapping, the changes are still not persisted to the database as the .Save() method is not called.
        /// 
        /// * For testing you will have to use the static .Save(IGatewayProviderService ..., as MerchelloContext.Current will likely be null
        /// 
        /// </remarks>
        internal static IShippingFixedRateTable ToShipRateTable(this ShipFixedRateTableDisplay shipFixedRateTableDisplay, IShippingFixedRateTable destination)
        {
            // determine if any rows were deleted
            var missingRows =
                destination.Rows.Where(
                    persisted => !shipFixedRateTableDisplay.Rows.Select(display => display.Key).Where(x => x != Guid.Empty).Contains(persisted.Key));

            foreach (var missing in missingRows)
            {
                destination.DeleteRow(missing);
            }

            foreach (var shipRateTierDisplay in shipFixedRateTableDisplay.Rows)
            {

                // try to find the matching row
                var destinationTier = destination.Rows.FirstOrDefault(x => x.Key == shipRateTierDisplay.Key);

                if (destinationTier != null)
                {
                    // update the tier information : note we can only update the Rate here!
                    // We need to remove the text boxes for the RangeLow and RangeHigh on any existing FixedRateTable
                    destinationTier.Rate = shipRateTierDisplay.Rate;
                }
                else
                {
                    // this should be implemented in V1
                    destination.AddRow(shipRateTierDisplay.RangeLow, shipRateTierDisplay.RangeHigh, shipRateTierDisplay.Rate);
                }

                //IShipRateTier destinationShipRateTier;

                //var matchingItems = destination.Rows.Where(x => x.Key == shipRateTierDisplay.Key).ToArray();
                //if (matchingItems.Any())
                //{
                //    var existingshipRateTier = matchingItems.First();
                //    if (existingshipRateTier != null)
                //    {
                //        destinationShipRateTier = existingshipRateTier;

                //        destinationShipRateTier = shipRateTierDisplay.ToShipRateTier(destinationShipRateTier);
                //    }
                //}
                //else
                //{
                //    // Case if one was created in the back-office.  Not planned for v1
                //    destination.AddRow(shipRateTierDisplay.RangeLow, shipRateTierDisplay.RangeHigh, shipRateTierDisplay.Rate);
                //}
            }

            return destination;
        }
        /// <summary>
        /// Maps changes made in the <see cref="ShipFixedRateTableDisplay"/> to the <see cref="IShippingFixedRateTable"/>
        /// </summary>
        /// <param name="shipFixedRateTableDisplay">The <see cref="ShipFixedRateTableDisplay"/> to map</param>
        /// <param name="destination">The <see cref="IShippingFixedRateTable"/> to have changes mapped to</param>
        /// <returns>The updated <see cref="IShippingFixedRateTable"/></returns>
        /// <remarks>
        ///
        /// Note: after calling this mapping, the changes are still not persisted to the database as the .Save() method is not called.
        ///
        /// * For testing you will have to use the static .Save(IGatewayProviderService ..., as MerchelloContext.Current will likely be null
        ///
        /// </remarks>
        internal static IShippingFixedRateTable ToShipRateTable(this ShipFixedRateTableDisplay shipFixedRateTableDisplay, IShippingFixedRateTable destination)
        {
            // determine if any rows were deleted
            var missingRows =
                destination.Rows.Where(
                    persisted => !shipFixedRateTableDisplay.Rows.Select(display => display.Key).Where(x => x != Guid.Empty).Contains(persisted.Key));

            foreach (var missing in missingRows)
            {
                destination.DeleteRow(missing);
            }

            foreach (var shipRateTierDisplay in shipFixedRateTableDisplay.Rows)
            {
                // try to find the matching row
                var destinationTier = destination.Rows.FirstOrDefault(x => x.Key == shipRateTierDisplay.Key);

                if (destinationTier != null)
                {
                    // update the tier information : note we can only update the Rate here!
                    // We need to remove the text boxes for the RangeLow and RangeHigh on any existing FixedRateTable
                    destinationTier.Rate = shipRateTierDisplay.Rate;
                }
                else
                {
                    // this should be implemented in V1
                    destination.AddRow(shipRateTierDisplay.RangeLow, shipRateTierDisplay.RangeHigh, shipRateTierDisplay.Rate);
                }

                //IShipRateTier destinationShipRateTier;

                //var matchingItems = destination.Rows.Where(x => x.Key == shipRateTierDisplay.Key).ToArray();
                //if (matchingItems.Any())
                //{
                //    var existingshipRateTier = matchingItems.First();
                //    if (existingshipRateTier != null)
                //    {
                //        destinationShipRateTier = existingshipRateTier;

                //        destinationShipRateTier = shipRateTierDisplay.ToShipRateTier(destinationShipRateTier);
                //    }
                //}
                //else
                //{
                //    // Case if one was created in the back-office.  Not planned for v1
                //    destination.AddRow(shipRateTierDisplay.RangeLow, shipRateTierDisplay.RangeHigh, shipRateTierDisplay.Rate);
                //}
            }

            return(destination);
        }
 internal static ShipFixedRateTableDisplay ToShipFixedRateTableDisplay(this IShippingFixedRateTable shippingFixedRateTable)
 {
     return(AutoMapper.Mapper.Map <ShipFixedRateTableDisplay>(shippingFixedRateTable));
 }
示例#6
0
        /// <summary>
        /// The delete row.
        /// </summary>
        /// <param name="gatewayProviderService">
        /// The gateway provider service.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        /// <param name="rateTable">
        /// The rate table.
        /// </param>
        /// <param name="shipRateTier">
        /// The ship rate tier.
        /// </param>
        internal static void DeleteRow(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider cache, IShippingFixedRateTable rateTable, IShipRateTier shipRateTier)
        {
            var row = rateTable.Rows.FirstOrDefault(x => x.Key == shipRateTier.Key);

            if (!rateTable.Rows.Any() || row == null)
            {
                return;
            }

            if (rateTable.Rows.IndexOf(rateTable.Rows.Last()) != rateTable.Rows.IndexOf(row))
            {
                rateTable.Rows.First(x => x.RangeLow == row.RangeHigh).RangeLow = row.RangeLow;
            }

            // clear the current cached item
            // TODO : This should use the distributed cache referesher
            cache.ClearCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey));

            gatewayProviderService.Save(rateTable.Rows);
            gatewayProviderService.Delete(shipRateTier);

            cache.GetCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey), () => rateTable, TimeSpan.FromHours(6));
        }
示例#7
0
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="gatewayProviderService">
        /// The gateway provider service.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        /// <param name="rateTable">
        /// The rate table.
        /// </param>
        internal static void Save(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider cache, IShippingFixedRateTable rateTable)
        {
            // clear the current cached item
            // TODO : This should use the distributed cache referesher
            cache.ClearCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey));

            // persist and enter into cache
            gatewayProviderService.Save(rateTable.Rows);
            cache.GetCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey), () => rateTable, TimeSpan.FromHours(6));
        }
        /// <summary>
        /// The delete row.
        /// </summary>
        /// <param name="gatewayProviderService">
        /// The gateway provider service.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        /// <param name="rateTable">
        /// The rate table.
        /// </param>
        /// <param name="shipRateTier">
        /// The ship rate tier.
        /// </param>
        internal static void DeleteRow(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider cache, IShippingFixedRateTable rateTable, IShipRateTier shipRateTier)
        {
            var row = rateTable.Rows.FirstOrDefault(x => x.Key == shipRateTier.Key);
            if (!rateTable.Rows.Any() || row == null) return;

            if (rateTable.Rows.IndexOf(rateTable.Rows.Last()) != rateTable.Rows.IndexOf(row))
            {
                rateTable.Rows.First(x => x.RangeLow == row.RangeHigh).RangeLow = row.RangeLow;
            }

            // clear the current cached item
            // TODO : This should use the distributed cache referesher
            cache.ClearCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey));

            gatewayProviderService.Save(rateTable.Rows);
            gatewayProviderService.Delete(shipRateTier);

            cache.GetCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey), () => rateTable);
        }  
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="gatewayProviderService">
        /// The gateway provider service.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        /// <param name="rateTable">
        /// The rate table.
        /// </param>
        internal static void Save(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider cache, IShippingFixedRateTable rateTable)
        {
            // clear the current cached item
            // TODO : This should use the distributed cache referesher
            cache.ClearCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey));

            // persist and enter into cache
            gatewayProviderService.Save(rateTable.Rows);
            cache.GetCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey), () => rateTable);
        }