Class SchemaOrgFieldMappingService
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog.SchemaOrg
- Assembly
- Dynamicweb.Ecommerce.dll
Manages the configured mappings of Dynamicweb product fields to Schema.org Product properties.
public abstract class SchemaOrgFieldMappingService
- Inheritance
-
SchemaOrgFieldMappingService
- Inherited Members
Remarks
A configured mapping replaces the built-in mapping of that property when the Schema.org Product model is generated for a product. Properties without a mapping keep the built-in behaviour.
Register an implementation of this type to keep the configuration somewhere other than the EcomSchemaOrgMapping table; SchemaOrgProductFactory reads the mappings through this type.
Methods
DeleteByIds(IEnumerable<int>)
Deletes the mappings that match the given IDs.
public abstract void DeleteByIds(IEnumerable<int> mappingIds)
Parameters
mappingIdsIEnumerable<int>The IDs of the mappings to delete.
Exceptions
- ArgumentNullException
Thrown when
mappingIdsisnull.
EnsureMappedFieldsAreFilled(ProductViewModelSettings)
Adds the product view model properties and fields the configured mappings need, so a mapped custom or category field is populated on the product view model and can be written to the JSON-LD output.
public abstract void EnsureMappedFieldsAreFilled(ProductViewModelSettings settings)
Parameters
settingsProductViewModelSettingsThe settings to add the required properties to.
Remarks
ViewModelFactory calls this when it creates a product or a product list view model, so a caller only needs it when a product view model is created another way; favorite lists, orders and carts are not covered. Call it after the settings have been configured and before the view model is created. Only the mappings that apply to the language of the settings are taken into account, and a field property the settings did not ask for is populated with the mapped fields only. When no such mapping uses a custom or category field, the settings are left untouched.
Exceptions
- ArgumentNullException
Thrown when
settingsisnull.
GetAll()
Gets all configured mappings, ordered by property and sort order.
public abstract IEnumerable<SchemaOrgFieldMapping> GetAll()
Returns
- IEnumerable<SchemaOrgFieldMapping>
The configured mappings.
GetById(int)
Gets the mapping with the given ID.
public abstract SchemaOrgFieldMapping? GetById(int id)
Parameters
idintThe mapping ID.
Returns
- SchemaOrgFieldMapping
The mapping, or
nullwhen no mapping has the given ID.
GetByProperty(SchemaOrgProductProperty)
Gets all mappings configured for the given Schema.org Product property, across all languages.
public abstract IEnumerable<SchemaOrgFieldMapping> GetByProperty(SchemaOrgProductProperty productProperty)
Parameters
productPropertySchemaOrgProductPropertyThe property to get the mappings for.
Returns
- IEnumerable<SchemaOrgFieldMapping>
The mappings configured for the property.
GetMappingsByProperty(string?)
Gets the mappings that apply in the given language, grouped by property. A mapping for the specific language takes precedence over a mapping that applies to all languages.
public abstract IReadOnlyDictionary<SchemaOrgProductProperty, IReadOnlyList<SchemaOrgFieldMapping>> GetMappingsByProperty(string? languageId)
Parameters
languageIdstringThe language the mappings are resolved for.
Returns
- IReadOnlyDictionary<SchemaOrgProductProperty, IReadOnlyList<SchemaOrgFieldMapping>>
The mappings that apply, grouped by property.
Remarks
For most properties the mappings for the specific language replace all mappings of the property for all languages. For AdditionalProperty, where each mapping is a characteristic of its own, a mapping for the specific language only replaces the mapping of the same source field.
Save(SchemaOrgFieldMapping)
Saves the mapping. A mapping without an ID is created, an existing mapping is updated.
public abstract void Save(SchemaOrgFieldMapping mapping)
Parameters
mappingSchemaOrgFieldMappingThe mapping to save.
Exceptions
- ArgumentNullException
Thrown when
mappingisnull.