Vue Storefront is now Alokai! Learn More
Money normalizer

Money normalizer

The normalizeMoney function maps Magento Money into Unified SfMoney.

Parameters

NameTypeDefault valueDescription
contextNormalizerContextcontext needed for the normalizer
moneyMoneyMagento money

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. If you want to extend the SfMoney with custom fields, you should use the addCustomFields API.

Source

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

export const normalizeMoney = defineNormalizer.normalizeMoney((_context, price) => {
  const amount = price.value ?? 0;
  return {
    amount,
    currency: price.currency as string,
    precisionAmount: amount.toFixed(2),
  };
});