Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

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

  1. Install the Optimizely.ContentGraph.Cms NuGet package.
  2. Install the Optimizely.Graph.Commerce NuGet package.
  3. Add the following code to the ConfigureServices method in Startup.cs:
    services.AddContentDeliveryApi();
    services.AddContentGraph(x =>
    {
        x.IncludeInheritanceInContentType = true;
        x.PreventFieldCollision = true;
    });
    services.AddCommerceGraph();
  4. Add the namespace:
    using Optimizely.Graph.Commerce;
  5. Add the Optimizely setting at the same level as EPiServer in appsettings.json:
    "Optimizely": {
      "ContentGraph": {
        "GatewayAddress": "https://cg.optimizely.com",
        "AppKey": "YOUR_APP_KEY",
        "Secret": "YOUR_SECRET",
        "SingleKey": "YOUR_SINGLE_KEY",
        "AllowSendingLog": "true"
      }
    }
  6. Build the solution.
  7. Prepare the database.
  8. Run the site. On first run, the site executes data migration and then displays the homepage.
  9. Go to GraphQLAdmin to clear all previously synced data.
  10. Run the Optimizely Graph content synchronization job to sync data.
  11. Go to GraphiQL to 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.

📘

Note

In 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.

📘

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

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

  • PropertyDictionarySingle
  • PropertyDictionaryMultiple

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.