/
Enabling Variant Support in ECommerce API

Enabling Variant Support in ECommerce API

Enabling variants in ECommerce API requires five “things” to be done:

  1. A new feature must be added to and set on all items that are either products or variants, to tell EC which are products and which are variants. .

  2. A new feature must be added to and set on all items that are a variant that tells which product is this a variant of.

  3. Mappings for these must be created.

  4. Variant support should be enabled in Settings.

  5. (Optional) In case you want variants in multiple dimensions a few more features/mappings are needed.

The above seems quite a bit, but it is actually quite simple to do. The biggest task lies in modifying the data correctly.

The following sections describe how each of the 5 above steps are carried out:

Adding features to Product

ECommerceType

EC needs a feature that holds the value “Product” on all Perfion Items that are reckoned Products and “Variant” on all items that are reckoned variants. As part of the Auto Creating-features, a feature named  ECommerceType has already been created for this purpose. This feature should simply be added to the configuration of the base feature holdings Products and filled out on all Perfion items that are either products and variants. Items not representing neither a product nor a variant should have this field blank (but they may have any value not being “Product” and “Variant”).

ECommerceVariantOfProduct

This mapping should be added to the configuration of “Products” and filled out on both products and variants. Note: The value has to be identical to the KeyField-value of which product it is a variant of, so it is important to check the mapping in order to verify which feature is mapped as KeyField product entity.
As part of the auto-creating of features such a feature has already been created. It is called ECommerceVariantOfProduct.

Both ECommerceType and ECommerceVariantOfProduct has been added to the configuration on Product and filled out on the jugs as shown in Figure 1 below.

 

Figure 1: The jugs have been made variants

Note how the item with base value “EM77” has been designated the ECommerceType “Product” while all the Jugs below it has been designated the ECommerceType “Variant”. Note further how all the variants as value of the  ECommerceVariantOfProduct-feature points to “EM77” because they are variants of exactly that product.

It is a requirement that a variant must be child of its product. It is not a requirement, however, that it must be an immediate child. It is OK to have virtual nodes in between the product virtual node and its variants (although there are no such virtuals in the figure).

It is important to note, that even products that does not have any variants also need to have its ECommerceType set to Product. Otherwise they will be ignored by EC. Perfion Items having their ECommerceType set to anything but “Product” or “Variant” will simply be ignored by EC as soon as variant-support is enabled.

Adding mappings to the Product- and Variant-entities

With data in place, the necessary mappings can be created. Consider the product-mappings in Figure 37.

Figure 2: Added mappings needed to support variants

The first new mapping added is the ECommerceType mapping. The Ecommerce Output Kind is exactly the feature of the same name. This tells EC that it should use this feature to figure out what is products and what is variants. Note: It is OK only to map this on entity Product and not on both Product and Variant. Note further, that this mapping does not output anything, so anything typed in “ECommerce To” will be ignored.

The next one for Ecommerce OutputKind is VariantOfProduct. This is mapped on entity Variant and tells EC where it for all variants can find their products. This also is not output, so an ECommerceTo is not needed.

The last two mappings added are for entity variant, simply to output data on the individual variants. As can be seen we simply output Title and Item No.

Enabling Variants

Enabling variants is simply done by setting the setting VariantSupportEnabled to the value True. See more in section VariantSupportEnabled.

Querying products with variants

Querying products works the same, regardless of products have variants or not. Consider the following query:

<Execute method="GetProducts" refreshconfiguration="true">   <Parameter id="Channel" value="My Channel" />   <Parameter id="Keys" value="EM77" />   <Parameter id="IncludeMappings">     <Value>Item No</Value>     <Value>Title</Value>   </Parameter> </Execute>

This will output the product with Key-value EM77. Now this product has variants, so it will look like this:

<Response>   <Result>     <Channel name="My Channel">       <TotalCount>1</TotalCount>       <Products>         <Product id="721" ecommerceproduct="EM77">           <Fields>             <Field name="Item No">EM77</Field>           </Fields>           <Variants>             <Variant id="625" ecommerceproduct="EM77" ecommercevariant="978ST">               <Fields>                 <Field name="Title" culture="en-US">Vacuum Jug EM77  Chalk</Field>                 <Field name="Item No">978ST</Field>               </Fields>             </Variant>             <Variant id="626" ecommerceproduct="EM77" ecommercevariant="980ST">               <Fields>                 <Field name="Title" culture="en-US">Vacuum Jug EM77  Olive</Field>                 <Field name="Item No">980ST</Field>               </Fields>             </Variant> <Variant id="627" ecommerceproduct="EM77" ecommercevariant="958ST">               <Fields>                 <Field name="Title" culture="en-US">Vacuum Jug EM77  Purple</Field>                 <Field name="Item No">958ST</Field>               </Fields>             </Variant>             ... more variants ...          </Variants>         </Product>       </Products>     </Channel>   </Result> </Response>

When querying products with variants the IncludeMappings and ExcludeMappings-parameters allow you prefix the FieldNames with the name of entity. The following query will include Item No on products and both Item No and Title on the variants.