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
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]https://docs.developers.optimizely.com/content-cloud/v12.0.0-content-cloud/docs/using-a-block-as-a-property "Optimizely Content Management System Developer Guide").
Generic PropertyList(PropertyList)
PropertyList is a property that lets define an editable list of objects. The content model can implement a property of type IList, 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; }
}
Updated 5 months ago