Skip to main content
The product listing formatter extension changes product display data before products are shown in the app. Use it to change the vendor text, add or remove product tags, set a stamp image, or hide a product from a listing. This extension runs on almost every product the app shows, across all screens.

Exported function

Export the formatter from your entry file under the extension’s functionName in napps.config.json. See How App Extensions work. The examples on this page name it formatProducts.
The function can be synchronous or asynchronous. If it returns a promise, the mobile application waits up to 3 seconds for it. After that, the app treats the extension as failed and continues without the formatter result. The function can run often and receive many products, so keep it fast: avoid long network requests and heavy CPU work, and handle missing or optional product data. If you need network calls, start them in parallel and await them together:
Do not change products after the function, or its promise, has resolved.

What you can change

Each item received by formatProducts is a ProductListingBaseDataEditor. With it, you can:
  • Read the original product data.
  • Change the vendor text.
  • Set or clear the stamp image.
  • Read, replace, add, or remove tags, including removing tags by type or clearing all tags.
  • Hide or show the product, and check whether it is visible.

TypeScript types

setVisible(false) removes the product from the formatted list after all product formatter hooks finish running. ProductTag is a runtime global. @napps/component-extension exports its type only, so construct tags with new ProductTag(...) and do not import ProductTag as a value.

Example