Add custom fields for product variations

The Ecommerce module enables you to create variations of products based on product attributes. If you want to characterize a product variation with additional information, you can add a custom field for the product variations. For example, you are creating variations for t-shirts. In addition to size or color, you may want to add the location of the product variation if, say, different variations are stored at different warehouses.

To do this, you need to create a MetaType (if one does not exist already) and then a MetaField that is to store the product variations additional data. As a result, MetaField information is stored in a new column in the database. Next, you extend the backend definition of product variations by updating the insert and edit views. Thus, when you create a new variation in the backend, you see the new custom field and can modify it to enter a value.

In the current example, you create a custom field BinLocation of type String that enables you to enter the location of product variations.

  1. Create MetaType and MetaField.
    You create a new MetaType, only if one does not exist. The code checks whether a MetaType exists for the ProductVariations type and, in case none is found, it creates a new MetaType.

    You create a MetaField of type string and name it BinLocation.

  2. Update the product variations definitions.
    You first modify the backend insert view for product variations, so that when you create variations, you can set the BinLocation custom field.
  3. Modify the backend edit view for product variations.
    You do this, so that when you edit variations, you can edit the BinLocation custom field.

Use the following code sample:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?