Alokai

getProduct

Method fetching information about a specific product from Salesforce Commerce Cloud.

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

Allows access to product details for a single product ID. Only products that are online and assigned to a site catalog are returned. Along with product details, the availability, images, price, bundled_products, set_products, recommendations, product options, variations, and promotions for the products will be included, as appropriate.

Signature

export declare function getProduct(
	props: ProductGetParams
): Promise<import("commerce-sdk/dist/product/product").ShopperProducts.Product>;

Parameters

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

Returns

Returns a representation of a Product.

Referenced Types

  • ProductGetParams
  • ShopperProducts.Product

Examples

Fetching a product by id.

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

const product = await sdk.commerce.getProduct({ id: '12345' });

Fetching a product by id 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 model for the product 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 product = await sdk.commerce.getProduct({
  id: '12345',
  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