Facet normalizer
Concept of facets exists in both Unified Data Layer world and SFCC. The normalizeFacet function maps SFCC Refinement into Unified SfFacet.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
context | NormalizeFacetContext | ||
refinement | Refinement | SFCC Refinement |
Extending
The SfFacet is returned from SearchProducts Method. If the SfFacet 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 SfFacet with a description field.
export const unifiedApiExtension = createUnifiedExtension({
normalizers: {
addCustomFields: [
{
normalizeFacet: (context, refinement) => ({
description: refinement.description,
}),
},
],
},
config: {
...
},
});
Source
facet.ts
import type { GetFacetTypeFn } from "@vue-storefront/unified-data-model";
import { SfFacetTypes } from "@vue-storefront/unified-data-model";
import type { Refinement } from "@internal";
import { defineNormalizer } from "../defineNormalizer";
const defaultGetFacetType: GetFacetTypeFn<Refinement> = () => SfFacetTypes.MULTI_SELECT;
export const normalizeFacet = defineNormalizer.normalizeFacet((context, refinement) => {
if (!refinement.values || refinement.values.length === 0) return null;
const { getFacetType = defaultGetFacetType } = context;
return {
label: refinement.label ?? refinement.attributeId,
name: refinement.attributeId,
values:
refinement.values?.map((refinementValue) => {
return {
label: refinementValue.label,
value: refinementValue.value,
productCount: refinementValue.hitCount,
};
}) ?? [],
type: getFacetType(refinement),
};
});