Skip to main content
Question

Update Custom Line items Name with new locales

  • May 16, 2025
  • 1 reply
  • 52 views

Wanted to update the name for existing item in customLineItems, could not find any action around that.

Is there any way to do the update.

 

Example

 

Want to add fr-CA in 

"name"
:
{
"en":"Alina Handwoven Solid Slub Pillow Cover - Square"
"en-US":"Alina Handwoven Solid Slub Pillow Cover - Square"
"en-GB":"Alina Handwoven Solid Slub Pillow Cover - Square"
"en-EU":"Alina Handwoven Solid Slub Pillow Cover - Square"
}

 

Ben Hedrick
commercetooler
Forum|alt.badge.img

Hey Manpreet,

 

You're correct, there isn't a direct update action specifically for changing the name of an existing customLineItem. However, you can achieve this by using the setLineItemCustomField update action in combination with a custom field designed to store the localized name.

Here's the recommended approach:

  1. Custom Field for Localized Name: Create a custom field (if you don't already have one) on the type associated with your custom line items. This custom field should be of type "LocalizedString" to store the localized names. Let's call this custom field localizedName.

  2. Update Action: Use the setLineItemCustomField update action to update the value of the localizedName custom field.

Explanation:

  • The setLineItemCustomField action targets the specific custom line item using its lineItemId.
  • It updates the custom field with the name localizedName (or whatever you named your custom field).
  • The value is the new LocalizedString object containing the localized names.

Key Considerations:

  • Custom Type: Ensure your custom line items have a custom type associated with them, and that this type has the localizedName custom field defined.
  • API Version: Make sure you're using a compatible API version that supports custom fields on line items.
  • Error Handling: Implement proper error handling to manage cases where the custom line item or custom field is not found.

This approach allows you to effectively update the localized name of a custom line item by leveraging custom fields and the setLineItemCustomField update action. Remember to consult the commercetools API documentation for the most accurate and up-to-date information.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings