Try our conversational search powered by Generative AI!

Products that share fields


If different types of products share common fields, whats the best way to implement this for Commerce?

For example, I have two products that both require Contact Firstname and Contact Surname fields.

Simple inheritance - with product types inheriting from a class containing the shared fields which in turn inherits from EPiServer.Commerce.Catalog.ContentTypes.ProductContent?

Or can a custom type be defined to encapsulate a Contact, and our product types have a public property of that type?

Jul 23, 2015 16:07

I think the first option is the way to go. C# does not allow multiple inheritance anyway.

You can extract as many shared properties as possible, put them in an abstract class - inherited from ProductContent or VariationContent, then inherit from that class.

One other option is to define a IContact interface. You will still need to implement the properties in your catalog content types, but your business code can now only care about the interface, and forget about the actual type.



Jul 23, 2015 17:20


To clarify, my second diagram doesn't show mutliple inheritance - it shows my products composed of a Contact, something like:

public class Contact()
    public string Firstname { get; }
    public string Surname { get; }

public class ProductTypeA: VariationContent
    public string Description { get; }
    public Contact Who { get; }

I guess you'd need a custom meta type or something for Commerce to be able to undertsand how to render the Contact type?


Edited, Jul 23, 2015 18:20

For easier mapping between metafields and properties, I would recommend to use primitive types, instead of composed types. Otherwise you might have to override a lot of code (which I'm not sure possible, we don't recommend it anyway)


Jul 23, 2015 18:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.