Skip to content

getProductsRelated(productId: number, options?: TGetProductsOptions): Promise<TWebapiList<Product> | null>

The getProductsRelated is an asynchronous method that allows to fetch a list of products related to the given product id.

Input parameters

productId - a number representing the product id.

options - an optional object with additional options for the request. You can read more about TGetProductsOptions model here.

Returned value

A returned value has a type of Promise<TWebapiList<Product> | null>. You can read more about TWebapiList model here.

Example

In this example we make a ProductFetcherApi call to get products related to the given product with id 1.

useStorefront(async (storefront) => {
    let productFetcherApi = await storefront.getApi('ProductFetcherApi');

    if (!productFetcherApi) {
        const featureSystemApi = this.getApiSync('FeatureSystemApi');
        await featureSystemApi.registerDynamic('ProductFetcher');

        productFetcherApi = await storefront.getApi('ProductFetcherApi');
    }

    const products = await productFetcherApi.getProductsRelated(1);
    console.log(products);
});

Product Fetcher API methods reference

Objects reference