diff --git a/src/Modules/OrchardCore.Commerce/Events/WorkflowShoppingCartEvents.cs b/src/Modules/OrchardCore.Commerce/Events/WorkflowShoppingCartEvents.cs index 166f4637..c2e22c6d 100644 --- a/src/Modules/OrchardCore.Commerce/Events/WorkflowShoppingCartEvents.cs +++ b/src/Modules/OrchardCore.Commerce/Events/WorkflowShoppingCartEvents.cs @@ -39,14 +39,16 @@ public class WorkflowShoppingCartEvents : IShoppingCartEvents if (!results.Any()) return (eventContext.Headers, eventContext.Lines); - var headers = GetOutput>(results, nameof(eventContext.Headers)) ?? eventContext.Headers; + var headers = GetOutput>(results, nameof(eventContext.Headers))? + .Select(item => (LocalizedHtmlString)item) + .ToList() ?? eventContext.Headers; var lines = GetOutput>(results, nameof(eventContext.Lines)) ?? eventContext.Lines; return (headers, lines); } public async Task VerifyingItemAsync(ShoppingCartItem item) => - GetOutput( + GetOutput( await TriggerEventAsync(item), "Error"); @@ -86,11 +88,17 @@ private static T GetOutput(IEnumerable contexts, st return output switch { - string outputLocalizedHtmlString when typeof(T) == typeof(LocalizedHtmlString) => - new LocalizedHtmlString(outputLocalizedHtmlString, outputLocalizedHtmlString) as T, + string outputLocalizedHtmlString when typeof(T) == typeof(SerializableLocalizedHtmlString) => + new SerializableLocalizedHtmlString(outputLocalizedHtmlString, outputLocalizedHtmlString) as T, string outputString => JsonSerializer.Deserialize(outputString, JOptions.Default), not null => JsonSerializer.Deserialize(JsonSerializer.Serialize(output, JOptions.Default), JOptions.Default), _ => default, }; } + + public sealed record SerializableLocalizedHtmlString(string Name, string Value) + { + public static implicit operator LocalizedHtmlString(SerializableLocalizedHtmlString item) => + item is null ? null : new LocalizedHtmlString(item.Name ?? item.Value, item.Value ?? item.Name); + } }