Connector Implementation: Mapping Classes
For each pair of an internal entity and an external entity that should be synchronized, you need to implement a mapping class, which defines the correspondence between the properties of the internal and external entities.
Base Class and Interfaces
The mapping class implements the following interfaces:
- PX.Commerce.Core.IMappedEntity: Represents the mapping between the properties of the local and external objects
- PX.Commerce.Core.IMappedEntityExtern<ExternType>: Provides methods for the addition of an external entity to the mapping
- PX.Commerce.Core.IMappedEntityLocal<LocalType>: Provides a method for the addition of an internal entity to the mapping
The MappedEntity<ExternType,
LocalType> class provides the default implementation of these interfaces.
The class also provides the default constructors from which you can derive the constructors
of the mapping classes. These constructors use the following as input parameters:
- A
string
identifier of the mapped entities, which is exactly two characters long - A
string
identifier of the connector, which is defined in the ConnectorType property of the connector class
Example
The following code shows an example of the implementation of a mapping class.
Tip:
You can see this code on GitHub.
using System;
using PX.Commerce.Core;
using PX.Commerce.Core.API;
namespace WooCommerceTest
{
public class MappedCustomer : MappedEntity<CustomerData, Customer>
{
public const string TYPE = BCEntitiesAttribute.Customer;
public MappedCustomer()
: base(WooCommerceConnector.TYPE, TYPE)
{ }
public MappedCustomer(Customer entity, Guid? id, DateTime? timestamp)
: base(WooCommerceConnector.TYPE, TYPE, entity, id, timestamp) { }
public MappedCustomer(CustomerData entity, string id,
DateTime? timestamp)
: base(WooCommerceConnector.TYPE, TYPE, entity,
id, id,timestamp) { }
}
}