Product review normalizer
The normalizeProductReview function maps BigCommerce ProductReview into Unified SfProductReview.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
context | NormalizerContext | Context which contains e.g. currency | |
review | ProductReview | BigCommerce 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 "@/helpers";
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(),
};
},
);