The Vue Storefront Essentials Course is now available! Learn More
Money normalizer

Money normalizer

The normalizeMoney function maps SAP Price into Unified SfMoney.

Parameters

NameTypeDefault valueDescription
pricePriceSAP price

Extending

The SfMoney is returned as a part of multiple models, as for example SfProduct, SfProductCatalogItem, and SfCart.

If you want to change the global attributes representation, you should override all root normalizers, so for example normalizeCart, normalizeProduct etc. Overriding the normalizeMoney function will not change have an impact of the image normalization inside these functions, it is just an utils function which may be then used in writing other custom normalizers or methods.

Source

image.ts
import type { SfMoney } from "@vue-storefront/unified-data-model";
import { Price } from "@vsf-enterprise/sapcc-types";

export function normalizeMoney(money: Price): SfMoney {
  const amount = money.value as number;

  return {
    currency: money.currencyIso as string,
    amount,
    precisionAmount: amount.toFixed(2),
  };
}