shopware/frontends - helpers 
Welcome to @shopware/helpers package.
For getting started documentation visit https://frontends.shopware.com/
Documentation specific for this package: helpers
Reusable classes 
The helpersCssClasses variable, defined in the cms/layoutClasses.ts helper file, comprises an array of class names utilized within the CMS.
To enhance type support, a union type HelpersCssClasses is defined, which encompasses all class names present in the helpersCssClasses array.
const visibilityMap: Record<CmsVisibility, HelpersCssClasses> = {
  mobile: "max-md:hidden",
  tablet: "md:max-lg:hidden",
  desktop: "lg:hidden",
};These classes can be integrated into a custom template, thereby ensuring consistency across different packages. For example as a safelist classes in unocss configuration file
import { helpersCssClasses } from "@shopware/helpers";
export default defineConfig({
  safelist: helpersCssClasses,
});Changelog 
Full changelog for stable version is available here
Latest changes: 1.5.0 
Minor Changes 
- #1910 c8fa438Thanks @mdanilowicz! - Add helper for getting payment and shipping method icon
API 
downloadFile 
Download file
export function downloadFile<T>(file: T, name: string)getTranslatedProperty 
Get translated property from the given object.
export function getTranslatedProperty<T>(
  element: T | undefined | null | never,
  property: keyof T,
): stringgetBiggestThumbnailUrl 
Returns the biggest thumbnail url from the media object
export function getBiggestThumbnailUrl<
  T extends {
    thumbnails?: Array<{
      width: number;
      url: string;
    }>;
  },
>(media?: T): string | undefinedgetMedia 
Prepare media object
export function getMedia<
  T extends {
    downloads?: Array<{
      id: string;
      accessGranted: boolean;
      media: {
        fileName: string;
        fileExtension: string;
      };
    }>;
  },
>(lineItem: T)getSmallestThumbnailUrl 
Returns the smallest thumbnail url from the media object
export function getSmallestThumbnailUrl<
  T extends {
    thumbnails?: Array<{
      width: number;
      url: string;
    }>;
  },
>(media?: T): string | undefinedgetSrcSetForMedia 
Returns the srcset attribute for the image, for available breakpoints
export function getSrcSetForMedia<
  T extends {
    thumbnails?: Array<{
      width: number;
      url: string;
    }>;
  },
>(media?: T): string | undefinedrelativeUrlSlash 
Add/remove slash from the relative path
export function relativeUrlSlash(relativeUrl: string, slash = true)urlIsAbsolute 
export function urlIsAbsolute(url: string)canUseQuoteActions 
export function canUseQuoteActions<
  T extends {
    stateMachineState?: {
      technicalName: string;
    };
  },
>(quote: T)getCmsLayoutConfiguration 
Get layout configuration for CMS content
export function getCmsLayoutConfiguration<
  T extends CmsBlock | CmsSection | CmsSlot,
>(content: T): LayoutConfigurationexpand LayoutConfiguration
export type LayoutConfiguration = {
  layoutStyles: {
    backgroundColor?: string | null;
    backgroundImage?: string | null;
    backgroundSize?: string | null;
    sizingMode?: string | null;
    marginBottom?: string | null | undefined;
    marginLeft?: string | null | undefined;
    marginRight?: string | null | undefined;
    marginTop?: string | null | undefined;
  };
  cssClasses: {
    [cssClass: string]: boolean;
  } | null;
};LayoutConfiguration 
export type LayoutConfiguration = {
  layoutStyles: {
    backgroundColor?: string | null;
    backgroundImage?: string | null;
    backgroundSize?: string | null;
    sizingMode?: string | null;
    marginBottom?: string | null | undefined;
    marginLeft?: string | null | undefined;
    marginRight?: string | null | undefined;
    marginTop?: string | null | undefined;
  };
  cssClasses: {
    [cssClass: string]: boolean;
  } | null;
};getCmsEntityObject 
Returns the main page object depending of the type of the CMS page.
export function getCmsEntityObject(
  response: CmsPageResponse,
): Product | Category | LandingPageisProduct 
Predicate function to check if the entity is a product.
export function isProduct<T extends { apiAlias: string }>(
  entity: T | Product,
): entity is ProductisCategory 
export function isCategory<T extends { apiAlias: string }>(
  entity: T | Category,
): entity is CategoryisLandingPage 
export function isLandingPage<T extends { apiAlias: string }>(
  entity: T | LandingPage,
): entity is LandingPagegetProductFreeShipping 
Get product free shipping property
export function getProductFreeShipping<
  T extends {
    shippingFree: boolean;
  },
>(product?: T): booleangetProductName 
export function getProductName<
  T extends {
    name: string;
  },
>({ product }: { product?: T } = {}): string | nullgetMainImageUrl 
gets the cover image
export function getMainImageUrl<
  T extends
    | {
        cover?: {
          media?: {
            url: string;
          };
        };
      }
    | {
        media?: Array<{
          media?: {
            url?: string;
          };
        }>;
      }
    | {
        cover?: {
          url: string;
        };
      },
>(object: T): stringgetProductTierPrices 
Get the prices depending on quantity added to cart. Tier prices can be set in Advanced pricing tab in Product view (admin panel)
export function getProductTierPrices<
  T extends {
    calculatedPrices?: Array<{
      unitPrice: number;
      quantity: number;
    }>;
  },
