Commerce Connect properties
Describes how to access and use specific properties in Optimizely Commerce Connect.
Properties store and present data for content, such as catalog content and blocks.
Use a block as a property in catalog content
Blocks in Optimizely Commerce Connect can be used in code as a property, which reuses 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 catalog content. When a block is used as a property in a catalog content, it is stored, loaded, and versioned with that content.
Add a block as a property
This example assumes 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 you update the corresponding view for the product to display the block as a property.
Example: FabricBlock 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: FabricProduct
[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 "Optimizely Content Management System Developer Guide").
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: 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 CustomerContact 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))]
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<CustomerContact>))]
public virtual IList<CustomerContact> CustomerContactList { get; set; }
}Updated 17 days ago
