Product review normalizer
The normalizeProductReview function maps Commercetools Review into Unified SfProductReview.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
review | Review | Commercetools Review |
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 defineNormalizers function. The following example demonstrates how to extend SfProductReview with a includedInStatistics field.
import { normalizers as normalizersCT, defineNormalizers } from "@vsf-enterprise/unified-api-commercetools";
const normalizers = defineNormalizers<typeof normalizersCT>()({
...normalizersCT,
normalizeProductReview: (review) => ({
...normalizersCT.normalizeProductReview(review),
includedInStatistics: review.includedInStatistics
}),
});
Source
productReview.ts
import { maybe } from "@shared/utils";
import { defineNormalizer } from "../defineNormalizer";
export const normalizeProductReview = defineNormalizer.normalizeProductReview((review) => {
return {
id: review.id,
title: maybe(review.title),
text: maybe(review.text),
rating: maybe(review.rating),
reviewer: maybe(review.authorName),
createdAt: review.createdAt,
};
});