Commerce Connect integration with PIM

  • Updated

This topic describes how to install and configure Optimizely Product Information Management (PIM) for Optimizely Commerce Connect. With the PIM integration, you can manage detailed product information and synchronize the data to Commerce Connect. 

About the PIM

The PIM is built for convenient management of detailed product information for your commerce site, including item information like size, weight, color and associated images. You can quickly set up catalog and product data requirements and efficiently manage the data acquisition and curation process. 

The diagram below shows how the PIM processes data by receiving, updating, approving and passing the data into Commerce Connect with a scheduled job.

PIM-B2C_data_flow.png

Installation and configuration

To add the PIM integration, install the EPiServer.Commerce.PIM NuGet package to your Optimizely Commerce Connect site.

The EPiServer.Commerce.PIM integration NuGet package contains a set of scheduled jobs for data synchronization. 

Configuration settings

After installing the package, add these configuration settings to the <appSettings> section in the web.config or appsettings.json file, and define values as described in the following.

web.config

<appSettings>
<add key="episerver:PIM.Environment" value="" />
<add key="episerver:PIM.ClientId" value="" />
<add key="episerver:PIM.ClientSecret" value="" />
<add key="episerver:PIM.NumberOfLookbackDays" value="" />
<add key="episerver:PIM.APIAddress" value="" />
<add key="episerver:PIM.TokenEndpoint" value="" />
</appSettings>

appsettings.json

"Commerce": { 
"PIMOptions": {
"Environment": "",
"AppKey": "",
"SecretKey": "",
"NumberOfLookbackDays": "",
"APIAddress": ""
}
} 

Configuration keys

Key Description
episerver:PIM.Environment

Values: Production or Sandbox.
Setting for current site environment.

This must match the setting in PIM > Configure > Settings > Active Publishing Environment

episerver:PIM.ClientId Client ID key to connect to the PIM API. 
episerver:PIM.ClientSecret Client Secret key to connect the PIM API. 
episerver:PIM.NumberOfLookbackDays Number of days used in Refresh mode to get product records based on the published date. The default value is 5 days
episerver:PIM.APIAddress Root URL of the PIM API endpoint.

 

Scheduled jobs

The PIM integration package contains a set of three scheduled jobs for managing data synchronization with Commerce Connect. Scheduled jobs are managed from the CMS Admin view.

Synchronize setup data

PIM: Synchronize setup data pushes information about your catalog and product types to the PIM. You should run the job any time you have made changes to content types or properties that have Commerce Connect attributes (for example, PIMSync). Run the job from a Sandbox or Production instance, not a partner QA site, including when new languages, websites, relationship types or product custom properties are added. 

Publish approved products

PIM: Publish approved products should be run whenever you want Approved products to be pulled into the active environment of your choice - either Sandbox (early in the project), or Production (once live). It pulls in products with the status Approved, and then updates the status in the PIM to Published. The job is typically set as recurring but can also be run on-demand. 

Refresh published products

PIM: Refresh published products keeps non-production environments synced with the PIM as needed. It uses the lookback days parameter in the job to pull in products with Published status, and then based on the date last published into the environment you are running the job from. You also can use this for development environments. It should typically only be run on-demand.

Import content from the PIM

You can add logic to create specific types of content from the PIM.

Create nodes

Implement the interface ICategoryNodeFactory to override the creation of categories/nodes. Use IContentEvents.PublishingContent to set properties on the new node.

Example:

public class CustomNodeContent : NodeContent { }

public class CustomCategoryNodeFactory : ICategoryNodeFactory
{
    private readonly IContentRepository _contentRepository;

    public CustomCategoryNodeFactory(IContentRepository contentRepository) => _contentRepository = contentRepository;

    public NodeContent Create(NodeContentBase parentNodeContent) => _contentRepository.GetDefault<CustomNodeContent>(parentNodeContent.ContentLink, parentNodeContent.MasterLanguage);
}

//Register your custom node factory  
services.AddSingleton<ICategoryNodeFactory, MyCustomCategoryNodeFactory>();

Create media files

Implement the interface IMediaFileFactory to override the creation of media files and image files. Use IContentEvents.PublishingContent to set properties on the new instance.

Example:

public class CustomCommerceImageFile : CommerceImageFile { }

public class CustomCommerceMediaFile : CommerceMediaFile { }

public class CustomMediaFileFactory : IMediaFileFactory
{
    private readonly IContentRepository _contentRepository;

    public CustomMediaFileFactory(IContentRepository contentRepository) => _contentRepository = contentRepository;

    public CommerceImageFile CreateImageFile(ContentReference folderLink, string name) => _contentRepository.GetDefault<CustomCommerceImageFile>(folderLink);

    public CommerceMediaFile CreateMediaFile(ContentReference folderLink, string name) => _contentRepository.GetDefault<CustomCommerceMediaFile>(folderLink);
}

//Register your custom media file factory  
services.AddSingleton<IMediaFileFactory, MyCustomMediaFileFactory>();