>(product?: T): TierPrice[]getProductReviews 
Format product reviews to ui-interfaces
export function getProductReviews<
  T extends {
    id: string;
    productReviews?: Array<{
      id: string;
      externalUser?: string;
      customerId?: string;
      createdAt: string;
      content: string;
      points?: number;
    }>;
  },
>({ product }: { product?: T } = {}): UiProductReview[]getProductUrl 
Get product url. The priority is SEO url and then technical url.
export function getProductUrl<
  T extends {
    id: string;
    seoUrls?: Array<{
      seoPathInfo?: string;
    }>;
  },
>(product?: T): stringgetProductRatingAverage 
Get product rating average property
export function getProductRatingAverage<T extends { ratingAverage: number }>(
  product: T,
): number | nullgetProductCalculatedListingPrice 
Get the calculated list price
export function getProductCalculatedListingPrice<
  T extends {
    calculatedPrice?: CalculatedPrice;
    calculatedPrices?: CalculatedPrice[];
  },
>(product?: T): number | undefinedgetProductFromPrice 
export function getProductFromPrice<
  T extends {
    calculatedPrice?: CalculatedPrice;
    calculatedPrices?: CalculatedPrice[];
  },
>(product: T): number | undefinedgetProductManufacturerName 
Gets the translated name of the product manufacturer
export function getProductManufacturerName(
  product: ProductWithManufacturer,
): stringgetProductRoute 
Get product route information for Vue router.
Returns product URL and route informations for resolving SEO url. Use it with combination of <RouterLink> or <NuxtLink> in Vue.js or Nuxt.js projects.
export function getProductRoute<
  T extends {
    id: string;
    seoUrls?: Array<{
      seoPathInfo?: string;
    }>;
  },
>(product?: T)isProductOnSale 
Checks if a product is on sale based on its price percentage
export function isProductOnSale(product: {
  calculatedPrice: {
    listPrice?: {
      percentage?: number;
    } | null;
  };
}): booleanisProductTopSeller 
Checks if a product is marked as a top seller
export function isProductTopSeller(product: {
  markAsTopseller?: boolean;
}): booleangetCategoryUrl 
Get URL for category. Some link
export function getCategoryUrl<
  T extends {
    type: string;
    externalLink?: string;
    seoUrls?: { seoPathInfo: string }[];
    internalLink?: string;
    id: string;
    linkType?: string;
  },
>(category: T): stringgetCategoryImageUrl 
gets the cover image
export function getCategoryImageUrl<
  T extends {
    media?: { url: string };
    type: string;
  },
>(category: T): stringgetCategoryBreadcrumbs 
Gather breadcrumbs from category
export function getCategoryBreadcrumbs<
  T extends {
    translated?: {
      breadcrumb?: string[];
    };
    breadcrumb?: string[];
  },
>(
  category: T,
  options?: {
    /**
     * Start at specific index if your navigation
     * contains root names which should not be visible.
     */
    startIndex?: number;
  },
)getCategoryRoute 
Get category/navigation route information for Vue Router.
Returns category or navigation URL and route informations for resolving SEO url. Use it with combination of <RouterLink> or <NuxtLink> in Vue.js or Nuxt.js projects.
Example:
<RouterLink :to="getCategoryRoute(navigationElement)">export function getCategoryRoute<
  T extends {
    type: string;
    externalLink?: string;
    seoUrls?: { seoPathInfo: string }[];
    internalLink?: string;
    id: string;
    linkType?: string;
  },
>(category: T)buildUrlPrefix 
export function buildUrlPrefix(
  url: string | UrlRoute,
  prefix: string,
): UrlRouteOutputexpand UrlRouteOutput
export type UrlRouteOutput = Omit<UrlRoute, "path"> & { path: string };getBackgroundImageUrl 
export function getBackgroundImageUrl<
  T extends {
    backgroundMedia?: {
      metaData?: {
        width?: number;
        height?: number;
      };
    };
  },
>(url: string, element: T): stringisMaintenanceMode 
export function isMaintenanceMode<
  T extends {
    code?: string;
  },
>(errors: [T]): booleangetCmsTranslate 
Replace text placeholder with param value
export function getCmsTranslate(
  key: string,
  params?: { [key: string]: string | number | null | undefined } | null,
)getCmsBreadcrumbs 
Build the breadcrumbs for the CMS page
export function getCmsBreadcrumbs<
  T extends {
    translated: {
      name: string;
    };
  },
>(page: T): { name: string }[]getListingFilters 
biome-ignore lint/suspicious/noExplicitAny: Listing filters needs to be improved when schema types are ready
export function getListingFilters<T extends Record<string, any>>(
  aggregations: T | undefined | null,
): ListingFilter[]getFormattedPrice 
Get formatted price
export function getFormattedPrice(
  value: string | number,
  currency: string,
  options: Options = {
    direction: "ltr",
    removeDecimals: false,
    removeCurrency: false,
  },
): stringgetShippingMethodDeliveryTime 
Get shipping delivery time
export function getShippingMethodDeliveryTime<
  T extends {
    deliveryTime?: {
      translated: {
        name: string;
      };
    };
  },
>(shippingMethod: T)getShippingMethodIcon 
Get shipping method icon
export function getShippingMethodIcon<
  T extends {
    media?: {
      url: string;
    };
  },
>(shippingMethod: T)getPaymentMethodIcon 
Get payment method icon
export function getPaymentMethodIcon<
  T extends {
    media?: {
      url: string;
    };
  },
>(paymentMethod: T)getLanguageName 
Get translated language name
export function getLanguageName<
  T extends {
    translationCode?: { translated: { name: string } };
  },
>(language: T): string