Use Coveo Search in SAP Commerce Cloud Composable Storefront

This is for:


SAP Commerce Cloud composable storefront (previously known as SAP Spartacus) is built upon Angular, which Coveo Atomic supports natively.

This article explains the steps required to build a basic search UI in SAP Commerce Cloud composable storefront using the Atomic framework.

Create an app

  1. Create a new Angular app

    ng new mystore --style=scss

    When prompted for Angular routing, enter n for no.

  2. Go to the newly created folder

    cd mystore
  3. To install Spartacus, you have to use the Spartacus schematics to quickly set up your application.

    For the base-url and base-site parameters, use values from your SAP Commerce instance.

    ng add @spartacus/schematics@latest --base-url --base-site=your-site --language=en --ssr

    During the installation, you’ll be prompted to choose which features you want to set up. If you want to build a B2B storefront, select the relevant B2B feature(s).

    For more details on available features, see the SAP documentation.

  4. Install the dependencies.

    yarn install
  5. To specify the path to your OCC, go to the the src/environments folder.

    In the environments and files, update the environment object with the following parameter:

    occBaseUrl: ''
  6. Open the tsconfig.json file and update the compilerOptions object with the following:

    "compilerOptions": {
      // ...
      "allowSyntheticDefaultImports": true

Adjust the app to use Coveo

To use Coveo-based search in your project, perform the following steps.

  1. Install the Atomic Angular package

    npm i @coveo/atomic-angular
  2. Move the Atomic static assets to the src folder of your app and update the angular.json file accordingly.

  3. To add basic styling, include the Default Coveo Theme.

  4. To be able to use the Atomic Angular components, open the src/app/app.module.ts file and import the AtomicAngular module.

  5. To initialize the search interface, update the src/app/app.component.ts file:

    import { AfterViewInit, Component } from '@angular/core';
    import { loadFieldActions } from '@coveo/atomic-angular'
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss']
    export class AppComponent implements AfterViewInit {
      ngAfterViewInit(): void {
        const searchInterface = document.querySelector('atomic-search-interface');
            accessToken: 'xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 1
            organizationId: 'orgnameplaceholder',
          .then(() => {
            const engine = searchInterface.engine;
            if (engine) {
              const fieldActions = loadFieldActions(engine);
              engine.dispatch(fieldActions.registerFieldsToInclude([ 2
    1 Specifies credentials for the target Coveo organization. See Authenticate via search token and Use API key authentication with the Search API.
    2 Specifies what custom fields to use in the UI.

Build a search UI

Now that you imported and initialized Coveo Atomic, you can use Atomic components to build a UI.

  1. As a starting point, paste the following sample into the src/app/app.component.html file:

        <atomic-layout-section section="search">
        <atomic-layout-section section="facets">
            <!-- The custom field dispatched in app.component.ts -->
            <!-- The custom field dispatched in app.component.ts -->
            <!-- The custom field dispatched in app.component.ts -->
        <atomic-layout-section section="main">
          <atomic-layout-section section="status">
              <atomic-sort-expression label="relevance" expression="relevancy"></atomic-sort-expression>
              <!-- The custom field dispatched in app.component.ts -->
              <atomic-sort-expression label="Price (high to low)" expression="ec_price descending"></atomic-sort-expression>
              <!-- The custom field dispatched in app.component.ts -->
              <atomic-sort-expression label="Price (low to high)" expression="ec_price ascending"></atomic-sort-expression>
          <atomic-layout-section section="results">
                  <atomic-result-text field="title"></atomic-result-text>
                    <!-- The custom field dispatched in app.component.ts -->
                    <atomic-result-image field="ec_image"></atomic-result-image>
                    <atomic-result-text field="excerpt"></atomic-result-text>
          <atomic-layout-section section="pagination">

    To see search results, make sure that your Coveo organization already has data indexed from an SAP Commerce Cloud instance.

  2. To launch the application locally, run the yarn start command. The application will open in the browser, at the http://localhost:4200 address by default.

  3. You now have a basic search interface powered by Coveo! Feel free to modify and experiment with it. You can add or remove components in the markup, type in requests in the search bar, use facets on the left side, click the results, etc.

Sample implementation

To see a more advanced implementation, examine the Coveo Barca demo.