Skip to content

UpdatingProduct

// RB2 Core Connect
using System.Text.Json.Serialization;
namespace CoreConnect.Commerce.Messages;
public class UpdateProductMessage
{
public string? ProductKey { get; set; }
public string? SKU { get; set; }
public string? VariantKey { get; set; }
public List<UpdateReference>? Categories { get; set; }
public UpdateReference? TaxCategory { get; set; }
public bool? Enabled { get; set; }
public UpdateReference? ProductTypeKey { get; set; }
public Dictionary<string, string>? Name { get; set; }
public Dictionary<string, string>? Slug { get; set; }
public Dictionary<string, string>? Description { get; set; }
public Dictionary<string, UpdateImage>? Images { get; set; }
public Dictionary<string, string>? MetaTitle { get; set; }
public Dictionary<string, string>? MetaDescription { get; set; }
public List<UpdateAttribute> AttributeMap { get; set; } = new List<UpdateAttribute>();
}
public class AttributeTypes
{
public const string String = "String";
public const string LocalizedString = "LocalizedString";
public const string Enum = "Enum";
public const string LocalizedEnum = "LocalizedEnum";
public const string Date = "Date";
public const string Boolean = "Boolean";
public const string Double = "Double";
public const string Decimal = "Decimal";
public const string Money = "Money";
public const string Array = "Array";
public const string Record = "Record";
}
[UnionTag(nameof(Kind))]
[UnionCase(typeof(UpdateAttribute.StringAttribute), nameof(AttributeTypes.String))]
[UnionCase(typeof(UpdateAttribute.LocalizedStringAttribute), nameof(AttributeTypes.LocalizedString))]
[UnionCase(typeof(UpdateAttribute.EnumAttribute), nameof(AttributeTypes.Enum))]
[UnionCase(typeof(UpdateAttribute.LocalizedEnumAttribute), nameof(AttributeTypes.LocalizedEnum))]
[UnionCase(typeof(UpdateAttribute.DateAttribute), nameof(AttributeTypes.Date))]
[UnionCase(typeof(UpdateAttribute.BooleanAttribute), nameof(AttributeTypes.Boolean))]
[UnionCase(typeof(UpdateAttribute.DoubleAttribute), nameof(AttributeTypes.Double))]
[UnionCase(typeof(UpdateAttribute.DecimalAttribute), nameof(AttributeTypes.Decimal))]
[UnionCase(typeof(UpdateAttribute.MoneyAttribute), nameof(AttributeTypes.Money))]
[UnionCase(typeof(UpdateAttribute.ArrayAttribute), nameof(AttributeTypes.Array))]
[UnionCase(typeof(UpdateAttribute.RecordAttribute), nameof(AttributeTypes.Record))]
[JsonConverter(typeof(UnionConverter<UpdateAttribute>))]
public abstract record UpdateAttribute(string name)
{
public abstract string Kind { get; }
public record StringAttribute(string name, string value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.String; } } }
public record LocalizedStringAttribute(string name, Dictionary<string, string> value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.LocalizedString; } } }
public record EnumAttribute(string name, string value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Enum; } } }
public record LocalizedEnumAttribute(string name, string value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.LocalizedEnum; } } }
public record DateAttribute(string name, DateTime value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Date; } } }
public record BooleanAttribute(string name, bool value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Boolean; } } }
public record DoubleAttribute(string name, double value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Double; } } }
public record DecimalAttribute(string name, decimal value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Decimal; } } }
public record MoneyAttribute(string name, string currency, decimal value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Money; } } }
public record ArrayAttribute(string name, List<UpdateAttribute> value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Array; } } }
public record RecordAttribute(string name, List<UpdateAttribute> value) : UpdateAttribute(name) { public override string Kind { get { return AttributeTypes.Record; } } }
}
public record UpdateImage(string url, string contentType, long? width = default, long? height = default, string? hint = default);