Problem connect a campaign price list to a discount using API

We are setting up discounts using the .net API, in Litium 8.7.2. We are using the price list service to create a campaign price list that we are adding the discounted products to.

priceList = new CampaignPriceList();
priceList.Id = campaignImport.CampaignId;
priceList.CurrencySystemId = standardPriceList.CurrencySystemId;
priceList.Localizations.CurrentCulture.Name = campaignImport.Name;

_priceListService.Create(priceList);

We then create a discount of the type DiscountedProductPrice where we pass along a DicountedProdctPrice object to the constructor, that has the price list id of the price list we just created.

var discountedProductPrice = new DiscountedProductPrice { PriceListSystemIds = new List { priceList.SystemId } };

var channel = _channelService.Get(_defaultChannelName);
var discount = new Discount(discountedProductPrice)
{
Id = campaignImport.CampaignId,
ChannelLinks = new List
{
new(channel.SystemId)
{
StartDateTimeUtc = campaignImport.StartDate,
EndDateTimeUtc = campaignImport.EndDate
}
}
};
discount.Localizations.CurrentCulture.Name = campaignImport.Name;

_discountService.Create(discount);

Both the discount and price list are created successfully. However, when you open the discount in the backoffice, the price list is not associated to the discount and we need to add it manually on the discount using the discount edit page under Sales → Dicsounts → [Discount name]…

If you do this step manually everything works. Should this not be done automaticlly when creating the pricelist and discount using the API and pass along the id of the price list to the constructor of the discount? Do we need to do an additional step to get the price list connected or is it some kind of timing problem where the price list does not exist yet or is it a bug?

Litium version: 8.7.2

Yea it’s a “bug”, the Variants field in DiscountedProductPrice has to be set and can’t be null.
So it should work if you change the variable discountedProductPrice to this:

    var discountedProductPrice = new DiscountedProductPrice 
    {
        PriceListSystemIds = new List<Guid> { priceList.SystemId },
        Variants = new Dictionary<Guid, IDictionary<Guid, decimal>>() 
    };
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.