Trying to set a different schedule for a promotion/ItemDiscount in code.
promotion.Schedule = new PromotionSchedule
ValidFrom = new DateTime(2017, 04, 20),
ValidUntil = new DateTime(2017, 04, 23),
CampaignLink = promotion.ParentLink,
UseCampaignDate = false
The Promotion gets saved and shows up in epi, and "UseCampaignDate" seems to be set correctly, but the validfrom and until are empty so the discount acts as "Expired".
Am I missing something?
Seems that the promotion needed to be saved to database before schedule could be set.
So first save the promotion, then set the schedule and then save again.
PromotionSchedule is just a BlockData, so you should not have to save the Promotion first before setting it. But I think your code is not the way you should do it, you can just set it like this
promotion.Schedule.ValidFrom = new DateTime(2017, 04, 20); promotion.Schedule.ValidUntil = new DateTime(2017, 04, 23);promotion.Schedule.UseCampaignDate = false;
without having to create a new instance of PromotionSchedule.
That did work as a charm :) Thanks!