The EPiServer.Commerce.Catalog.Linking.ProductVariation class represents a relation between a product and a variant. To administer those relations, use EPiServer.Commerce.Catalog.Linking.IRelationRepository service.
The Child property of the ProductVariation contains the ContentReference of the variant. The class also has a SortOrder property, which describes the order of the variants, and a GroupName property for grouping variants. The Quantity property is not used for variants. EPiServer.Commerce.Catalog.Linking.EntryRelation contains default values that can be used: DefaultGroupName and DefaultQuantity.
A ProductVariation is uniquely defined by the ContentReference in its Child property together with its Parent property (referencing the product that has the variant). That is, the same variant cannot be added to a product more than once.
## Get a product's variants
Call the GetChildren method of IRelationRepository with the ContentReference of a product to get the following variants.
Code sample
To get the following products, call the GetParents method of ILinksRepository with the ContentReference of a variant:
Code sample
Or, get a variant's parent product by using entry content **extensions.**
Code sample
## Add a variant to a product
Use the UpdateRelation method or extension method of IRelationRepository to add new ProductVariation objects to a product. The new variant must have a Parent ContentReference and a Child ContentReference.
Code sample
## Remove variant from a product
To remove a variant from a product, call the RemoveRelation method or extension method of IRelationRepository, with a ProductVariation object matching an existing variant. You can either construct a matching object, or use GetParents to get the existing **Relations**, filter out the object you want to remove, and pass it to RemoveRelation.
Code sample