Optimizely Graph for Commerce Connect
Describes how to configure Optimizely Graph for Commerce Connect
Optimizely Graph for Commerce
Prerequisites
Get started
- Install
Optimizely.ContentGraph.Cms
from Optimizely Nuget package. - Install
Optimizely.Graph.Commerce
from Optimizely Nuget package. - 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, you can aggregate some custom properties such as 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.
Optimizely Graph Search Provider
This project introduces a Graph Search Provider for Optimizely Commerce Connect
, which lets you search for products, variants, bundles, and packages within Optimizely Graph.
To use this search functionality, ensure that you configured Optimizely.Graph.Commerce
properly as described previously.
Get started
Install Optimizely.Graph.Commerce
to your Commerce Connect project then config
it.
Update appsettings.json
as shown in the following:
"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 data, including all products, variants, bundles, and packages into Graph. Since this project references Optimizely.Graph.Commerce
, it benefits from the enhanced data structure and additional information provided by that package. Once indexed, you can access the data with GraphQL queries.
Note
This method does not yet support the implementation of
Mediachase.Commerce.Search
indexing. Instead, you must rely on the Optimizely Graph content synchronization job to index and manage commerce data within Graph.
Search data
Once you install and configured Optimizely.Commerce.GraphSearchProvider
in appsettings.json
, it becomes available as one of the search providers. To make it the default for your commerce system, set its name in the DefaultSearchProvider
configuration value.
Based on Mediachase.Search
, this provider automatically turns search requests into GraphQL queries with the customized implementation of ISearchQueryBuilder
. It communicates with the Optimizely Graph server to fetch accurate and enriched commerce data in real time.
This gives you a modern, GraphQL-powered search experience for your commerce solution—with minimal configuration and maximum impact.
Updated 8 days ago