Unable to get variantId for free products

Hi,
I am trying to fetch the variant Id

var variantId = orderCarrier.OrderRows.FirstOrDefault(x => x.ID.ToString() == paymentRow.ReferenceID)?.ArticleNumber;

This works fine for all products, except when a free product is added from campaign,
and hence, I am not able to get the variant.

Kindly advice what needs to be done here ?

Litium version: 7

Can you expand a bit more on your scenario? When are you trying to fetch the variant id?

Hi @NilsN

here is some more code :

foreach (var paymentInfoCarrier in orderCarrier.PaymentInfo)
{
foreach (var paymentRow in paymentInfoCarrier.Rows)
{
switch (paymentRow.ReferenceType)
{
case Foundation.Modules.ECommerce.Payments.PaymentInfoRowType.OrderRow:
// here is where I need the variantID
// this is inside the litium.voyado plugin, need to fetch variant details.
}
}
}

issue is only when the product is free product.

I tried this locally, putting your code in a simple test controller with the following code and I get the expected variants. Is your product setup different? My free gift product is using the template Product with only one variant.

public IHttpActionResult Index()
{
	var orderCarrier = ModuleECommerce.Instance.Orders.GetOrder("LS100008", ModuleECommerce.Instance.AdminToken).GetAsCarrier(true, true, true, true, true, true);

	var variants = new List<string>();

	foreach (var paymentInfoCarrier in orderCarrier.PaymentInfo)
	{
		foreach (var paymentRow in paymentInfoCarrier.Rows)
		{
			switch (paymentRow.ReferenceType)
			{
				case Foundation.Modules.ECommerce.Payments.PaymentInfoRowType.OrderRow:
					// here is where I need the variantID
					// this is inside the litium.voyado plugin, need to fetch variant details.
					var variantId = orderCarrier.OrderRows.FirstOrDefault(x => x.ID.ToString() == paymentRow.ReferenceID)?.ArticleNumber;
					variants.Add(variantId);
					break;
			}
		}
	}

	return Json(variants);
}

The order LS100008:

The response:
JSON-Response

This was tested using a standard Accelerator of Litium 7.2.3.

@NilsN
I am using the version 7.3.0
This is how my order row looks.

This is the final variantId’s that I get, null represents the free product.
image

So what could be possible wrong here.

If the order is re-calculated, then the added rows from campaigns will be removed and then added again, that make them get a new OrderRowID and the reference is not matching any more. Is the order re-calculated after it is placed?

Hi @patric.forsgard
I have checked this and the campaign row get a new OrderRowId even before the order is placed.
It keeps changing when we refresh the checkout page.

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