List Price Plugin
Storefront plugin config that surfaces a separate list price (recommended retail / manufacturer price) alongside the active selling price. Use it to render struck-through "before" prices, discount labels, or campaign indicators when the active price is below the list price.
Disclaimer: This module depends on a compatible list-price plugin being active in the consumer's Vendure backend instance, exposing
listPrice/listPriceWithTaxonProductVariant(and onProduct.listPrice/Product.listPriceWithTaxif you also use the search-result strategy). Configure the backend first, then register this plugin config in the storefront.
Purpose
Use this module when your backend stores a separate list price per variant and you need that value available across product, search, and order contexts without duplicating GraphQL field selections in every consumer.
Features
- Extends product, brief-product, and order queries with
listPriceandlistPriceWithTaxon variants and order line variants - Augments
Product,BriefProductVariant, andSearchResultwith optionallistPrice/listPriceWithTaxfields — only when this plugin is imported - Registers
showListPrices,listPrice, andlistPriceWithTaxplugin feature mappings so consumers can read list-price values through the standard feature API - Resolves list prices from
OrderLine.productVariant,ProductVariant, orSearchResultautomatically - Ships
vendureListPriceSearchResultStrategy— a ready-made price strategy for use withVendureSearchResultCustomPricePluginthat fetchesprice,priceWithTax,listPrice, andlistPriceWithTaxfrom theproductsoperation - Ships
isCampaignutility to compare a list price against the active price
Installation
- npm
- Yarn
npm install @haus-storefront-react/vendure-plugin-configs
yarn add @haus-storefront-react/vendure-plugin-configs
Note: This is not a public package. Contact the Haus Tech Team for access.
API Reference
Exports
VendureListPricePlugin— the plugin config instancevendureListPriceSearchResultStrategy— price strategy forVendureSearchResultCustomPricePluginthat includes list pricesisCampaign— utility that returnstruewhen the active price differs from a non-zero list priceListPriceFeaturestype
VendureListPricePlugin
Plugin config instance created with VendurePluginConfig. Register it via pluginConfigs in your data provider.
Adds to ProductVariant / BriefProductVariant
| Field | Type | Description |
|---|---|---|
listPrice | SinglePrice? | List price for the variant |
listPriceWithTax | SinglePrice? | List price for the variant, including tax |
Adds to Product
| Field | Type | Description |
|---|---|---|
listPrice | Price? | List price union (PriceRange | SinglePrice) |
listPriceWithTax | Price? | List price union including tax |
Adds to SearchResult (populated by vendureListPriceSearchResultStrategy)
| Field | Type | Description |
|---|---|---|
listPrice | Price? | List price union written into the search result cache |
listPriceWithTax | Price? | List price union including tax |
ListPriceFeatures
interface ListPriceFeatures {
showListPrices: boolean
listPrice: (props: {
variant?: ProductVariant
orderLine?: OrderLine
searchResult?: SearchResult
identifier?: string
}) => Price
listPriceWithTax: (props: {
variant?: ProductVariant
orderLine?: OrderLine
searchResult?: SearchResult
identifier?: string
}) => Price
}
| Feature | Type | Description |
|---|---|---|
showListPrices | boolean | Toggle list-price rendering in consuming components |
listPrice | function | Resolves list price (multiplied by quantity for order lines, falling back to discountedLinePriceWithTax when the variant has no list price) |
listPriceWithTax | function | Same as listPrice but using listPriceWithTax |
vendureListPriceSearchResultStrategy
Price strategy for VendureSearchResultCustomPricePlugin that queries the products operation for price, priceWithTax, listPrice, and listPriceWithTax as PriceRange | SinglePrice unions. When passed as the priceStrategy setting, the strategy result is merged into the React Query cache for search and searchField responses — including the augmented listPrice / listPriceWithTax fields on each SearchResult item.
Signature
const vendureListPriceSearchResultStrategy: (
productIds: string[],
sdk: VendureSDK,
) => Promise<Array<VendureSearchResultCustomPriceStrategy>>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productIds | string[] | Yes | Product IDs to fetch prices for |
sdk | VendureSDK | Yes | The Vendure SDK instance |
Module augmentation
Importing this strategy augments VendureSearchResultCustomPriceStrategy from @haus-storefront-react/vendure-plugin-configs/search-result-custom-price with optional listPrice? and listPriceWithTax? fields, so the extra values flow through fetchPrices into the cached search items automatically.
isCampaign
Compares a list price against an active price. Returns false when the list price resolves to 0, and true when the two values differ. Accepts PriceRange, SinglePrice, or numeric inputs.
const isCampaign: (
listPrice: PriceRange | SinglePrice | number,
currentPrice: PriceRange | SinglePrice | number,
) => boolean
Basic Usage
Example 1: Register the Plugin
- React
- React Native
import { VendureListPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/list-price'
const listPricePlugin = VendureListPricePlugin.init({
enableFeatures: ['showListPrices'],
})
import { VendureListPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/list-price'
const listPricePlugin = VendureListPricePlugin.init({
enableFeatures: ['showListPrices'],
})
Example 2: Hydrate List Prices on Search Results
Combine vendureListPriceSearchResultStrategy with VendureSearchResultCustomPricePlugin to populate listPrice and listPriceWithTax on every SearchResult item returned by search / searchField.
Order matters: register
VendureSearchResultCustomPricePluginso it can stripprice/priceWithTax/currencyCodefrom the default search query, then registerVendureListPricePluginto enable the feature and bring in the type augmentation.
- React
- React Native
import { VendureSearchResultCustomPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
import {
VendureListPricePlugin,
vendureListPriceSearchResultStrategy,
} from '@haus-storefront-react/vendure-plugin-configs/list-price'
const pluginConfigs = [
VendureSearchResultCustomPricePlugin.init({
settings: {
priceStrategy: vendureListPriceSearchResultStrategy,
},
}),
VendureListPricePlugin.init({ enableFeatures: ['showListPrices'] }),
]
import { VendureSearchResultCustomPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
import {
VendureListPricePlugin,
vendureListPriceSearchResultStrategy,
} from '@haus-storefront-react/vendure-plugin-configs/list-price'
const pluginConfigs = [
VendureSearchResultCustomPricePlugin.init({
settings: {
priceStrategy: vendureListPriceSearchResultStrategy,
},
}),
VendureListPricePlugin.init({ enableFeatures: ['showListPrices'] }),
]
Example 3: Render a Campaign Label
Use isCampaign to compare the variant's list price against the active price.
- React
- React Native
import { isCampaign } from '@haus-storefront-react/vendure-plugin-configs/list-price'
export function ListPriceLabel({ variant }) {
if (!variant.listPriceWithTax) return null
const onCampaign = isCampaign(variant.listPriceWithTax, variant.priceWithTax)
return onCampaign ? <s>{variant.listPriceWithTax.value}</s> : null
}
import { Text } from 'react-native'
import { isCampaign } from '@haus-storefront-react/vendure-plugin-configs/list-price'
export function ListPriceLabel({ variant }) {
if (!variant.listPriceWithTax) return null
const onCampaign = isCampaign(variant.listPriceWithTax, variant.priceWithTax)
return onCampaign ? <Text style={{ textDecorationLine: 'line-through' }}>{variant.listPriceWithTax.value}</Text> : null
}
Advanced Usage
Reading List Prices via the Feature API
Once the plugin is registered, listPrice and listPriceWithTax become standard plugin features and can be invoked through the feature dispatcher with any of variant, orderLine, or searchResult. The handler picks the first matching source and returns a numeric Price.
- React
- React Native
import { useFeature } from '@haus-storefront-react/hooks'
export function VariantListPrice({ variant }) {
const listPriceWithTax = useFeature('listPriceWithTax', { variant })
return <span>{listPriceWithTax || null}</span>
}
import { Text } from 'react-native'
import { useFeature } from '@haus-storefront-react/hooks'
export function VariantListPrice({ variant }) {
const listPriceWithTax = useFeature('listPriceWithTax', { variant })
return <Text>{listPriceWithTax || null}</Text>
}
Made with ❤️ by Haus Tech Team