Skip to content

Commit 732cce6

Browse files
alexeyshibanovyuskithedeveloperclaudeOlegoO
authored
feat: Add Variation configuration section type and MaxLength field (#869)
Co-authored-by: yuskithedeveloper <yuskianywhere@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Oleg Zhuk <zhukoo@gmail.com>
1 parent 761e043 commit 732cce6

File tree

33 files changed

+7229
-213
lines changed

33 files changed

+7229
-213
lines changed

src/VirtoCommerce.CatalogModule.Core/Model/Configuration/ProductConfigurationSection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ProductConfigurationSection : AuditableEntity, ICloneable, IHasName
1616
public string Type { get; set; }
1717
public bool AllowCustomText { get; set; }
1818
public bool AllowPredefinedOptions { get; set; }
19+
public int? MaxLength { get; set; }
1920

2021
[JsonIgnore]
2122
public ProductConfiguration Configuration { get; set; }

src/VirtoCommerce.CatalogModule.Core/ModuleConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace VirtoCommerce.CatalogModule.Core
1111
public static class ModuleConstants
1212
{
1313
public const string ConfigurationSectionTypeProduct = "Product";
14+
public const string ConfigurationSectionTypeVariation = "Variation";
1415
public const string ConfigurationSectionTypeText = "Text";
1516
public const string ConfigurationSectionTypeFile = "File";
1617
public const string ConfigurationSectionFilesScope = "product-configuration";
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Globalization;
3+
using System.IO;
4+
using System.Text;
5+
using Newtonsoft.Json;
6+
using VirtoCommerce.Platform.Core.Common;
7+
8+
namespace VirtoCommerce.CatalogModule.Core.Serialization;
9+
10+
/// <summary>
11+
/// Provides JSON serialization and deserialization for catalog objects (products, categories, etc.)
12+
/// with settings optimized for compact storage (e.g. product snapshots in orders).
13+
/// </summary>
14+
public static class ProductJsonSerializer
15+
{
16+
public static JsonSerializer ObjectSerializer { get; } = new()
17+
{
18+
DefaultValueHandling = DefaultValueHandling.Include,
19+
NullValueHandling = NullValueHandling.Ignore,
20+
Formatting = Formatting.None,
21+
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
22+
TypeNameHandling = TypeNameHandling.None,
23+
};
24+
25+
public static string Serialize(object obj)
26+
{
27+
using var stringWriter = new StringWriter(new StringBuilder(256), CultureInfo.InvariantCulture);
28+
using var jsonTextWriter = new JsonTextWriter(stringWriter);
29+
jsonTextWriter.Formatting = ObjectSerializer.Formatting;
30+
ObjectSerializer.Serialize(jsonTextWriter, obj, objectType: null);
31+
32+
return stringWriter.ToString();
33+
}
34+
35+
public static T Deserialize<T>(string json)
36+
{
37+
return (T)Deserialize(json, typeof(T));
38+
}
39+
40+
public static object Deserialize(string json, Type type)
41+
{
42+
using var stringReader = new StringReader(json);
43+
using var jsonTextReader = new JsonTextReader(stringReader);
44+
var result = ObjectSerializer.Deserialize(jsonTextReader, type);
45+
46+
return result;
47+
}
48+
49+
/// <summary>
50+
/// Deserializes JSON to the correct polymorphic type using <see cref="AbstractTypeFactory{T}"/>.
51+
/// </summary>
52+
public static T DeserializePolymorphic<T>(string json)
53+
where T : class
54+
{
55+
var type = AbstractTypeFactory<T>.TryCreateInstance().GetType();
56+
return Deserialize(json, type) as T;
57+
}
58+
}

0 commit comments

Comments
 (0)