Promotion: gift with purchase is not saving the gift items

Member since: 2013
 

Hi

I am programmatically adding a promotion to Epi Commerce. The ype of promotion I am adding is 'Gift with purchase'. Code below:

newDiscount.IsActive = true;
newDiscount.Name = "Free gift with purchase";
newDiscount.Description = "Free gift with purchase";
newDiscount.Condition.Items = targets;//list of ContentReferences
newDiscount.Condition.RequiredQuantity = 1;
newDiscount.Discount.Percentage = 100;
newDiscount.ExcludedItems = new List<ContentReference> { SalesCampaignFolder.CampaignRoot }; // Exclude all other discounts from combining with this discount
               
newDiscount.DiscountTarget = new DiscountItems()
{
     Items = freegifts, //List of ContentReferences
     MaxQuantity = 1,
};
ContentRepository.Save(newDiscount, SaveAction.Publish, AccessLevel.NoAccess);

The promotion saves fine without any erros. The issue I am experiecing is that the 'free gifts' are not saving, no entries in the 'Get these entries' section. Initially I thought is was a stock issue, but there is enough in inventory.

#198866 Nov 07, 2018 22:39
  • Member since: 2011
     

    DiscountItems is a block, so you don't "new it", you just set the values to it 

    newDiscount.DiscountTarget.Items = freegifts; //List of ContentReferences
    newDiscount.DiscountTarget.MaxQuantity = 1;
    #198881 Nov 08, 2018 8:31
  • Member since: 2013
     

    Hi Quan.

    Yip, that was the fix. Thanks for that!!

    Regards

    Farhad

    #198925 Nov 08, 2018 22:09