private ICartBuilder GetCartBuilder() { var catalogApi = GetCatalogApiClient(); var cartApi = GetCartApiClient(); var marketingApi = GetMarketingApiClient(); var inventoryApi = GetInventoryApiClient(); var pricingApi = GetPricingApiClient(); var customerApi = GetCustomerApiClient(); var orderApi = GetOrderApiClient(); var quoteApi = GetQuoteApiClient(); var storeApi = GetStoreApiClient(); var cacheManager = new Mock <ILocalCacheManager>().Object; var workContextFactory = new Func <WorkContext>(GetTestWorkContext); var promotionEvaluator = new PromotionEvaluator(marketingApi); var inventoryService = new Mock <IInventoryService>().Object; var pricingService = new PricingServiceImpl(pricingApi, GetTaxEvaluator(), promotionEvaluator, inventoryService); var customerService = new CustomerServiceImpl(workContextFactory, customerApi, orderApi, quoteApi, storeApi, GetSubscriptionModuleApiClient(), cacheManager); var catalogSearchService = new CatalogSearchServiceImpl(workContextFactory, catalogApi, inventoryApi, pricingService, customerService, GetSubscriptionModuleApiClient(), GetProductAvailabilityService(), inventoryService); var retVal = new CartBuilder(workContextFactory, cartApi, catalogSearchService, cacheManager, promotionEvaluator, GetTaxEvaluator(), GetSubscriptionModuleApiClient(), GetProductAvailabilityService()); return(retVal); }
private ICartBuilder GetCartBuilder() { var catalogApi = GetCatalogApiClient(); var cartApi = GetCartApiClient(); var marketingApi = GetMarketingApiClient(); var inventoryApi = GetInventoryApiClient(); var pricingApi = GetPricingApiClient(); var searchApi = GetSearchApiClient(); var customerApi = GetCustomerApiClient(); var orderApi = GetOrderApiClient(); var quoteApi = GetQuoteApiClient(); var storeApi = GetStoreApiClient(); var cacheManager = new Mock <ILocalCacheManager>().Object; var workContextFactory = new Func <WorkContext>(GetTestWorkContext); var promotionEvaluator = new PromotionEvaluator(marketingApi); var pricingService = new PricingServiceImpl(pricingApi, null, promotionEvaluator); var customerService = new CustomerServiceImpl(workContextFactory, customerApi, orderApi, quoteApi, storeApi, null, cacheManager); var catalogSearchService = new CatalogSearchServiceImpl(workContextFactory, catalogApi, inventoryApi, searchApi, pricingService, customerService, null); var retVal = new CartBuilder(workContextFactory, cartApi, catalogSearchService, cacheManager, promotionEvaluator, null, null); return(retVal); }
private IEnumerable <PromotionRecord> CalculateCartDiscounts() { var records = new List <PromotionRecord>(); foreach (var form in CurrentOrderGroup.OrderForms) { var set = GetPromotionEntrySetFromOrderForm(form); // create context var ctx = new Dictionary <string, object> { { PromotionEvaluationContext.TargetSet, set } }; var couponCode = CustomerSessionService.CustomerSession.CouponCode; //1. Prepare marketing context var evaluationContext = new PromotionEvaluationContext { ContextObject = ctx, CustomerId = CustomerSessionService.CustomerSession.CustomerId, CouponCode = CustomerSessionService.CustomerSession.CouponCode, PromotionType = PromotionType.CartPromotion, Currency = CustomerSessionService.CustomerSession.Currency, Store = CustomerSessionService.CustomerSession.StoreId, IsRegisteredUser = CustomerSessionService.CustomerSession.IsRegistered, IsFirstTimeBuyer = CustomerSessionService.CustomerSession.IsFirstTimeBuyer }; //2. Evaluate //var evaluator = new DefaultPromotionEvaluator(MarketingRepository, PromotionUsageProvider, new IEvaluationPolicy[] { new GlobalExclusivityPolicy(), new CartSubtotalRewardCombinePolicy(), new ShipmentRewardCombinePolicy() }, CacheRepository); var promotions = PromotionEvaluator.EvaluatePromotion(evaluationContext); var rewards = promotions.SelectMany(x => x.Rewards); //3. Generate warnings if (!string.IsNullOrEmpty(couponCode) && !promotions.Any(p => (p.CouponId != null && p.Coupon.Code == couponCode) || (p.CouponSetId != null && p.CouponSet.Coupons.Any(c => c.Code == couponCode)))) { RegisterWarning(WorkflowMessageCodes.COUPON_NOT_APPLIED, "Coupon doesn't exist or is not applied"); } records.AddRange(rewards.Select(reward => new PromotionRecord { AffectedEntriesSet = set, TargetEntriesSet = set, Reward = reward, PromotionType = PromotionType.CartPromotion })); } return(records.ToArray()); }
private ICatalogSearchService GetCatalogSearchService() { var apiClientConfiguration = new Client.Client.Configuration(GetApiClient()); var workContextFactory = new Func <WorkContext>(GetTestWorkContext); var catalogApi = new CatalogModuleApi(apiClientConfiguration); var pricingApi = new PricingModuleApi(apiClientConfiguration); var pricingService = new PricingServiceImpl(workContextFactory, pricingApi); var inventoryApi = new InventoryModuleApi(apiClientConfiguration); var searchApi = new SearchModuleApi(apiClientConfiguration); var marketingApi = new MarketingModuleApi(apiClientConfiguration); var promotionEvaluator = new PromotionEvaluator(marketingApi); return(new CatalogSearchServiceImpl(workContextFactory, catalogApi, pricingService, inventoryApi, searchApi, promotionEvaluator)); }
private IEnumerable <PromotionRecord> CalculateLineItemDiscounts() { var records = new List <PromotionRecord>(); foreach (var form in CurrentOrderGroup.OrderForms) { foreach (var lineItem in form.LineItems) { var set = new PromotionEntrySet(); var entry = GetPromotionEntryFromLineItem(lineItem); set.Entries.Add(entry); // create context var ctx = new Dictionary <string, object> { { PromotionEvaluationContext.TargetSet, set } }; //1. Prepare marketing context var evaluationContext = new PromotionEvaluationContext { ContextObject = ctx, CustomerId = CustomerSessionService.CustomerSession.CustomerId, CouponCode = CustomerSessionService.CustomerSession.CouponCode, Currency = CustomerSessionService.CustomerSession.Currency, PromotionType = PromotionType.CatalogPromotion, Store = CustomerSessionService.CustomerSession.StoreId, IsRegisteredUser = CustomerSessionService.CustomerSession.IsRegistered, IsFirstTimeBuyer = CustomerSessionService.CustomerSession.IsFirstTimeBuyer }; //2. Evaluate var promotions = PromotionEvaluator.EvaluatePromotion(evaluationContext); var rewards = promotions.SelectMany(x => x.Rewards); records.AddRange(rewards.Select(reward => new PromotionRecord { AffectedEntriesSet = set, TargetEntriesSet = set, Reward = reward, PromotionType = PromotionType.CatalogPromotion })); } } return(records.ToArray()); }
private ICatalogSearchService GetCatalogSearchService() { var catalogApi = GetCatalogApiClient(); var commerceApi = GetCoreApiClient(); var inventoryApi = GetInventoryApiClient(); var marketingApi = GetMarketingApiClient(); var pricingApi = GetPricingApiClient(); var searchApi = GetSearchApiClient(); var workContextFactory = new Func <WorkContext>(GetTestWorkContext); var pricingService = new PricingServiceImpl(workContextFactory, pricingApi, commerceApi); var promotionEvaluator = new PromotionEvaluator(marketingApi); var result = new CatalogSearchServiceImpl(workContextFactory, catalogApi, pricingService, inventoryApi, searchApi, promotionEvaluator); return(result); }
private ICartBuilder GetCartBuilder() { var apiClientCfg = new Client.Client.Configuration(GetApiClient()); var marketingApi = new MarketingModuleApi(apiClientCfg); var cartApi = new ShoppingCartModuleApi(apiClientCfg); var cacheManager = new Moq.Mock <ICacheManager <object> >(); var workContextFactory = new Func <WorkContext>(GetTestWorkContext); var promotionEvaluator = new PromotionEvaluator(marketingApi); var catalogModuleApi = new CatalogModuleApi(apiClientCfg); var pricingApi = new PricingModuleApi(apiClientCfg); var pricingService = new PricingServiceImpl(workContextFactory, pricingApi); var inventoryApi = new InventoryModuleApi(apiClientCfg); var searchApi = new SearchModuleApi(apiClientCfg); var catalogSearchService = new CatalogSearchServiceImpl(workContextFactory, catalogModuleApi, pricingService, inventoryApi, searchApi, promotionEvaluator); var retVal = new CartBuilder(cartApi, promotionEvaluator, catalogSearchService, cacheManager.Object); return(retVal); }
protected override void Execute(System.Activities.CodeActivityContext context) { base.Execute(context); if (ServiceLocator == null) { return; } if (CurrentOrderGroup == null || CurrentOrderGroup.OrderForms.Count == 0) { return; } // get line item promotions var lineItemRecords = CalculateLineItemDiscounts(); // get cart promotions var cartRecords = CalculateCartDiscounts(); // combine all records var recordsList = new List <PromotionRecord>(lineItemRecords); recordsList.Add(cartRecords); // filter policies var allRecords = PromotionEvaluator.EvaluatePolicies(recordsList.ToArray()); //3. Apply discounts var cartSubtotalRewards = (from r in allRecords where r.Reward is CartSubtotalReward select r).ToArray(); var lineItemRewards = (from r in allRecords where r.Reward is CatalogItemReward select r).ToArray(); var shipmentRewards = (from r in allRecords where r.Reward is ShipmentReward select r).ToArray(); var lineItemDiscountTotal = ApplyCatalogItemRewards(lineItemRewards); var orderSubTotal = CurrentOrderGroup.Subtotal - lineItemDiscountTotal; //Apply order subtotal discounts ApplyOrderSubtotalReward(orderSubTotal, cartSubtotalRewards); //Apply shipment discounts ApplyShipmentReward(shipmentRewards); //Add Gifts ApplyGiftReward(null, lineItemRewards); }
private ICartBuilder GetCartBuilder() { var catalogModuleApi = GetCatalogApiClient(); var cartApi = GetCartApiClient(); var commerceApi = GetCoreApiClient(); var marketingApi = GetMarketingApiClient(); var inventoryApi = GetInventoryApiClient(); var pricingApi = GetPricingApiClient(); var searchApi = GetSearchApiClient(); var cacheManager = new Moq.Mock <ILocalCacheManager>(); var workContextFactory = new Func <WorkContext>(GetTestWorkContext); var promotionEvaluator = new PromotionEvaluator(marketingApi); var pricingService = new PricingServiceImpl(workContextFactory, pricingApi, commerceApi); var catalogSearchService = new CatalogSearchServiceImpl(workContextFactory, catalogModuleApi, pricingService, inventoryApi, searchApi, promotionEvaluator); var retVal = new CartBuilder(cartApi, promotionEvaluator, catalogSearchService, commerceApi, cacheManager.Object); return(retVal); }