Find out which campaign entered coupon code is related to?

Hi!

If I add two rows in my cart. The first one is connected to a campaign giving med 50% on that item and the second one gives me 10% on the second item when I use a code.
Then OrderCarrier.CampaignInfo is populated with the code and both order rows has a CampaignID.
But how do I know which campaign is connected with the code?
What I want to do is to show the name of the campaign activated by the code but I cannot figure out how if there is more than one campaign activated on the carrier?

Thanks!

/Kristoffer

Litium version: 6.3.9

You could fetch all the campaign IDs from the order carrier (there’s an extension method for that), get each campaign and check if their condition info is of type VoucherCodeCondition. If it is you can get the name from the campaign.

string campaignName = string.Empty;
var campaignIds = CartService.OrderCarrier.GetCampaignIds();
foreach (var campaignSystemId in campaignIds)
{
	var campaign = _moduleECommerce.Campaigns.GetCampaign(campaignSystemId, _securityToken);
	if (campaign.ConditionInfos.Any(x => x.TypeName == typeof(VoucherCodeCondition).FullName)) { 
		campaignName = campaign.Name;
		break;
	}
}

Another option could be to look at the SetCampaignCode method, which creates two lists of campaign IDs: one without the code (list A) and one with the code (list B). If list B contains a campaign that is not in list A, that’s the id of your campaign.

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