The Vue Storefront Essentials Course is now available! Learn More
GetProducts

GetProducts

Implements GetProducts Unified Method.

Source

import { defineApi, getNormalizerContext } 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 responseData = await context.api.getProduct({ ids, skus });
  const { results = [] } = responseData.data?.products || {};

  const { normalizeProductCatalogItem } = getNormalizers(context);

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

  return {
    products,
  };
});