Пример #1
0
        public async Task <ActionResult <webModel.PromotionReward[]> > EvaluatePromotions([FromBody] PromotionEvaluationContext context)
        {
            var promotionResult = await _promoEvaluator.EvaluatePromotionAsync(context);

            //This dynamic casting is used here for duck-type casting class hierarchy into flat type
            //because OpenAPI and code generation like AutoRest tools don't work with inheritances
            var result = promotionResult.Rewards.Select(x => (dynamic)x).ToArray();

            return(Ok(result));
        }
Пример #2
0
        public virtual async Task Run(SearchProductResponse parameter, Func <SearchProductResponse, Task> next)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            var query = parameter.Query;

            if (query == null)
            {
                throw new OperationCanceledException("Query must be set");
            }

            var responseGroup = EnumUtility.SafeParse(query.GetResponseGroup(), ExpProductResponseGroup.None);

            // If promotion evaluation requested
            if (responseGroup.HasFlag(ExpProductResponseGroup.LoadPrices))
            {
                var promoEvalContext = new PromotionEvaluationContext
                {
                    Currency   = query.CurrencyCode,
                    StoreId    = query.StoreId,
                    Language   = query.CultureName,
                    CustomerId = query.UserId
                };
                await _pipeline.Execute(promoEvalContext);

                //Evaluate promotions
                promoEvalContext.PromoEntries = parameter.Results.Select(x => _mapper.Map <ProductPromoEntry>(x, options =>
                {
                    options.Items["all_currencies"] = parameter.AllStoreCurrencies;
                    options.Items["currency"]       = parameter.Currency;
                })).ToList();

                var promotionResults = await _marketingEvaluator.EvaluatePromotionAsync(promoEvalContext);

                var promoRewards = promotionResults.Rewards.OfType <CatalogItemAmountReward>().ToArray();
                if (promoRewards.Any())
                {
                    parameter.Results.Apply(x => x.ApplyRewards(promoRewards));
                }
            }
            await next(parameter);
        }
 public virtual async Task <PromotionResult> EvaluatePromotionsAsync(PromotionEvaluationContext evalContext)
 {
     return(await _marketingEvaluator.EvaluatePromotionAsync(evalContext));
 }
        public async Task <ActionResult <PromotionReward[]> > EvaluatePromotions([FromBody] PromotionEvaluationContext context)
        {
            var retVal = await _promoEvaluator.EvaluatePromotionAsync(context);

            return(Ok(retVal.Rewards));
        }
 public void EvaluateStackable()
 {
     _stackablePolicy.EvaluatePromotionAsync(pCtx);
 }
 public void EvaluateBestReward()
 {
     _bestRewardPolicy.EvaluatePromotionAsync(pCtx);
 }