Push SAP products to Coveo by country

This is for:

Developer

When pushing data from SAP Commerce Cloud (version 2105 or later) to a Coveo organization, you can automatically push products to various Coveo sources based on their availability in different countries.

Note

To use this feature, you must use a specific version of the Coveo extension:

  • Version 3.3.1 or later for v3.

  • Version 2.1.5 or later for v2.

To ensure that products and variants are only available in the correct source, populate the SnField called coveoAuthorizedCountries for each product with the correct values.

When pushing data to Coveo, use value providers to set field values. There are two ways to populate the coveoAuthorizedCountries field:

Out-of-the-box value provider

Use the existing productAttributeSnIndexerValueProvider provider if all of your products have an Authorized Countries attribute that specifies where they’re available.

The Coveo SAP Commerce indexer push extension automatically populates the coveoAuthorizedCountries field with the value of the Authorized Countries attribute.

For a given product:

  • If the Authorized Countries attribute is empty, the product is sent to all sources.

  • If the attribute is set, the product is restricted to sources that match the listed countries.

Custom value provider

Create a custom value provider to populate the coveoAuthorizedCountries field based on the product’s availability in different countries.

The following code snippet shows how to create a custom value provider:

package com.coveo.indexer.service.impl;

import de.hybris.platform.core.model.c2l.CountryModel;
import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.searchservices.indexer.SnIndexerException;
import de.hybris.platform.searchservices.indexer.service.SnIndexerContext;
import de.hybris.platform.searchservices.indexer.service.SnIndexerFieldWrapper;
import de.hybris.platform.searchservices.indexer.service.impl.AbstractSnIndexerValueProvider;

import java.util.Collection;
import java.util.Set;

public class CustomAuthCountryValueProvider extends AbstractSnIndexerValueProvider<ProductModel, Void> {

    protected static final Set<Class<?>> SUPPORTED_QUALIFIER_CLASSES = Set.of();

    @Override
    protected Object getFieldValue(SnIndexerContext indexerContext, SnIndexerFieldWrapper fieldWrapper, ProductModel source, Void data) throws SnIndexerException {
        Collection<CountryModel> countries = getCountries(source); 1
        return countries; 2
    }

    private Collection<CountryModel> getCountries(ProductModel source) {
        return source.getCoveoAuthorizedCountries();
    }

    @Override
    public Set<Class<?>> getSupportedQualifierClasses() throws SnIndexerException {
        return SUPPORTED_QUALIFIER_CLASSES;
    }
}
1 Use custom logic to get the countries where the product is available.
2 Return the countries as a Collection<CountryModel> object.