Learn how to implement personalized products in Umbraco Commerce.
Personalized products can be customized by the customer. This customization can be adding a message or selecting different options for the product. This guide will show you how to implement personalized products in Umbraco Commerce.
This will be broken down into the following steps:
Add a message field on the product page in the add-to-cart form
Register a UI extension to display the value in the Backoffice.
This guide is not a direct follow-on from the getting started tutorial. It is assumed that your store is set up in a similar structure.
Capturing a Message
On the frontend, add a text area to the product page where the customer can enter their message.
Customer Message Field
Saving the Message as an Order Line Property
When the customer adds the product to the cart, the message will be saved in an order line property.
Add an Observations property of the AddToCartDto to capture the message.
AddToCartDto.cs
public class AddToCartDto
{
...
public string? Observations { get; set; }
}
Locate the AddToCart of the CartSurfaceController.
Set a property on the order line if a value has been sent with the request.
CartSurfaceController.cs
[HttpPost]
public async Task<IActionResult> AddToCart(AddToCartDto postModel)
{
try
{
await _commerceApi.Uow.ExecuteAsync(async uow =>
{
var store = CurrentPage.GetStore();
var order = await _commerceApi.GetOrCreateCurrentOrderAsync(store.Id)
.AsWritableAsync(uow)
.AddProductAsync(postModel.ProductReference, decimal.Parse(postModel.Quantity), new Dictionary<string, string>{
{ "productObservations", postModel.Observations }
});
await _commerceApi.SaveOrderAsync(order);
uow.Complete();
});
}
catch (ValidationException ex)
{
...
}
}
Accessing the Property in the Backoffice
To view the data in the Backoffice order editor, you need to register an ucOrderProperty extension along with the relevant label localizations as sampled below.
Create a new umbraco-package.json file in a folder in the App_Plugins directory in the root of your project and add the following code: