How toDeveloper Guide

Developer Guide

Sana Commerce 9.0
Your connector

Extend the Product Entity with a New Property

In order to code in a more convenient way with a new data you can add a new property to the 'Product' entity.
The easiest way to store the value of the custom field in the database is to add the 'XmlField' attribute to the property. This means that the value of the property will be stored in the database as the xml field of the product entity and will be loaded when the product entity is loaded.

Step 1: You should extend the product class:

public class ExtendedProduct: Sana.Commerce.Catalog.Product, IExtendedProduct
{
[XmlField]
public string Comments { get; set; }
}

Step 2: Register new product class for the 'IProduct' interface:
Replace the following string in the 'RegisterTypes' function of the 'Sana.Commerce.Sdk.WebApplication' class:

ObjectManager.RegisterType<IProduct, Product>();

with

ObjectManager.RegisterType<IProduct, ExtendedProduct>();

Extend the 'ICatalogXmlParser' implementation in order to get a value of the field from xml and put it to the new property of the 'ExtendedProduct' class.
Create a new class inherited from the 'Sana.Commerce.Provider.Navision.Catalog.CatalogXmlParser' class.
Register the new class in the 'RegisterTypes' function of the 'Sana.Commerce.Sdk.WebApplication' class:

ObjectManager.RegisterType<ICatalogXmlParser, ExtendedCatalogXmlParser >();

Step 3: Override the 'ReadProductDefaultFields' function:

public class ExtendedCatalogXmlParser: Sana.Commerce.Provider.Navision.Catalog.CatalogXmlParser
{
protected override void ReadProductDefaultFields(IProduct result, TypedValueDictionary fields, XElement element)
{
base.ReadProductDefaultFields(result, fields, element);
((ExtendedProduct)result).Comments = fields.ReadString("Comments");
}
}
How toDeveloper Guide