Sales App extension hooks and types
Explore the APIs and core types available for building Sales App extensions.
This guide introduces the Sales App APIs and core types used to build extensions.
The following APIs are available:
| API | Category | Use case |
|---|---|---|
defineExtensions | Function | Register components in extension points. |
useCart | Hook | Read cart-level data or perform cart mutations, such as adding items, coupons, or gift cards. |
useCartItem | Hook | Read data or perform mutations for a single cart item, such as changing quantity, attachments, or price. |
useCurrentUser | Hook | Access authenticated user data. |
useExtension | Hook | Access runtime context, such as the current account or the current extension point. |
usePDP | Hook | Access product detail page data, specifically the current productSku. |
Available types and their corresponding hooks include:
| Types | Used by | Description |
|---|---|---|
CartItem | useCart, useCartItem | An item in the cart, including product, quantity, seller, pricing, and attachments. |
ClientProfileData | useCart | Customer data returned from the cart context. |
ProductSku | usePDP | A product SKU, including identifying information, quantity, and pricing fields. |
Totalizers | useCart | Summary totals from an orderForm or cart, such as shipping, taxes, or discounts. |
API reference
defineExtensions
The defineExtensions function registers one or more React components by associating them with extension points. Learn more in Exploring Sales App extensions.
Use this function in your extension entry point file, such as src/index.tsx.
Usage
In the following example, Recommendations is rendered at the cart.cart-list.after extension point, which appears below the cart items list.
Parameters
The defineExtensions function accepts a single parameter, Record<ExtensionPoints, () => ReactNode>. The ExtensionPoints type represents the list of valid extension points available in VTEX Sales App.
useCart
The useCart hook allows you to access cart data and perform mutations that will reflect on other entities within the Sales App data layer.
This hook is available in the following extension points:
cart.cart-list.aftercart.cart-item.aftercart.order-summary.afterpdp.sidebar.beforepdp.sidebar.afterpdp.content.after
See all available extension points in the guide Exploring Sales App extensions.
Usage
You can also use useCart to interact with the Sales App data layer by mutating the cart item list:
Parameters
The useCart hook doesn't accept any parameters.
Returns
The useCart hook returns an object with the following properties:
| Property | Type | Description |
|---|---|---|
orderFormId | string | undefined | orderForm identifier for the current cart. |
value | number | Cart total. |
items | CartItem[] | Items currently in the cart. |
totalizers | Totalizers[] | Aggregated cart totals. |
clientProfileData | ClientProfileData | Customer profile data associated with the cart. |
giftCards | GiftCard[] | Gift cards currently attached to the cart. |
addItem | (data: UseCartAddItemData) => Promise<void> | Adds an item to the cart. |
removeItem | (id: string, index: number) => Promise<void> | Removes an item from the cart. |
addCoupon | (coupon: string) => Promise<void> | Applies a coupon to the cart. |
addGiftCard | (redemptionCodeOrGiftCard: string | GiftCard, provider?: string) => Promise<void> | Adds a gift card to the cart payment data. You can provide either a redemption code (as a string) with an optional provider, or a GiftCard object if you already have the gift card details. |
sync | () => Promise<void> | Syncs the cart with the latest Order Form data. |
addItem
In the addItem property, the UseCartAddItemData type is an object with the following structure:
_10type UseCartAddItemData = {_10 id: string;_10 quantity: number;_10 seller: string;_10 attachments?: Attachment[];_10};
addGiftCard
In the addGiftCard property, the GiftCard type is an object with the following structure:
_12export type GiftCard = {_12 id: string_12 redemptionCode?: string | null_12 name: string_12 caption: string_12 value: number_12 balance: number_12 provider: string_12 groupName?: string | null_12 inUse: boolean_12 isSpecialCard: boolean_12}
Example using a redemption code:
useCartItem
The useCartItem hook provides access to detailed information about an individual cart item. This is useful when you need to retrieve or display specific data related to a single item in the cart.
This hook is available in the following extension point:
cart.cart-item.after
See all available extension points in the guide Exploring Sales App extensions.
Usage
Parameters
The useCartItem hook doesn't accept any parameters.
Returns
The useCartItem hook returns an object with the following properties:
| Property | Type | Description |
|---|---|---|
item | CartItem[] | undefined | Cart item data for the current item. |
itemIndex | number | undefined | Index of the current item in the cart. |
changeItem | (data: UseCartItemChangeItemData) => Promise<void> | Updates the item data. |
changePrice | (price: number) => Promise<void> | Changes the item price when manual price is enabled. To check whether the manual price is active, use Get orderForm configuration. To enable it, use Update orderForm configuration and set allowManualPrice to true. |
changeItem
In the changeItem property, the UseCartItemChangeItemData type is an object with the following structure:
_10type UseCartItemChangeItemData = {_10 quantity?: number_10 attachments?: Attachment[]_10}
useCurrentUser
The useCurrentUser hook allows you to access currently authenticated user data, like name and email.
This hook is available in the following extension point:
menu.drawer-content
See all available extension points in the guide Exploring Sales App extensions.
Usage
Parameters
The useCurrentUser hook doesn't accept any parameters.
Returns
The useCurrentUser hook returns an object with the following properties:
| Property | Type | Description |
|---|---|---|
name | string | Name of the current user. |
email | string | Email address of the current user. |
useExtension
The useExtension hook allows you to access information about the current account and the extension point in which your extension is running.
This hook is available for all extension points. See the full list in the guide Exploring Sales App extensions.
Usage
Parameters
The useExtension hook doesn't accept any parameters.
Returns
The useExtension hook returns an object with the following structure:
| Property | Type | Description |
|---|---|---|
account | string | The current account name where the extension is running. |
extensionPoint | ExtensionPointsType | The name of the extension point your extension is hooked to. |
usePDP
The usePDP hook allows you to access Product Detail Page (PDP) data and perform mutations that will reflect on other entities within the Sales App data layer.
This hook is available in the following extension points:
pdp.sidebar.beforepdp.sidebar.afterpdp.content.after
See all available extension points in the guide Exploring Sales App extensions.
Usage
Parameters
The usePDP hook doesn't accept any parameters.
Returns
The usePDP hook returns an object with the following property:
| Property | Type | Description |
|---|---|---|
productSku | ProductSku | Product SKU data for the current product detail page. |
Types
CartItem
The CartItem type represents an item in the cart. Its signature and the types used follow this contract:
_13 type CartItem = {_13 id: string_13 name: string_13 quantity: number_13 seller: string_13 sellingPrice: number_13 listPrice: number_13 manualPrice?: number_13 price: number_13 imageUrl: string_13 productRefId?: string_13 attachments?: Attachment[]_13};
Attachment
The Attachment type is defined as:
_10type Attachment = {_10 name: string;_10 content: Record<string, string>;_10};
ClientProfileData
The ClientProfileData type represents the structure of the data returned for a client. Its signature and the types used follow this contract:
_10type ClientProfileData = {_10 email: string | null;_10 document: string | null;_10 phone: string | null;_10};
ProductSku
The ProductSku type represents the structure of a product SKU, including quantity and pricing details. Its signature and the types used follow this contract:
_10type ProductSku = {_10 id: string;_10 name: string;_10 quantity: number;_10 price: number;_10 listPrice: number;_10 sellingPrice?: number;_10};
Totalizers
The Totalizers type represents the structure of the summary totals returned in an orderForm or cart, such as shipping, taxes, or discounts. Its signature and the types used follow this contract:
_10type Totalizers = {_10 id: string_10 name: string_10 value: number_10};