예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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));
        }