GetProductDetails
Implements GetProductDetails
Unified Method.
Source
import { defineApi } from "@vsf-enterprise/unified-api-commercetools";
import { assignToNormalizerContext, getNormalizers } from "@vsf-enterprise/unified-api-commercetools/udl";
import { getProduct } from "@vsf-enterprise/unified-api-commercetools";
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)),
};
});