Image normalizer
The normalizeImage function maps SAP Image into Unified SfImage.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
context | NormalizerContext | Normalization context including an optional transformImageUrl which may transform the url | |
image | Image | SAP image |
Extending
The SfImage is returned as a part of multiple models, as for example SfProduct, SfProductCatalogItem, and SfCart. If the SfImage structure doesn't contain the information you need for your Storefront, you can extend its logic using the addCustomFields API.
export const unifiedApiExtension = createUnifiedExtension({
normalizers: {
addCustomFields: [
{
normalizeImage: (context, image) => ({
format: image.format,
}),
},
],
},
config: {
...
},
});
Source
image.ts
import { maybe } from "@/helpers";
import { defineNormalizer } from "../defineNormalizer";
export const normalizeImage = defineNormalizer.normalizeImage((context, image) => {
let url = image.url as string;
if (context.transformImageUrl) {
url = context.transformImageUrl(url);
}
return {
alt: maybe(image.altText),
url,
};
});