The Vue Storefront Essentials Course is now available! Learn More
Product normalizers

Product normalizers

Product includes two normalizers:

  • normalizeProduct: This function is used to map SFCC Product into SfProduct, which includes a full product details
  • normalizeProductCatalogItem: This function is used to map SFCC Product into SfProductCatalogItem, which includes only basic product details, needed to display a product in a product catalog

Parameters

normalizeProduct

NameTypeDefault valueDescription
productProductSFCC Product
ctxNormalizerContextContext needed for the normalizer. Context contain a currency field that contains a currency code

normalizeProductCatalogItem

NameTypeDefault valueDescription
productProductSearchHit or ProductSFCC ProductSearchHit or Product
ctxNormalizerContextContext needed for the normalizer. Context contain a currency field that contains a currency code

Extending

The SfProduct model is returned from GetProductDetails method. The SfProductCatalogItem model is returned from GetProducts method. If any of these models don't contain the information you need for your Storefront, you can extend its logic using the defineNormalizers function. In the following example we extend the normalizeProduct with manufacturerSku field which is available on SFCC Product and normalizeProductCatalogItem with productType field.

import { normalizers as normalizersSFC, defineNormalizers } from "@vsf-enterprise/unified-api-sfcc";
import { defineNormalizers } from "@vue-storefront/unified-data-model";

const normalizers = defineNormalizers<typeof normalizersSFCC>()({
  ...normalizersSFCC,
  normalizeProduct: (product, context) => ({
    ...normalizersSFCC.normalizeProduct(product, context),
    manufacturerSku: product.manufacturerSku,
  }),
  normalizeProductCatalogItem: (product, context) => ({
    ...normalizersSFCC.normalizeProductCatalogItem(product, context),
    productType: product.productType,
  }),
});

Since both normalizers accepts SFCC Product as a first argument, you may also use the same approach to use same representation for both SfProduct and SfProductCatalogItem models.

import { normalizers as normalizersSFC, defineNormalizers } from "@vsf-enterprise/unified-api-sfcc";

const normalizers = defineNormalizers<typeof normalizersSFCC>()({
  ...normalizersSFCC,
  normalizeProduct: (product, context) => ({
    ...normalizersSFCC.normalizeProduct(product, context),
  }),
  normalizeProductCatalogItem: (product, context) => ({
    ...normalizersSFCC.normalizeProduct(product, context),
  }),
});

However in this case you should be aware that SfProductCatalogItem will contain all the fields from SfProduct model and it will affect the performance of the catalog page.

Source

The normalizeProduct and normalizeProductCatalogItem function consists of several smaller normalizers such as normalizeImage, normalizeDiscountablePrice, and more. If you decide to override the normalization function, you should only override the root normalizer, which are normalizeProduct and normalizeProductCatalogItem.

šŸ”“ ../../node_modules/@vsf-enterprise/unified-api-sfcc/src/normalizers/product/product.ts | Snippet does not exist šŸ”“ šŸ”“ ../../node_modules/@vsf-enterprise/unified-api-sfcc/src/normalizers/product/productCatalog.ts | Snippet does not exist šŸ”“ šŸ”“ ../../node_modules/@vsf-enterprise/unified-api-sfcc/src/normalizers/image/image.ts | Snippet does not exist šŸ”“ šŸ”“ ../../node_modules/@vsf-enterprise/unified-api-sfcc/src/normalizers/product/variant.ts | Snippet does not exist šŸ”“ šŸ”“ ../../node_modules/@vsf-enterprise/unified-api-sfcc/src/normalizers/money/discountablePrice.ts | Snippet does not exist šŸ”“