public virtual PromotionContext Evaluate(PromotionFilter filter, PromotionEntriesSet sourceEntriesSet, PromotionEntriesSet targetEntriesSet, bool checkEntryLevelLimit) { var helper = new PromotionHelper(); helper.PromotionContext.TargetGroup = PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key; helper.PromotionContext.SourceEntriesSet = sourceEntriesSet; helper.PromotionContext.TargetEntriesSet = targetEntriesSet; helper.Eval(filter, checkEntryLevelLimit); return helper.PromotionContext; }
public virtual PromotionContext Evaluate(PromotionFilter filter, PromotionEntriesSet sourceEntriesSet, PromotionEntriesSet targetEntriesSet, bool checkEntryLevelLimit) { var helper = new PromotionHelper(); helper.PromotionContext.TargetGroup = PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key; helper.PromotionContext.SourceEntriesSet = sourceEntriesSet; helper.PromotionContext.TargetEntriesSet = targetEntriesSet; helper.Eval(filter, checkEntryLevelLimit); return(helper.PromotionContext); }
private static void PreparePromotion(PromotionHelper helper, Entry entry, bool checkEntryLevelDiscountLimit) { var currentMarket = CurrentMarket.Service.GetCurrentMarket(); decimal minQuantity = 1; // get min quantity attribute if (entry.ItemAttributes != null) { minQuantity = entry.ItemAttributes.MinQuantity; } // we can't pass qauntity of 0, so make it default to 1 if (minQuantity <= 0) { minQuantity = 1; } var price = StoreHelper.GetSalePrice(entry, minQuantity, currentMarket) ?? new Mediachase.Commerce.Catalog.Objects.Price(new Money(0, currentMarket.DefaultCurrency)); // Create filter var filter = new PromotionFilter() { IgnoreConditions = false, IgnorePolicy = false, IgnoreSegments = false, IncludeCoupons = false }; // Create new entry // TPB: catalogNodes is determined by the front end. GetParentNodes(entry) var result = new PromotionEntry(String.Empty, String.Empty, entry.ID, price.Money.Amount); var promotionEntryPopulateService = (IPromotionEntryPopulate)MarketingContext.Current.PromotionEntryPopulateFunctionClassInfo.CreateInstance(); promotionEntryPopulateService.Populate(result, entry, currentMarket.MarketId, currentMarket.DefaultCurrency); var sourceSet = new PromotionEntriesSet(); sourceSet.Entries.Add(result); // Only target entries helper.PromotionContext.TargetGroup = PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key; // Configure promotion context helper.PromotionContext.SourceEntriesSet = sourceSet; helper.PromotionContext.TargetEntriesSet = sourceSet; // Execute the promotions and filter out basic collection of promotions, we need to execute with cache disabled, so we get latest info from the database helper.Eval(filter, checkEntryLevelDiscountLimit); }
// Old stuff... no demo... Legacy Promos // This is a slightly-refactored version of the StoreHelper.GetDiscountPrice() method // catalogName and catalogNodeCode... can be used to filter out certain nodes or catalogs private static Price GetDiscountPriceInternal(EntryContentBase contentSku, Entry sku, IPriceValue price, string catalogName, string catalogNodeCode) { string catalogNodes = String.Empty; string catalogs = String.Empty; // Now cycle through all the catalog nodes where this entry is present filtering by specified catalog and node code // Note: The nodes are only populated when Full or Nodes response group is specified. if (sku.Nodes != null && sku.Nodes.CatalogNode != null && sku.Nodes.CatalogNode.Length > 0) { foreach (CatalogNode node in sku.Nodes.CatalogNode) { string entryCatalogName = CatalogContext.Current.GetCatalogDto(node.CatalogId).Catalog[0].Name; // Skip filtered catalogs if (!String.IsNullOrEmpty(catalogName) && !entryCatalogName.Equals(catalogName)) { continue; } // Skip filtered catalogs nodes if (!String.IsNullOrEmpty(catalogNodeCode) && !node.ID.Equals(catalogNodeCode, StringComparison.OrdinalIgnoreCase)) { continue; } if (String.IsNullOrEmpty(catalogs)) { catalogs = entryCatalogName; } else { catalogs += ";" + entryCatalogName; } if (String.IsNullOrEmpty(catalogNodes)) { catalogNodes = node.ID; } else { catalogNodes += ";" + node.ID; } } } if (String.IsNullOrEmpty(catalogs)) { catalogs = catalogName; } if (String.IsNullOrEmpty(catalogNodes)) { catalogNodes = catalogNodeCode; } // Get current context Dictionary <string, object> context = MarketingContext.Current.MarketingProfileContext; // Create filter PromotionFilter filter = new PromotionFilter { IgnoreConditions = false, IgnorePolicy = false, IgnoreSegments = false, IncludeCoupons = false }; // Create new entry // Note: catalogNodes is determined by GetParentNodes(entry) PromotionEntry result = new PromotionEntry(catalogs, catalogNodes, sku.ID, price.UnitPrice.Amount); var promotionEntryPopulateService = (IPromotionEntryPopulate)MarketingContext.Current.PromotionEntryPopulateFunctionClassInfo.CreateInstance(); promotionEntryPopulateService.Populate(result, sku, _currentMarket.Service.GetCurrentMarket().MarketId, _currentMarket.Service.GetCurrentMarket().DefaultCurrency); PromotionEntriesSet sourceSet = new PromotionEntriesSet(); sourceSet.Entries.Add(result); // Create new promotion helper, which will initialize PromotionContext object for us and setup context dictionary PromotionHelper helper = new PromotionHelper(); // Only target entries helper.PromotionContext.TargetGroup = PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key; // Configure promotion context helper.PromotionContext.SourceEntriesSet = sourceSet; helper.PromotionContext.TargetEntriesSet = sourceSet; // Execute the promotions and filter out basic collection of promotions, we need to execute with cache disabled, so we get latest info from the database helper.Eval(filter); Money discountedAmount; // Check the count, and get new price if promotion is applied if (helper.PromotionContext.PromotionResult.PromotionRecords.Count > 0) { discountedAmount = new Money(price.UnitPrice.Amount - GetDiscountPriceFromPromotionResult( helper.PromotionContext.PromotionResult), _currentMarket.Service.GetCurrentMarket().DefaultCurrency); return(new Price { UnitPrice = discountedAmount, ValidFrom = price.ValidFrom, ValidUntil = price.ValidUntil, MinQuantity = price.MinQuantity, MarketId = price.MarketId, EntryContent = contentSku, CustomerPricing = price.CustomerPricing }); } else { return(new Price(price)); } }