Try our conversational search powered by Generative AI!

Promotion: gift with purchase is not saving the gift items

Vote:
 

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 { 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
Vote:
 

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
Vote:
 

Hi Quan.

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

Regards

Farhad

#198925
Nov 08, 2018 22:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.