Optimizely Graph for Commerce Connect
Describes how to configure Optimizely Graph for Commerce Connect
Optimizely Graph for Commerce Connect connects your Commerce Connect catalog data to Optimizely Graph, so you can query products, variants, bundles, and packages with GraphQL and aggregate values from variations into product-level fields.
Get started
- Install the
Optimizely.ContentGraph.CmsNuGet package. - Install the
Optimizely.Graph.CommerceNuGet package. - Add the following code to the
ConfigureServicesmethod inStartup.cs:services.AddContentDeliveryApi(); services.AddContentGraph(x => { x.IncludeInheritanceInContentType = true; x.PreventFieldCollision = true; }); services.AddCommerceGraph(); - Add the namespace:
using Optimizely.Graph.Commerce; - Add the
Optimizelysetting at the same level asEPiServerinappsettings.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. On first run, the site executes data migration and then displays the homepage.
- Go to
GraphQLAdminto clear all previously synced data. - Run the Optimizely Graph content synchronization job to sync data.
- Go to
GraphiQLto write queries that fetch data.
Aggregate data for product content
Aggregate property values from product variations to the parent product. For example, aggregate custom properties such as Size and Color from VariationContent to Sizes and Colors on ProductContent by inheriting from ProductAggregationContentApiModelBase.
[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 the Optimizely.Graph.Commerce package, so you can create the class in your commerce site and inherit from it.
NoteIn some 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 scheduled job runs.
See the Product Listing Page - using Graph blog post for more information.
Configure the Optimizely Graph search provider
The Graph search provider for Commerce Connect lets you search products, variants, bundles, and packages directly through Optimizely Graph.
To use this search functionality, configure Optimizely.Graph.Commerce as described previously.
Install Optimizely.Graph.Commerce in your Commerce Connect project, then configure it. Update appsettings.json as follows:
"Commerce": {
"SearchOptions": {
"DefaultSearchProvider": "CommerceGraphSearchProvider",
"SearchProviders": [
{
"Name": "CommerceGraphSearchProvider",
"Type": "Optimizely.Commerce.GraphSearchProvider.CommerceGraphSearchProvider, Optimizely.Commerce.GraphSearchProvider",
"Parameters": {
"queryBuilderType": "Optimizely.Commerce.GraphSearchProvider.GraphSearchQueryBuilder, Optimizely.Commerce.GraphSearchProvider.GraphSearchQueryBuilder",
"simulateFaceting": "true"
}
}
]
},
}Index data
The Optimizely Graph content synchronization job indexes products, variants, bundles, and packages into Graph. Because this project references Optimizely.Graph.Commerce, it inherits the enhanced data structure and additional information provided by that package. After indexing, you can access the data with GraphQL queries.
NoteThis method does not yet support the implementation of
Mediachase.Commerce.Searchindexing. Instead, you must rely on the Optimizely Graph content synchronization job to index and manage commerce data within Graph.
Search data
After you install and configure Optimizely.Commerce.GraphSearchProvider in appsettings.json, it is available as one of the search providers. To make it the default for your commerce system, set its name as the DefaultSearchProvider configuration value.
Based on Mediachase.Search, this provider converts search requests into GraphQL queries through a customized implementation of ISearchQueryBuilder. It communicates with the Optimizely Graph server to fetch enriched commerce data in real time, delivering a GraphQL-powered search experience for your commerce solution with minimal configuration.
Scope of search
- Global search
- Catalog panel
- Add Line Item dialog (Order Management)
Supported specialized properties
PropertyDictionarySinglePropertyDictionaryMultiple
Current limitations
In version 1.0.0 of GraphSearchProvider, the IncludeInDefaultSearch attribute is not supported. Ideally, only properties marked with this attribute should be searchable. The provider currently falls back to full-text search, which makes all string-typed properties searchable regardless of the attribute.
Updated 20 days ago
