The Vue Storefront Essentials Course is now available! Learn More
Address normalizers

Address normalizers

Address management in the Storefront requires bidirectional normalization.

Retrieving Addresses

To map SFCC BasketAddress into Unified Model, following normalizers are used:

  • normalizeAddress: This function is used to retrieve an address that has been saved in the checkout process.
  • normalizeCustomerAddress: When a customer retrieves one of the addresses they've saved, this function comes into play.

Saving Address

When a customer sets a shipping address during the checkout process, the SetCartAddress method is utilized. Here, a critical aspect arises in scenarios involving SalesForce Commerce Cloud. To ensure the correct handling of new addresses in SFCC, a special unnormalization process is required.

  • unnormalizeAddress To accurately save a new address in SFCC, we need to unnormalize the address data. This means mapping the unified SfCreateAddressBody format used within the Storefront into the specific structure required by SFCC, known as CustomerCreateAddressParams. This unnormalization step ensures that the address is correctly processed and stored in SFCC, maintaining data integrity between the Storefront and SFCC.

Parameters

normalizeAddress

NameTypeDefault valueDescription
addressAddressSFCC Address

normalizeCustomerAddress

NameTypeDefault valueDescription
addressCustomerAddressSFCC Address. If address does not contain the id, an error is thrown

unnormalizeAddress

NameTypeDefault valueDescription
addressSfCreateAddressBodyUnified address body sent in the request from the Storefront

Extending

The SfCustomerAddress model represents a reusable address, which customer decided to store. It is used within customer address methods, as for example GetCustomerAddresses. If any of this models don't contain the information you need for your Storefront, you can extend its logic using the defineNormalizers function. In the following example we extend the normalizeCustomerAddress with visibleInAddressBook field which is available on SFCC Address.

import { normalizers as normalizersSFCC, defineNormalizers } from "@vsf-enterprise/unified-api-sfcc";

const normalizers = defineNormalizers<typeof normalizersSFCC>()({
  ...normalizersSFCC,
  normalizeCustomerAddress: (address) => ({
    ...normalizersSFCC.normalizeCustomerAddress(address),
    visibleInAddressBook: address?.visibleInAddressBook ?? false,
  }),
});

Similarly if you want to change the mapping of unnormalizeAddress function you can customize it within defineNormalizers.

The SfAddress is used within the GetCart method. If you want to extend the SfAddress model, you should extend the normalizeCart function.

Source

🔴 ../../node_modules/@vsf-enterprise/unified-api-sfcc/src/normalizers/cart/address.ts | Snippet does not exist 🔴