Alokai

getProducts

Method fetching information about specific products from Salesforce Commerce Cloud.

This method communicates with the getProducts endpoint of the Vue Storefront API Middleware. In turn, it receives data from the getProducts or the Get multiple products endpoints exposed by SCAPI / OCAPI, depending on the middleware configuration.

Allows access to multiple products by a single request. Only products that are online and assigned to a site catalog are returned. The maximum number of productIDs that can be requested are 24. Along with product details, the availability, product options, images, price, promotions, and variations for the valid products will be included, as appropriate.

Signature

export declare function getProducts(
	props: ProductsGetParams
): Promise<import("commerce-sdk/dist/product/product").ShopperProducts.Product[]>;

Parameters

NameRequiredTypeDescription
propsRequiredProductsGetParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.

Returns

Returns representations of Products.

Referenced Types

  • ProductsGetParams
  • ShopperProducts.Product

Examples

Fetching products by ids.

import { sdk } from '~/sdk.config.ts';

const products = await sdk.commerce.getProducts({ ids: ['12345', '23456'] });

Fetching products by ids with the following modifiers: - Specifying that availability should be returned for the 'eu-stock' and 'us-stock' inventory lists using the inventoryIds parameter; - Specifying that the full image models for the products should be returned instead of just the most suitable image using the allImages parameter; - Fetching the prices for all pricebooks assigned to the site instead of just the default sales price using the perPricebook parameter; - Getting all localisable fields in the 'en_US' locale instead of the one in middleware.config.js using the locale parameter; - Getting the prices for the 'USD' currency instead of the one in middleware.config.js using the currency parameter; - Removing 'variations' information from the response by setting all other available options in the expand parameter;

import { sdk } from '~/sdk.config.ts';

const products = await sdk.commerce.getProducts({
  ids: ['12345', '23456'],
  inventoryIds: ['eu-stock', 'us-stock'],
  allImages: true,
  perPricebook: true,
  locale: 'en_US',
  currency: 'USD',
  expand: [
    'availability',
    'bundled_products',
    'links',
    'promotions',
    'options',
    'images',
    'prices',
    'set_products',
    'recommendations',
  ],
});

On this page