Deleting variations
To delete a variation, you must perform the following:
- Get an instance of the catalog manager.
Get an instance of the CatalogManager object.
- Get the variation detail for the specified variation.
To get the variation detail, call the GetProductVariationDetails method of the manager and filter the collection by the ID of the variation.
- Mark the variation detail for deletion.
To mark the detail to be deleted, call the DeleteProductVariationDetail method of the manager and pass the ID of the detail as an argument.
- Mark the variation for deletion.
To mark the variation to be deleted, call the DeleteProductVariation method of the manager and pass the ID of the variation as an argument.
- Save the changes.
To delete the variation, save the changes to the manager.
TIP: To delete multiple variations, query them and execute the code below for each one of them.
Here is a code example:
public static void DeleteVariation(Guid variationId)
{
CatalogManager catalogManager = new CatalogManager();
var detail = catalogManager.GetProductVariationDetails().Where(d => d.ProductVariationParent.Id == variationId).SingleOrDefault();
catalogManager.DeleteProductVariationDetail(detail.Id);
catalogManager.DeleteProductVariation(variationId);
catalogManager.SaveChanges();
}