Table of Contents

Class VariantService

Namespace
Dynamicweb.Ecommerce.Variants
Assembly
Dynamicweb.Ecommerce.dll

The entry point for working with product variants: creating and deleting variants, managing the variant groups and options a product varies over, and combining separate products into one master product with variants.

public class VariantService
Inheritance
VariantService
Inherited Members

Remarks

This service orchestrates VariantCombinationService, VariantGroupService and VariantOptionService; go to those directly when only one of the three is needed.

Methods

AddGroupToProduct(string, string)

Relates the product to the given variant group so it can vary over that group's options.

public virtual void AddGroupToProduct(string productId, string variantGroupId)

Parameters

productId string

The ID of the product.

variantGroupId string

The ID of the variant group.

Remarks

Every existing variant combination of the product is deleted, as the set of groups has changed.

BuildFamily(string, IEnumerable<string>, string, bool)

Combines the given products into a product family on the master product: one variant group flagged as Family, with one option per product number.

public virtual void BuildFamily(string masterProductId, IEnumerable<string> productIds, string languageId, bool canChangeMasterProduct)

Parameters

masterProductId string

The ID of the product the others become variants of.

productIds IEnumerable<string>

The IDs of the products to combine onto the master product.

languageId string

The ID of the language the combine is performed in.

canChangeMasterProduct bool

When true, the master product may itself become a variant, which also clears its product number and EAN.

Remarks

Prices, stock, assets, comments, favourites, assortments and audit entries follow the products onto their new variant keys. The work runs in a transaction when /Globalsettings/Ecom/Product/UseTransactionsInCombine is enabled; failures are logged and the affected caches cleared rather than thrown.

BuildFamilyAsVariants(string, List<ProductInfo>, List<string>)

Combines the given products into variants of the master product over the given variant groups, using the variant options already assigned to each product.

public virtual void BuildFamilyAsVariants(string masterProductId, List<CombineProductsData.ProductInfo> productCombinationInfos, List<string> variantGroupIds)

Parameters

masterProductId string

The ID of the product the others become variants of.

productCombinationInfos List<CombineProductsData.ProductInfo>

The products to combine, each carrying the variant options it ends up on.

variantGroupIds List<string>

The IDs of the variant groups the master product should vary over.

Remarks

Unlike BuildFamily(string, IEnumerable<string>, string, bool) the variant options are taken from productCombinationInfos rather than generated from product numbers, and the master product's number and EAN are always cleared. The combine runs in the default language.

ClearCache()

Clears all caches used by everything related to variants

public virtual void ClearCache()

ClearVariantCombinationCache()

Clears the variant combination cache.

public virtual void ClearVariantCombinationCache()

ClearVariantGroupCache()

Clears the cache for variant groups

public virtual void ClearVariantGroupCache()

ClearVariantGroupOptionValuesCache()

Clears the variant group option values

public virtual void ClearVariantGroupOptionValuesCache()

ClearVariantGroupProductRelationCache()

Clears the variant group product relations

public virtual void ClearVariantGroupProductRelationCache()

ClearVariantGroupPropertiesCache()

Clears the cache for variant group properties

public virtual void ClearVariantGroupPropertiesCache()

ClearVariantOptionsCache()

Clears the cache for variant options

public virtual void ClearVariantOptionsCache()

CreateExtendedVariant(Product, IEnumerable<string>)

Creates an extended variant of the product for the given variant options, i.e. a variant combination plus a product row of its own that can carry variant-specific values.

public virtual void CreateExtendedVariant(Product product, IEnumerable<string> optionIds)

Parameters

product Product

The product to save as the variant. Its values become the variant's values.

optionIds IEnumerable<string>

The IDs of the variant options making up the variant, one per variant group.

Exceptions

ArgumentNullException

product is null.

CreateSimpleVariant(string, IEnumerable<string>)

Creates a simple variant of the product for the given variant options, i.e. a variant combination without a product row of its own.

public virtual void CreateSimpleVariant(string productId, IEnumerable<string> optionIds)

Parameters

productId string

The ID of the product.

optionIds IEnumerable<string>

The IDs of the variant options making up the variant, one per variant group.

Delete(VariantGroup)

Deletes the given variant group, its options, and the product variants built on those options. Does nothing when group is null.

public virtual void Delete(VariantGroup group)

Parameters

group VariantGroup

The variant group to delete.

Delete(VariantOption)

Deletes the given variant option along with its property values and every variant product and combination built on it. Does nothing when variantOption is null.

public virtual void Delete(VariantOption variantOption)

Parameters

variantOption VariantOption

The variant option to delete.

DeleteAllVariants(string)

Deletes every variant combination of a product.

public virtual void DeleteAllVariants(string productId)

Parameters

