Classes for External Entities

Classes for external entities are adapters for the entities of the REST API of the external e-commerce system.

Base Class and Interface

You define a class that derives from the PX.Commerce.Core.BCAPIEntity base class, which implements the PX.Commerce.Core.IExternEntity interface. In this class, you define the properties of the external REST API entity that you need to synchronize with the properties of the entity stored in MYOB Acumatica.

Attributes of the Class and its Properties

You assign the PX.Commerce.Core.CommerceDescription attribute with the name of the entity to the class. Entity names are used as the names of the external objects on the Entities (BC202000) form.

You assign the CommerceDescription attributes to the properties of the class as well. In each attribute, you specify the following parameters:
  • The name of the property, which is used as the name of the external field on the mapping and filtering tabs of the Entities form.
  • Optional: A FieldFilterStatus value, which specifies whether the field is used on the filtering tabs of the Entities form.
  • Optional: A FieldMappingStatus value, which specifies whether the field is used on the mapping tabs of the Entities form.
  • Optional: A String value, which specifies the feature on which the field depends, such as "PX.Objects.CS.FeaturesSet+userDefinedOrderTypes". The field is available on the Entities form if the specified feature is enabled on the Enable/Disable Features (CS100000) form.

You also assign the Newtonsoft.Json.JsonProperty attribute to the properties of the class to map them to the properties of the external entity retrieved in JSON format through the external REST API.

Note: The classes and the communication with the external system depend on the external system.

Example

The following code shows an example of the declaration of a customer entity for the WooCommerce connector.

Tip: You can see this code on GitHub.
using System;
using System.Collections.Generic;
using PX.Commerce.Core;
using Newtonsoft.Json;

namespace WooCommerceTest
{
    [CommerceDescription(WCCaptions.Customer)]
    public class CustomerData : BCAPIEntity, IWooEntity
    {
        [JsonProperty("id")]
        [CommerceDescription(WCCaptions.ID, FieldFilterStatus.Skipped, 
            FieldMappingStatus.Import)]
        public int? Id { get; set; }

        [JsonProperty("date_created")]
        public DateTime? DateCreatedUT { get; set; }

        [CommerceDescription(WCCaptions.DateCreatedUT)]
        [ShouldNotSerialize]
        public virtual DateTime? CreatedDateTime
        {
            get
            {
                return DateCreatedUT != null ? (DateTime)DateCreatedUT.ToDate() : default;
            }
        }

        [JsonProperty("date_modified_gmt")]
        public DateTime? DateModified { get; set; }

        [CommerceDescription(WCCaptions.DateModifiedUT)]
        [ShouldNotSerialize]
        public virtual DateTime? ModifiedDateTime
        {
            get
            {
                return DateModified != null ? (DateTime)DateModified.ToDate() : default;
            }
        }

        [JsonProperty("email")]
        [CommerceDescription(WCCaptions.Email, FieldFilterStatus.Skipped, 
            FieldMappingStatus.Import)]
        [ValidateRequired]
        public string Email { get; set; }

        [JsonProperty("first_name")]
        [CommerceDescription(WCCaptions.FirstName, FieldFilterStatus.Skipped, 
            FieldMappingStatus.Import)]
        [ValidateRequired]
        public string FirstName { get; set; }

        [JsonProperty("last_name")]
        [CommerceDescription(WCCaptions.LastName, FieldFilterStatus.Skipped, 
            FieldMappingStatus.Import)]
        [ValidateRequired()]
        public string LastName { get; set; }

        [JsonProperty("username")]
        [CommerceDescription(WCCaptions.UserName, FieldFilterStatus.Skipped, 
            FieldMappingStatus.Import)]
        public string Username { get; set; }

        [JsonProperty("billing")]
        public CustomerAddressData Billing { get; set; }

        [JsonProperty("shipping")]
        public CustomerAddressData Shipping { get; set; }
    }

    public interface IWooEntity
    {
        DateTime? DateCreatedUT { get; set; }

        DateTime? DateModified { get; set; }

    }
}