Vue Storefront is now Alokai! Learn More
Money normalizer

Money normalizer

The normalizeMoney function maps BigCommerce money amount into Unified SfMoney.

Parameters

NameTypeDefault valueDescription
contextNormalizerContextContext which contains e.g. currency
moneynumberAmount as number

Extending

The SfMoney is returned as a part of multiple models, as for example SfProduct, SfProductCatalogItem, and SfCart. If you want to extend the SfMoney with custom fields, you should use the addCustomFields API.

export const unifiedApiExtension = createUnifiedExtension({
  normalizers: {
    addCustomFields: [
      {
        normalizeMoney: (context, money) => ({
          someNewField: "someValue",
        }),
      },
    ],
  },
  config: {
    ...
  },
});

Source

money.ts
import { defineNormalizer } from "../defineNormalizer";

export const normalizeMoney = defineNormalizer.normalizeMoney((context, amount) => {
  return {
    amount,
    currency: context.currency,
    precisionAmount: amount.toFixed(2),
  };
});