Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

InMemoryLineItem not saving properly

Vote:
 

Hi,

I am working with Commerce 12.3.1, the DisplayName property of the line item is not being saved. 

The below code snippet is present in the custom implementation of UpdatePlacedPrice method of DefaultPlacedPriceProcessor class.

//If display name is not present use the parent name

string DisplayName = entry.GetPropertyValue("DisplayName");
DisplayName = string.IsNullOrEmpty(DisplayName) ? entry.Name : DisplayName;
if (!string.Equals(lineItem.DisplayName, DisplayName))
{
if(!noneValidationAdded)
onValidationError(lineItem, ValidationIssue.None);

lineItem.DisplayName = DisplayName;
}

But when it saves to cart, the display name is blank. Below is the scenario:

Create a line item with DisplayName = "Test Display Name", I then save the cart using the code snippet below:

var orderService = ServiceLocator.Current.GetInstance();
orderService.Save(cart);

But once I check the InMemoryLineItem object's DisplayName property it is blank.  

#197548
Edited, Oct 06, 2018 1:06
Vote:
 

Can you share a bit more of your code, for example where you call these methods and/or where you create the LineItem?

With the limited information, here are some things to check:

First, just to cover our bases, does entry.Name contain a value? With the code example you gave DisplayName will remain empty if both entry.GetPropertyValue("DisplayName") and entry.Name are empty.

Second, in regards to separation of concerns, why are you setting DisplayName in a method related to updating prices? I'd look into putting the code that does this in another place. For example closer to where you create the LineItem.

#197570
Edited, Oct 08, 2018 11:26
* 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.