Customer normalizer
The normalizeCustomer
function is used to map a BigCommerce Customer
into the unified SfCustomer
data model.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
context | NormalizerContext | Context which contains e.g. currency | |
customer | Customer | BigCommerce Customer |
Extending
The SfCustomer
model is returned from Unified Methods such as RegisterCustomer
, LoginCustomer
and GetCustomer
. If the SfCustomer
structure doesn't contain the information you need for your Storefront, you can extend its logic using the addCustomFields
API. The following example demonstrates how to extend SfCustomer
with a company
field.
export const unifiedApiExtension = createUnifiedExtension({
normalizers: {
addCustomFields: [
{
normalizeCustomer: (context, customer) => ({
company: customer.company,
}),
},
],
},
config: {
...
},
});
Source
customer.ts
import { defineNormalizer } from "../defineNormalizer";
export const normalizeCustomer = defineNormalizer.normalizeCustomer((_context, user) => {
if (!user.id) {
throw new Error("User id is required");
}
return {
id: user.id.toString(),
firstName: user.first_name,
lastName: user.last_name,
email: user.email,
};
});