Optimizely Graph for Commerce Connect
Describes how to configure Optimizely Graph for Commerce Connect
Prerequisites
- .NET 6
- NodeJS equal or greater than v20.14.0
- yarn
- Optimizely Commerce Connect equal or greater than v14.26.0
Solution structure
- EPiServer.Reference.Commerce.Site – The site where Optimizely Graph is installed. Commerce data is synced to the Optimizely Graph server from here.
- Optimizely.Graph.Commerce – The connector for Commerce Connect and Optimizely Graph. This project is packed in a Nuget package.
- ClientApp – React client application for consuming Optimizely Graph. This is a small sample client app for querying data, using facets and search phrases.
Get started
- Install
Optimizely.ContentGraph.Cms
. - Install
Optimizely.Graph.Commerce
. - Add the following code snippet to
ConfigureServices
method inStartup.cs
:services.AddContentDeliveryApi(); services.AddContentGraph(x => { x.IncludeInheritanceInContentType = true; x.PreventFieldCollision = true; }); services.AddCommerceGraph();
- Add namespace.
using Optimizely.Graph.Commerce;
- Add Optimizely setting as the same level as Episerver in
appsetting.json
."Optimizely": { "ContentGraph": { "GatewayAddress": "https://cg.optimizely.com", "AppKey": "{your-app-key}", "Secret": "{your-secret}", "SingleKey": "{your-single-key}", "AllowSendingLog": "true" } }
- Build the solution.
- Prepare the database.
- Run the site. The first time the site is ran the site executes data migration and the homepage displays when done.
- Go to
GraphQLAdmin
to clear all previous synced data. Go to the Optimizely Graph content synchronization job to start syncing data. Go toGraphiQL
to write queries to fetch data.
Aggregate data for product content
With Optimizely Graph for Commerce Connect, you can aggregate propety values from product variations. For example, aggregate the Size and Color from VariationContent
to Sizes and Colors for ProductContent
by inheriting from the ProductAggregationContentApiModelBase
class.
[ServiceConfiguration(typeof(IContentApiModelProperty), Lifecycle = ServiceInstanceScope.Singleton)]
public class SizeContentApiModel : ProductAggregationContentApiModelBase<string, GenericProduct, GenericVariant>
{
public SizeContentApiModel(ContentTypeModelRepository contentTypeModelRepository, IContentLoader contentLoader)
: base(contentTypeModelRepository, contentLoader)
{
}
public override string Name => "Sizes";
protected override Expression<Func<GenericVariant, string>> VariationProperty => (x) => x.Size;
}
[ServiceConfiguration(typeof(IContentApiModelProperty), Lifecycle = ServiceInstanceScope.Singleton)]
public class ColorContentApiModel : ProductAggregationContentApiModelBase<string, GenericProduct, GenericVariant>
{
public ColorContentApiModel(ContentTypeModelRepository contentTypeModelRepository, IContentLoader contentLoader)
: base(contentTypeModelRepository, contentLoader)
{
}
public override string Name => "Colors";
protected override Expression<Func<GenericVariant, string>> VariationProperty => (x) => x.Color;
}
The ProductAggregationContentApiModelBase
class is in Optimizely.Graph.Commerce
package, so you can create the class from your commerce site and inherit this class.
Notes
In some edge cases, such as deleting a market or a warehouse, the data from variants or packages using that market or warehouse is not synced until the Content Graph Indexing Schedule Job runs.
References
See the Product Listing Page - using Graph blog post for information.
Updated about 2 months ago