Vue Storefront is now Alokai! Learn More
Product review normalizer

Product review normalizer

The normalizeProductReview function maps BigCommerce ProductReview into Unified SfProductReview.

Parameters

NameTypeDefault valueDescription
contextNormalizerContextContext which contains e.g. currency
reviewProductReviewBigCommerce ProductReview

Extending

The SfProductReview is returned from GetProductReviews Method. If the SfProductReview structure doesn't contain the information you need for your Storefront, you can extend its logic using the addCustomFields API. The following example demonstrates how to extend SfProductReview with a status field.

export const unifiedApiExtension = createUnifiedExtension({
  normalizers: {
    addCustomFields: [
      {
        normalizeProductReview: (context, review) => ({
          status: review.status
        }),
      },
    ],
  },
  config: {
    ...
  },
});

Source

productReview.ts
import { maybe } from "@shared/utils";
import type { ProductReview } from "@vsf-enterprise/bigcommerce-api";
import { defineNormalizer } from "../defineNormalizer";

export const normalizeProductReview = defineNormalizer.normalizeProductReview(
  (context, review: ProductReview) => {
    return {
      id: review.id.toString(),
      title: review.title,
      text: maybe(review.text),
      rating: review.rating,
      reviewer: review.name,
      createdAt: new Date(review.date_created).toISOString(),
    };
  },
);