Vue Storefront is now Alokai! Learn More
GetProducts

GetProducts

Implements GetProducts Unified Method.

Source

import { defineApi } from "@vsf-enterprise/unified-api-commercetools";
import { getNormalizers } from "@vue-storefront/unified-data-model";

export const getProducts = defineApi.getProducts(async (context, args) => {
  const { ids, skus } = args;
  const { normalizeProductCatalogItem } = getNormalizers(context);

  const responseData = await context.api.getProduct({ ids, skus });
  const { results = [] } = responseData.data?.products || {};

  const products = results.map((product) => normalizeProductCatalogItem(product));

  return {
    products,
  };
});