Vue Storefront is now Alokai! Learn More
GetProductDetails

GetProductDetails

Implements GetProductDetails Unified Method.

Source

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

export const getProductDetails = defineApi.getProductDetails(async (context, args) => {
  const product = await getProduct(context, args);
  const categories = product.masterData.current?.categories || [];
  assignToNormalizerContext(context, { sku: args.sku });

  const { normalizeProduct, normalizeCategory } = getNormalizers(context);

  return {
    product: normalizeProduct(product),
    categoryHierarchy: categories.map((category) => normalizeCategory(category)),
  };
});