예제 #1
0
        /// <summary>
        /// Processes the specified commerce context.
        /// </summary>
        /// <param name="commerceContext">The commerce context.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public virtual async Task <FulfillmentFeeBook> Process(CommerceContext commerceContext, string name = "")
        {
            using (var activity = CommandActivity.Start(commerceContext, this))
            {
                var FulfillmentFeeBookName = commerceContext.GetPolicy <GlobalPolicy>().GetFulfillmentFeeBookName(name, commerceContext);
                var cachePolicy            = commerceContext.GetPolicy <FulfillmentFeeCachePolicy>();
                var cacheKey = string.Format("{0}{1}", commerceContext.CurrentLanguage(), FulfillmentFeeBookName);

                ICache             cache = null;
                FulfillmentFeeBook FulfillmentFeeBook = null;

                if (cachePolicy.AllowCaching)
                {
                    var environmentCacheArgument = new EnvironmentCacheArgument {
                        CacheName = cachePolicy.CacheName
                    };
                    cache = await _cachePipeline.Run(environmentCacheArgument, commerceContext.GetPipelineContextOptions());

                    FulfillmentFeeBook = await cache.Get(cacheKey) as FulfillmentFeeBook;
                }

                if (FulfillmentFeeBook == null)
                {
                    FulfillmentFeeBook = await this.GetFulfillmentFeeBook(commerceContext, FulfillmentFeeBookName);

                    if (cachePolicy.AllowCaching && cache != null)
                    {
                        await cache.Set(cacheKey, new Cachable <FulfillmentFeeBook>(FulfillmentFeeBook, 1L), cachePolicy.GetCacheEntryOptions());
                    }
                }

                return(FulfillmentFeeBook);
            }
        }
 private FulfillmentFee GetFulfillmentFeeDefault(FulfillmentFeeBook fulfillmentFeeBook, string currency, string fulfillmentMethodName)
 {
     return(fulfillmentFeeBook.FulfillmentFees.Where(item =>
                                                     item.FulfillmentMethodName.Equals(fulfillmentMethodName, StringComparison.OrdinalIgnoreCase) &&
                                                     item.Fee.CurrencyCode.Equals(currency, StringComparison.OrdinalIgnoreCase) &&
                                                     item.IsDefault.Equals(true))
            .FirstOrDefault());
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SaveFulfillmentFeeBookArgument"/> class.
        /// </summary>
        /// <param name="FulfillmentFeeBook">The Fulfillment fee book.</param>
        /// <param name="name">The name.</param>
        /// <param name="FulfillmentFees">The Fulfillment fees.</param>
        public SaveFulfillmentFeeBookArgument(FulfillmentFeeBook FulfillmentFeeBook, string name, IList <FulfillmentFee> FulfillmentFees)
            : base(FulfillmentFeeBook)
        {
            Condition.Requires(name).IsNotNull("The Fulfillment fee book name can not be null or empty");
            this.Name = name;

            Condition.Requires(FulfillmentFees).IsNotNull("The Fulfillment fee book fees collection can not be null or empty");
            this.FulfillmentFees = FulfillmentFees;
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FulfillmentFeeBookArgument"/> class.
 /// </summary>
 /// <param name="FulfillmentFeeBook">The Fulfillment fee book.</param>
 public FulfillmentFeeBookArgument(FulfillmentFeeBook FulfillmentFeeBook)
 {
     this.FulfillmentFeeBook = FulfillmentFeeBook;
 }
        private FulfillmentFee GetFulfillmentFee(CommercePipelineExecutionContext context, FulfillmentFeeBook fulfillmentFeeBook, string currency, string fulfillmentMethodName, string fulfillmentTypeName)
        {
            FulfillmentFee fulfillmentFee = null;

            if (string.IsNullOrEmpty(fulfillmentMethodName))
            {
                fulfillmentFee = GetFulfillmentFeeDefault(fulfillmentFeeBook, currency, fulfillmentMethodName);
                context.Logger.LogDebug($"Default fee found for fulfillment method '{fulfillmentMethodName}', fulfillment type '{fulfillmentTypeName}' and currency code '{currency}'.");
            }
            else
            {
                fulfillmentFee = GetFulfillmentFeeByType(fulfillmentFeeBook, currency, fulfillmentMethodName, fulfillmentTypeName);
                context.Logger.LogDebug($"Specific fee found for fulfillment method '{fulfillmentMethodName}', fulfillment type '{fulfillmentTypeName}' and currency code '{currency}'.");
            }

            return(fulfillmentFee);
        }