productId string

The ID of the product.

DeleteVariant(string, string)

Deletes one variant combination of a product.

public virtual void DeleteVariant(string productId, string variantId)

Parameters

productId string

The ID of the product.

variantId string

The ID of the variant combination.

DeleteVariantGroup(string)

Deletes the variant group with the given ID, its options, and the product variants built on those options.

public virtual void DeleteVariantGroup(string variantGroupId)

Parameters

variantGroupId string

The ID of the variant group.

DeleteVariantOption(string)

Deletes the variant option with the given ID, along with its property values and every variant product and combination built on it.

public virtual void DeleteVariantOption(string variantOptionId)

Parameters

variantOptionId string

The ID of the variant option.

ExtendAllVariants(Product)

Turns every simple variant combination of the product into an extended variant, giving each one a product row of its own.

public virtual void ExtendAllVariants(Product product)

Parameters

product Product

The master product whose combinations are extended.

GetAllOptions()

Gets every variant option whose variant group still exists, ordered by sort order and then by ID.

public virtual IEnumerable<VariantOption> GetAllOptions()

Returns

IEnumerable<VariantOption>

All variant options in use. Options left behind by a deleted group are skipped.

GetOptions(string, VariantGroup)

Gets the options from the given variant group that the product actually has variant combinations for.

public virtual IList<VariantOption> GetOptions(string productId, VariantGroup variantGroup)

Parameters

productId string

The ID of the product.

variantGroup VariantGroup

The variant group.

Returns

IList<VariantOption>

The subset of the group's options that are in use on the product, in sort order.

Exceptions

ArgumentNullException

variantGroup is null.

GetOptions(string, string)

Gets the options from the given variant group that the product actually has variant combinations for.

public virtual IList<VariantOption> GetOptions(string productId, string variantGroupId)

Parameters

productId string

The ID of the product.

variantGroupId string

The ID of the variant group.

Returns

IList<VariantOption>

The subset of the group's options that are in use on the product, in sort order.

GetVariantGroup(string)

Gets the variant group with the given ID.

public virtual VariantGroup? GetVariantGroup(string variantGroupId)

Parameters

variantGroupId string

The ID of the variant group.

Returns

VariantGroup

The variant group, or null when no group has that ID.

GetVariantName(string, string?)

Gets the display name of a variant, composed from the names of the variant options it is made of.

public virtual string GetVariantName(string variantId, string? languageId = null)

Parameters

variantId string

The ID of the variant combination, i.e. the option IDs joined by ".".

languageId string

The ID of the language to get the option names in. The current ecommerce context language is used when omitted.

Returns

string

The option names joined by CombinationTextSeparator, or an empty string when variantId is empty.

PotentialVariantCount(string)

Counts how many variants the product could have, i.e. the product of the option counts of the variant groups it is related to. Groups with a single option do not multiply the count.

public virtual ulong? PotentialVariantCount(string productId)

Parameters

productId string

The ID of the product.

Returns

ulong?

The number of possible variants, or null when it exceeds 10,000,000 or the multiplication overflows.

RemoveAllGroupsFromProduct(string)

Removes every variant group relation from the product, and deletes its variant combinations.

public virtual void RemoveAllGroupsFromProduct(string productId)

Parameters

productId string

The ID of the product.

Remarks

Variant products (the product rows of extended variants) are not deleted, so they are left without a relation to the master. Delete them first with DeleteVariantsByProductIdAndVariantIds(string, ICollection<string>) when the product should no longer vary at all.

RemoveGroupFromProduct(string, string)

Removes the relation between the product and the given variant group.

public virtual void RemoveGroupFromProduct(string productId, string variantGroupId)

Parameters

productId string

The ID of the product.

variantGroupId string

The ID of the variant group.

Remarks

Every existing variant combination of the product is deleted, as the set of groups has changed.

Save(VariantCombination)

Saves the given variant combination and puts it in the cache.

public virtual void Save(VariantCombination variantCombination)

Parameters

variantCombination VariantCombination

The variant combination to save.

Save(VariantGroup)

Saves the given variant group.

public virtual void Save(VariantGroup group)

Parameters

group VariantGroup

The variant group to save.

Save(VariantOption)

Saves the given variant option.

public virtual void Save(VariantOption variantOption)

Parameters

variantOption VariantOption

The variant option to save.

Save(IEnumerable<VariantCombination>)

Saves the given variant combinations in one batch.

public virtual void Save(IEnumerable<VariantCombination> variantCombinations)

Parameters

variantCombinations IEnumerable<VariantCombination>

The variant combinations to save.

Remarks

Unlike Save(VariantCombination) this does not update the cache; clear it with ClearVariantCombinationCache() when the saved combinations must be visible to subsequent reads.

To top