Attributes normalizer
Attributes are Unified Data Layer representation of SAP VariantOptionQualifiers
. The normalizeAttribute
function maps VariantOptionQualifier
into a SfAttribute
.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
context | NormalizerContext | context needed for the normalizer. | |
optionQualifier | VariantOptionQualifiers | SAP VariantOptionQualifiers |
Extending
The SfAttribute
is returned as a part of SfProduct
, SfOrder
and SfCart
. If you want to extend the SfAttribute
with custom fields, you should use the addCustomFields
API.
import { normalizers } from "@vsf-enterprise/unified-api-sapcc";
export const unifiedApiExtension = createUnifiedExtension({
normalizers: {
addCustomFields: [
{
normalizeAttribute: (context, optionQualifier) => {
const normalizedAttribute = normalizers.normalizeAttribute(context, optionQualifier);
if (normalizedAttribute) {
return {
someNewField: "someValue",
};
}
return null;
},
},
],
},
config: {
...
},
});
Source
attributes.ts
import type { VariantOptionQualifier } from "@vsf-enterprise/sapcc-types";
import { defineNormalizer } from "../defineNormalizer";
export const normalizeAttribute = defineNormalizer.normalizeAttribute(
(_context, optionQualifier) => {
if (!isValidOptionQualifier(optionQualifier)) {
return null;
}
return {
name: optionQualifier.qualifier,
label: optionQualifier.name ?? optionQualifier.qualifier,
value: optionQualifier.value,
valueLabel: optionQualifier.value,
};
},
);
type ValidOptionQualifier = VariantOptionQualifier &
Required<Pick<VariantOptionQualifier, "qualifier" | "value">>;
function isValidOptionQualifier(
optionQualifier: VariantOptionQualifier,
): optionQualifier is ValidOptionQualifier {
return !!optionQualifier.qualifier && !!optionQualifier.value;
}