/// <summary> /// Gets the marketing helper. /// </summary> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <returns></returns> private MarketingHelper GetMarketingHelper(bool useCache) { MarketingHelper helper = null; string cacheKey = MarketingCache.CreateCacheKey("MarketingHelper"); if (useCache) { object cachedObject = MarketingCache.Get(cacheKey); if (cachedObject != null) { helper = (MarketingHelper)cachedObject; } } // If marketing is not initialized, init it if (helper == null) { // Load promotion Dto PromotionDto promotionDto = PromotionManager.GetPromotionDto(FrameworkContext.Current.CurrentDateTime); // Get all the data from the database first helper = new MarketingHelper(CampaignManager.GetCampaignDto(), ExpressionManager.GetExpressionDto(), PolicyManager.GetPolicyDto(), promotionDto, SegmentManager.GetSegmentDto()); // Insert cache //if (useCache) MarketingCache.Insert(cacheKey, helper, MarketingConfiguration.Instance.CacheConfig.PromotionCollectionTimeout); } return(helper); }
/// <summary> /// Initializes a new instance of the <see cref="SearchController" /> class. /// </summary> /// <param name="marketing">The marketing.</param> /// <param name="priceListClient">The price list client.</param> /// <param name="storeClient">The store client.</param> /// <param name="catalogClient">The catalog client.</param> /// <param name="searchFilter">The search filter.</param> public SearchController(MarketingHelper marketing, PriceListClient priceListClient, StoreClient storeClient, CatalogClient catalogClient, ISearchFilterService searchFilter) { _marketing = marketing; _priceListClient = priceListClient; _storeClient = storeClient; _catalogClient = catalogClient; _searchFilter = searchFilter; }
/// <summary> /// Evaluates the promotions. /// </summary> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="context">The context.</param> /// <param name="filter">The filter.</param> /// <returns>Collection of promotions that were applied. Look inside PromotionContext for actual rewards and for items that have been affected by these promotions.</returns> public PromotionItemCollection EvaluatePromotions(bool useCache, PromotionContext context, PromotionFilter filter) { MarketingHelper helper = GetMarketingHelper(useCache); PromotionItemCollection dto = new PromotionItemCollection(helper); // Remove current customer promotion history if we opted to not use cache (which happens during checkout) if (!useCache) { string cacheKey = MarketingCache.CreateCacheKey("MarketingHelper-customer", context.CustomerId.ToString()); MarketingCache.Remove(cacheKey); } return(EvaluatePromotions(context, dto, filter)); }
/// <summary> /// Returns customer segments for specified customer or organization. /// </summary> /// <param name="context">The context. Should include ContextConstants.CustomerProfile of type ProfileBase</param> /// <param name="customerPrincipalId">The customer principal id.</param> /// <param name="organizationPrincipalId">The organization principal id.</param> /// <returns>int list of customer segment ids</returns> public List <int> GetCustomerSegments(Dictionary <string, object> context, Guid customerPrincipalId, Guid organizationPrincipalId) { List <int> segments = new List <int>(); MarketingHelper helper = GetMarketingHelper(true); SegmentDto segmentsDto = helper.Segments; PromotionContext promotionContext = new PromotionContext(context, null, null); // Cycle through customer segments foreach (SegmentDto.SegmentRow segmentRow in segmentsDto.Segment) { bool includeSegment = false; bool excludeSegment = false; // Check if profile is directly specified in the members tables foreach (SegmentDto.SegmentMemberRow memberRow in segmentRow.GetSegmentMemberRows()) { if (memberRow.PrincipalId == customerPrincipalId || memberRow.PrincipalId == organizationPrincipalId) { if (memberRow.Exclude) { excludeSegment = true; break; } else { includeSegment = true; break; } } } // if explicitely excluded, skip the segment if (excludeSegment) { continue; } // Validate expressions, if any of the expression is met, user is part of the group foreach (SegmentDto.SegmentConditionRow condition in segmentRow.GetSegmentConditionRows()) { ExpressionDto.ExpressionRow expressionRow = helper.Expressions.Expression.FindByExpressionId(condition.ExpressionId); if (expressionRow != null && !String.IsNullOrEmpty(expressionRow.ExpressionXml)) { ValidationResult result = ValidateExpression(expressionRow.ApplicationId.ToString() + "-" + expressionRow.Category + "-" + expressionRow.ExpressionId.ToString(), expressionRow.ExpressionXml, promotionContext); if (!result.IsValid) { includeSegment = false; continue; } else { includeSegment = true; break; } } } if (!includeSegment) { continue; } segments.Add(segmentRow.SegmentId); } return(segments); }