When giving a talk at the Serbia meetup for Episerver last Thursday, about setting up / creating your catalog (models), I got the question if it was possible to give a discount on a bundle. This is not possible out of the box but can be easily done with a custom promotion.
Nothing special going on in the code, just using the content references in the bundle instead of the references below a category. Note: set MatchRecursive to false when getting the DiscountItems or PromotionItems
protected static DiscountItems GetTargetItems(BuyBundleGetItemDiscount promotionData)
{
IEnumerable<ContentReference> entries = ListBundleEntries(referenceToBundle: promotionData.Bundle).Select(e => e.Child);
return new DiscountItems { Items = entries.ToList(), MatchRecursive = false };
}
protected static IEnumerable<BundleEntry> ListBundleEntries(ContentReference referenceToBundle)
{
IRelationRepository relationRepository = ServiceLocator.Current.GetInstance<IRelationRepository>();
// Relations to bundle entries are of type BundleEntry
List<BundleEntry> bundleEntries = relationRepository.GetChildren<BundleEntry>(parentLink: referenceToBundle).ToList();
return bundleEntries;
}
The complete promotion can be found in a Gist
This is helpful information, thanks for sharing the code.
LikeLike