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

Category normalizer

The normalizeCategory function is used to map a SAP CategoryHierarchy or Category into the unified SfCategory data model.

Parameters

NameTypeDefault valueDescription
categoryCategoryHierarchy or CategorySAP Category

Extending

The SfCategory model is returned from the Unified Methods such as SearchProducts, and GetCategories. If the SfCategory structure doesn't contain the information you need for your Storefront, you can extend its logic using the defineNormalizers function. The following example demonstrates how to extend SfCategory with an url field.

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

const normalizers = defineNormalizers<typeof normalizersSAP>()({
  ...normalizersSAP,
  normalizeCategory: (category) => ({
    ...normalizersSAP.normalizeCategory(category),
    url: category.url,
  }),
});

Source

CategoryHiearchy is returned from API Client's the getCatalogVersion and Category from the getProduct.

customer.ts
import { User } from "@vsf-enterprise/sapcc-types";
import { SfCustomer } from "@vue-storefront/unified-data-model";

export function normalizeCustomer(user: User): SfCustomer {
  if (!user.customerId || !user.uid || !user.firstName || !user.lastName) {
    throw new Error("Missing required fields for customer");
  }

  return {
    id: user.customerId,
    firstName: user.firstName,
    lastName: user.lastName,
    email: user.uid,
  };
}