using CoreConnect.Commerce.Core;
using HotChocolate.Types;
using Attribute = CoreConnect.Commerce.Core.Attribute;
namespace CoreConnect.Commerce.Catalog;
public class ProductVariant
/// The ID of the Product Variant.
public required string Id { get; set; }
/// The SKU of the Product Variant.
public required string Sku { get; set; }
/// The Price Include Tax of the Product Variant.
public Money? PriceInclTax { get; set; }
/// The Price Exclude Tax of the Product Variant.
public Money? PriceExclTax { get; set; }
/// The Sale Price Include Tax (Discounted Price Include Tax) of the Product Variant.
public Money? SalePriceInclTax { get; set; }
/// The Sale Price Exclude Tax (Discounted Price Exclude Tax) of the Product Variant.
public Money? SalePriceExclTax { get; set; }
/// Discounted prices for a product based on quantity tiers
public IEnumerable<TierPrices>? TierPrices { get; set; }
/// The Default Image of the Product Variant.
public Image? DefaultImage { get; set; }
/// The Images of the Product Variant.
public required IEnumerable<Image> Images { get; set; }
/// The Attributes of the Product Variant.
public required IEnumerable<Attribute> Attributes { get; set; }
public ProductVariantStock? Stock { get; set; }
/// The Inventories of the Product Variant.
public IEnumerable<Inventory>? Inventories { get; set; }
/// Price custom objects.Object is of type CentPrecisionMoney
[GraphQLType(typeof(AnyType))]
public Dictionary<string, object>? CustomFields { get; set; }
/// Available discounts for a product
public List<string>? Discounts { get; set; }
public class ProductVariantStock
public int AvailableQuantity { get; set; }
public bool IsSellableWithoutStock { get; set; }
public bool IsAvailable { get; set; }
public required string Id { set; get; }
public string? ChannelId { set; get; }
public long? AvailableQuantity { get; set; }
[ExtendObjectType<ProductVariant>]
public class ProductVariantExtension
private const string _parsedAttributes = "parsedAttributes";
public ProductVariantMetadata GetMetadata([Parent] ProductVariant product)
return SetMetadata(product);
private static ProductVariantMetadata SetMetadata(ProductVariant product)
var attributes = product.Attributes
a => AttributeValueHelper.GetAttributeValue(a.Value ?? new AttributeValue())
var jsonAttributes = JsonSerializer.Serialize(attributes);
return new ProductVariantMetadata(_parsedAttributes, JsonDocument.Parse(jsonAttributes).RootElement);
public class ProductVariantMetadata
public ProductVariantMetadata(string key, JsonElement value)
public string Key { get; set; }
public JsonElement Value { get; set; }
public string? Discount { get; set; }
public long? Quantity { get; set; }
public Money? Price { get; set; }