Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
You can, in theory, do something like this
var targetItems = new CatalogItemSelection(promotionItems.Reward.Items.Except(outOfStockItems), promotionItems.Reward.Type, promotionItems.Reward.IncludesSubcategories);
return new PromotionItems(promotionItems.Promotion, promotionItems.Condition, targetItems);
I am not sure what you are using the PromotionItems for so no further comment. but you can (and have to) reconstruct the object
Thanks, I would like to remove from the saved content, something like this:
var promotionItems = _promotionProcessor.Service.GetPromotionItems(promotionData);
var clone = (PromotionData) promotionData.CreateWritableClone();
var targetItems = new CatalogItemSelection(promotionItems.Reward.Items.Except(outOfStockItems),
promotionItems.Reward.Type,
promotionItems.Reward.IncludesSubcategories);
clone.? //TargetItems
_contentRepository.Service.Save(clone);
Is that doable?
I guess I could use:
clone.ExcludedItems.Add(variantLink);
Which probably is the best, then it will work even if it is a product in the rewards.
It seems you have to update promotionData.Condition.Items, but it depends on the actual promotion content type. Condition is a block of type PurchaseQuantity which available on several built in promotions, but not all
I could not find Condtion on the PromotionData, but this code actually worked just fine:
var variantLink = _referenceConverter.Service.GetContentLink(lineItem.Code);
if (promotionData.ExcludedCatalogItems == null || !promotionData.ExcludedCatalogItems.Contains(variantLink))
{
var clone = (PromotionData)promotionData.CreateWritableClone();
if (clone.ExcludedCatalogItems == null)
{
clone.ExcludedCatalogItems = new List<ContentReference>();
}
clone.ExcludedCatalogItems.Add(variantLink);
_contentRepository.Service.Publish(clone, EPiServer.Security.AccessLevel.NoAccess);
}
Even though Items and ExcludedItems will contain the same variant in this case, the result is what I wanted.
/Kristoffer
You need to cast the PromotionData to specific types that have Condition property - it's not available on the base type.
using ExcludedCatalogItems is a bit hacky as it should be used for things you want to exclude from discount. Like Gift cards etc.
Another approach is to implement IEntryFilter (easiest = inherit from EntryFilter), and filter out out of stock items. That means you won't have to care about updating your promotions dynamically
Agree, a bit hacky it is.
Thanks, I think I will solve it on some way from here.
Hmm, what should I cast it to? Condition seems to be at the PromotionItems and not the PromotionData?
You need to cast it to BuyQuantityGetFreeItems, BuyQuantityGetOrderDiscount, BuyQuantityGetSelectedItemsDiscount etc. Unfortunately there is no universal interface to cast to. With that said, IEntryFilter is a more general approach
Implemenation, at this moment:
var buyQuantityGetFreeItems = promotionData as BuyQuantityGetFreeItems;
if (buyQuantityGetFreeItems != null)
{
var clone = (BuyQuantityGetFreeItems)buyQuantityGetFreeItems.CreateWritableClone();
clone.Condition.Items.Remove(variantLink);
_contentRepository.Service.Save(clone, SaveAction.Publish | SaveAction.SkipValidation, EPiServer.Security.AccessLevel.NoAccess);
}
Implemenation, at this moment:
var buyQuantityGetFreeItems = promotionData as BuyQuantityGetFreeItems;
if (buyQuantityGetFreeItems != null)
{
var clone = (BuyQuantityGetFreeItems)buyQuantityGetFreeItems.CreateWritableClone();
clone.Condition.Items.Remove(variantLink);
_contentRepository.Service.Save(clone, SaveAction.Publish | SaveAction.SkipValidation, EPiServer.Security.AccessLevel.NoAccess);
}
HI!
I would like to rmove a variant from a promotion reward when it goes out of stock but the reward collection is read-only.
I would like to do something liek this:
var promotions = promotionEngine.Service.GetPromotionItemsForCampaign(campaign.ContentLink);
foreach (var promotionData in promotions.Where(p => p.Promotion.IsActive))
{
if (promotionData.Reward.Items.Contains(new EPiServer.Core.ContentReference(1234)))
{
promotionData.Reward.Items.Remove(new EPiServer.Core.ContentReference(1234))
}
}
Is this doable?
Thanks!
/Kristoffer