Vue Storefront is now Alokai! Learn More
Category normalizer

Category normalizer

The normalizeCategory function is used to map a Magento CategoryTree into the unified SfCategory data model.


NameTypeDefault valueDescription
contextNormalizerContextcontext needed for the normalizer
categoryCategoryTreeWithParentUidMagento CategoryTree with information about categories' parent uid


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 addCustomFields API. The following example demonstrates how to extend SfCategory with a description field.

export const unifiedApiExtension = createUnifiedExtension({
  normalizers: {
    addCustomFields: [
        normalizeCategory: (context, category) => ({
          description: category.description,
  config: {


import { maybe, slugify } from "@shared/utils";
import { defineNormalizer } from "../defineNormalizer";

export const normalizeCategory = defineNormalizer.normalizeCategory((context, category) => {
  return {
    id: category.uid as string,
    name: ?? category.uid!,
    parentCategoryId: maybe(category.parentCategoryId),
    slug: category.url_key ?? slugify( ?? ""),
    subcategories: maybe(
        .map((element) =>
          context.normalizers.normalizeCategory({ ...element, parentCategoryId: category.uid }),