Create product variations

To create a product variation, you must perform the following:

  1. Get the catalog manager.
    Get an instance of the CatalogManager object.
  2. Get the specified product.
    Get an instance of the product that the variation will belong to. For more information, see For developers: Query products.
  3. Get the specified attribute value.
    Get an instance of the attribute value that the variation will be associated to.
  4. Create new product variation.
    To create new product variation, call the CreateProductVariation method of the manager.
  5. Set the properties of the ProductVariation instance.
    In this example the following properties are set:
    • AdditionalPrice
    • Parent
    • Sku 
    • IsActive
  6. Set the Variant property.
    To set the variant property, you must perform the following:
    1. Create an instance of the AttributeValuePair class.
    2. Set its AttributeId property to the ID of the attribute that the specified value belongs to. 
    3. Set the AttributeValueId to the ID of the specified attribute value.
    4. Create an instance of the JavaScriptSerializer class.
    5. Serialize the AttributeValuePair instance into a string.
    6. Set the Variant property of the variation to the serialized string.
  7. Create a product variation detail.
    To create a product variation detail, you must perform the following:
    1. Create a new instance of the ProductVariationDetail class by calling the CreateProductVariationDetail method of the manager. 
    2. Set the ProductAttributeParent to the instance of the attribute that the specified attribute value belongs to.
    3. Set the ProductAttributeValueParent to the instance of the specified attribute value.
    4. Set the ProductVariationParent to the instance of the product variation.
    5. Set the ProductVariationDetailParentId to Guid.Empty.
  8. Add the variation to the product.
    Add the instance of the product variation to the ProductVariations collection of the product.
  9. Save the changes.
    Save the changes to the catalog manager.
Here is a code example:


Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?