Loading...
Area: Episerver Commerce
Applies to versions: 10 and up

Commerce properties

Recommendations [hide]

This topic explains how to access and use specific properties in Episerver Commerce. Properties store and present data for content, such as catalog content and blocks.

In this topic

Using a block as a property in catalog content

Blocks in Episerver Commerce can be used in code as a property, which is a convenient way to reuse a set of properties in multiple instances. This topic describes how to add and render an existing block as a property in an existing catalog content type.

Blocks can only be rendered in the context of other content, such as a catalog content. When a block is used as a property in a catalog content, it is stored, loaded and versioned with that content.

Adding a block as a property

Here we assume existing catalog content "FabricProduct," to which you want to add an existing block type "FabricBlock". The block has a FabricName property of type String, and an Image property of type ContentReference. The product content, "FabricProduct," will have the block as a property, and we will update the corresponding view for the the product to display the block as a property.

Example: The Fabric block type.

[ContentType(DisplayName = "FabricBlock", GUID = "119EE80A-525B-479D-A838-6B4E0A903147")]
 public class FabricBlock : BlockData
   {
     public virtual String FabricName {get; set;}
     public virtual ContentReference Image {get; set;} 
   }

Example: The Fabric product.

CatalogContentType( GUID = "485DFA88-E6D3-4CEF-9257-4A6346C1EE29",
                    MetaClassName = "FabricProduct",
                    DisplayName = "Fabric product")]
public class FabricProduct : ProductContent
  {
    public virtual FabricBlock FabricProductBlock { get; set; }
  }

See also Using a block as a Property.

Generic PropertyList(PropertyList<T>)

PropertyList is a property that lets define an editable list of objects. The content model can implement a property of type IList<T>, where T is a class with property definitions.

Example of PropertyList in catalog content

This example shows how to implement a list of customer contacts on a product. The list contains items with string and int properties.
First, define the "CustomerContact" model class.

public class CustomerContact
  {
    public string Name { get; set; }
    public string Email {get; set; }
    public int Age { get; set; }
    public int PhoneNumber { get; set; }
  }

Next, register the property definition. It uses a property class that sets the generic type to Customer Contact item class.

[PropertyDefinitionTypePlugIn]
public class CustomerContactListProperty : PropertyList<CustomerContact>
  {
  }

Finally, add the list of customer contacts on the product.

[CatalogContentType(MetaClassName = "NodeContentWithPropertyList")]
public class NodeContentWithPropertyList : NodeContent
  {
   [BackingType(typeof(PropertyCustomerContactList))]
    public virtual IList<CustomerContact> CustomerContactList { get; set; }
  }

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: May 07, 2019

Recommendations [hide]