/// <summary> /// Initializes a new instance of the <see cref="DefaultShipmentRateQuoteStrategy"/> class. /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethods"> /// The shipping gateway methods. /// </param> /// <param name="runtimeCache"> /// The runtime cache. /// </param> public DefaultShipmentRateQuoteStrategy( IShipment shipment, IShippingGatewayMethod[] shippingGatewayMethods, IRuntimeCacheProvider runtimeCache) : base(shipment, shippingGatewayMethods, runtimeCache) { }
/// <summary> /// Creates a cache key for caching <see cref="IShipmentRateQuote"/>s /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethod"> /// The shipping Gateway Method. /// </param> /// <returns> /// The cache key. /// </returns> protected static string GetShipmentRateQuoteCacheKey(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { var address = shipment.GetDestinationAddress(); var args = string.Format("{0}.{1}", address.Region.Replace(" ", string.Empty), address.CountryCode); return(Cache.CacheKeys.ShippingGatewayProviderShippingRateQuoteCacheKey(shipment.Key, shippingGatewayMethod.ShipMethod.Key, shipment.VersionKey, args)); }
/// <summary> /// The save shipping gateway method. /// </summary> /// <param name="shippingGatewayMethod"> /// The shipping gateway method. /// </param> public override void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { GatewayProviderService.Save(shippingGatewayMethod.ShipMethod); // I will be to moving SaveShippingGatewayMethod to the base class and make it virtual to handle // this for people, but it will not be a breaking change so no worries. base.ShipMethods = null; }
/// <summary> /// Initializes a new instance of the <see cref="ShipmentRateQuoteStrategyBase"/> class. /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethods"> /// The shipping gateway methods. /// </param> /// <param name="runtimeCache"> /// The runtime cache. /// </param> protected ShipmentRateQuoteStrategyBase(IShipment shipment, IShippingGatewayMethod[] shippingGatewayMethods, IRuntimeCacheProvider runtimeCache) { Mandate.ParameterNotNull(shipment, "shipment"); Mandate.ParameterNotNull(shippingGatewayMethods, "gatewayShipMethods"); Mandate.ParameterNotNull(runtimeCache, "runtimeCache"); _shipment = shipment; _shippingGatewayMethods = shippingGatewayMethods; _runtimeCache = runtimeCache; }
/// <summary> /// Deletes an Active ShipMethod /// </summary> /// <param name="shippingGatewayMethod">The shipping gateway method</param> public virtual void DeleteShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { GatewayProviderService.Delete(shippingGatewayMethod.ShipMethod); _shipMethods = null; }
/// <summary> /// Maps a <see cref="ShippingGatewayMethodBase"/> to <see cref="ShippingGatewayMethodDisplay"/>. /// </summary> /// <param name="method"> /// The method. /// </param> /// <returns> /// The <see cref="ShippingGatewayMethodDisplay"/>. /// </returns> internal static ShippingGatewayMethodDisplay ToShippingGatewayMethodDisplay(this IShippingGatewayMethod method) { return(AutoMapper.Mapper.Map <ShippingGatewayMethodDisplay>(method)); }
/// <summary> /// Quotes a single GatewayShipMethod for a shipment rate /// </summary> /// <param name="shipment">The <see cref="IShipment"/> used to generate the rate quote</param> /// <param name="shippingGatewayMethod">The <see cref="IShippingGatewayMethod"/> used to generate the rate quote</param> /// <returns>The <see cref="IShipmentRateQuote"/></returns> public virtual IShipmentRateQuote QuoteShipMethodForShipment(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { var ctrValues = new object[] { shipment, new[] { shippingGatewayMethod }, RuntimeCache }; var typeName = MerchelloConfiguration.Current.GetStrategyElement(Constants.StrategyTypeAlias.DefaultShipmentRateQuote).Type; var attempt = ActivatorHelper.CreateInstance<ShipmentRateQuoteStrategyBase>(typeName, ctrValues); if (!attempt.Success) { LogHelper.Error<ShippingGatewayProviderBase>("Failed to instantiate strategy " + typeName, attempt.Exception); throw attempt.Exception; } return QuoteShippingGatewayMethodsForShipment(attempt.Result).FirstOrDefault(); }
/// <summary> /// Saves a shipmethod /// </summary> /// <param name="shippingGatewayMethod">The <see cref="IShippingGatewayMethod"/> to be saved</param> public abstract void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod);
/// <summary> /// Saves a <see cref="FedExShippingGatewayMethod"/> /// </summary> /// <param name="shippingGatewayMethod"></param> public override void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { GatewayProviderService.Save(shippingGatewayMethod.ShipMethod); }
/// <summary> /// Saves a <see cref="FixedRateShippingGatewayMethod"/> /// </summary> /// <param name="shippingGatewayMethod"></param> public override void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { GatewayProviderService.Save(shippingGatewayMethod.ShipMethod); ShippingFixedRateTable.Save(GatewayProviderService, RuntimeCache, ((FixedRateShippingGatewayMethod)shippingGatewayMethod).RateTable); }
public override void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { throw new System.NotImplementedException(); }
/// <summary> /// Returns the cached <see cref="IShipmentRateQuote"/> if it exists /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethod"> /// The shipping Gateway Method. /// </param> /// <returns> /// The <see cref="IShipmentRateQuote"/>. /// </returns> protected IShipmentRateQuote TryGetCachedShipmentRateQuote(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { return(_runtimeCache.GetCacheItem(GetShipmentRateQuoteCacheKey(shipment, shippingGatewayMethod)) as ShipmentRateQuote); }
/// <summary> /// Returns the cached <see cref="IShipmentRateQuote"/> if it exists /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethod"> /// The shipping Gateway Method. /// </param> /// <returns> /// The <see cref="IShipmentRateQuote"/>. /// </returns> protected IShipmentRateQuote TryGetCachedShipmentRateQuote(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { return _runtimeCache.GetCacheItem(GetShipmentRateQuoteCacheKey(shipment, shippingGatewayMethod)) as ShipmentRateQuote; }
/// <summary> /// Creates a cache key for caching <see cref="IShipmentRateQuote"/>s /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethod"> /// The shipping Gateway Method. /// </param> /// <returns> /// The cache key. /// </returns> protected static string GetShipmentRateQuoteCacheKey(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { var address = shipment.GetDestinationAddress(); var args = address.Region.IsNullOrWhiteSpace() ? address.CountryCode : string.Format("{0}.{1}", address.Region.Replace(" ", string.Empty), address.CountryCode); return Cache.CacheKeys.ShippingGatewayProviderShippingRateQuoteCacheKey(shipment.Key, shippingGatewayMethod.ShipMethod.Key, shipment.VersionKey, args); }
/// <summary> /// Creates a cache key for caching <see cref="IShipmentRateQuote"/>s /// </summary> /// <param name="shipment"></param> /// <param name="shippingGatewayMethod"></param> /// <returns></returns> protected static string GetShipmentRateQuoteCacheKey(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { return Cache.CacheKeys.ShippingGatewayProviderShippingRateQuoteCacheKey(shipment.Key, shippingGatewayMethod.ShipMethod.Key, shipment.VersionKey); }
/// <summary> /// Creates a cache key for caching <see cref="IShipmentRateQuote"/>s /// </summary> /// <param name="shipment"> /// The shipment. /// </param> /// <param name="shippingGatewayMethod"> /// The shipping Gateway Method. /// </param> /// <returns> /// The cache key. /// </returns> protected static string GetShipmentRateQuoteCacheKey(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { return(Cache.CacheKeys.ShippingGatewayProviderShippingRateQuoteCacheKey(shipment.Key, shippingGatewayMethod.ShipMethod.Key, shipment.VersionKey)); }
/// <summary> /// Saves a <see cref="FixedRateShippingGatewayMethod"/> /// </summary> /// <param name="shippingGatewayMethod">The <see cref="IShippingGatewayMethod"/> to be saved</param> public override void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { GatewayProviderService.Save(shippingGatewayMethod.ShipMethod); ShippingFixedRateTable.Save(GatewayProviderService, RuntimeCache, ((FixedRateShippingGatewayMethod) shippingGatewayMethod).RateTable); }
/// <summary> /// Quotes a single GatewayShipMethod for a shipment rate /// </summary> /// <param name="shipment">The <see cref="IShipment"/> used to generate the rate quote</param> /// <param name="shippingGatewayMethod">The <see cref="IShippingGatewayMethod"/> used to generate the rate quote</param> /// <returns>The <see cref="IShipmentRateQuote"/></returns> public virtual IShipmentRateQuote QuoteShipMethodForShipment(IShipment shipment, IShippingGatewayMethod shippingGatewayMethod) { var ctrValues = new object[] { shipment, new[] { shippingGatewayMethod }, RuntimeCache }; var typeName = MerchelloConfiguration.Current.GetStrategyElement(Constants.StrategyTypeAlias.DefaultShipmentRateQuote).Type; var attempt = ActivatorHelper.CreateInstance <ShipmentRateQuoteStrategyBase>(typeName, ctrValues); if (!attempt.Success) { LogHelper.Error <ShippingGatewayProviderBase>("Failed to instantiate strategy " + typeName, attempt.Exception); throw attempt.Exception; } return(QuoteShippingGatewayMethodsForShipment(attempt.Result).FirstOrDefault()); }
public override void SaveShippingGatewayMethod(IShippingGatewayMethod shippingGatewayMethod) { GatewayProviderService.Save(shippingGatewayMethod.ShipMethod); }