Search Result Custom Price Plugin
Storefront plugin config that replaces price, priceWithTax, and currencyCode on search results — and injects listPrice and listPriceWithTax — with values resolved by a pluggable price strategy.
Disclaimer: This module hooks into the Vendure SDK's
searchandsearchFieldmethods at runtime. The replacement prices are fetched asynchronously and written back into the React Query cache after the initial search response returns.
Purpose
Vendure search results may return stale or simplified price data (e.g. from a search index). Use this plugin when you need accurate, up-to-date prices on search/product-list pages — for example prices resolved from product variants or from the Product.price union type — without changing how the rest of your storefront consumes search results.
Features
- Strips
price,priceWithTax, andcurrencyCodefrom the default search query so the index is not the price source - Overrides
searchandsearchFieldSDK methods to fetch replacement prices via a configurable strategy - Injects
listPriceandlistPriceWithTaxfields that don't exist on search results natively - Ships a built-in default strategy that resolves prices (including list prices) from variant data
- Ships
priceOnProductsStrategy, an alternative strategy that queriesProduct.price/Product.priceWithTax/Product.listPrice/Product.listPriceWithTaxunion fields (PriceRange|SinglePrice) - Writes updated results back into the React Query cache automatically
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
VendureSearchResultCustomPricePlugin— the plugin config instancepriceOnProductsStrategy— a ready-made price strategy that queriesproductswithPriceRange/SinglePricefieldsfetchPrices— lower-level helper used internally; also exported for advanced compositionVendureSearchResultCustomPricePluginSettingstypeVendureSearchResultCustomPriceStrategytype
VendureSearchResultCustomPricePlugin
Plugin config instance created with VendurePluginConfig. Register it via pluginConfigs in your data provider.
VendureSearchResultCustomPricePluginSettings
interface VendureSearchResultCustomPricePluginSettings {
priceStrategy?: (
productIds: string[],
sdk: VendureSDK,
) => Promise<Array<VendureSearchResultCustomPriceStrategy>>
}
| Setting | Type | Required | Default | Description |
|---|---|---|---|---|
priceStrategy | (productIds: string[], sdk: VendureSDK) => Promise<Strategy[]> | No | Built-in variant-based strategy | Custom async function that resolves prices for a list of product IDs |
VendureSearchResultCustomPriceStrategy
The shape each strategy must return per product.
interface VendureSearchResultCustomPriceStrategy {
productId: string
price: Price
priceWithTax: Price
listPrice?: Price
listPriceWithTax?: Price
currencyCode: CurrencyCode
}
Utilities
priceOnProductsStrategy
Alternative price strategy that queries the products operation and resolves Price as the PriceRange | SinglePrice union type. Use this when your backend exposes price, priceWithTax, listPrice, and listPriceWithTax on the Product entity directly.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productIds | string[] | Yes | Product IDs to fetch prices for |
sdk | VendureSDK | Yes | The Vendure SDK instance |
Returns
Promise<Array<VendureSearchResultCustomPriceStrategy>>
Basic Usage
Example 1: Register Plugin with Default Strategy
Uses the built-in strategy that calculates min/max price from product variants.
- React
- React Native
import { VendureSearchResultCustomPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
const searchResultPricePlugin = VendureSearchResultCustomPricePlugin.init({
enableFeatures: {},
})
import { VendureSearchResultCustomPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
const searchResultPricePlugin = VendureSearchResultCustomPricePlugin.init({
enableFeatures: {},
})
Example 2: Register Plugin with priceOnProductsStrategy
Uses the included strategy that queries Product.price and Product.priceWithTax union fields.
- React
- React Native
import {
VendureSearchResultCustomPricePlugin,
priceOnProductsStrategy,
} from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
const searchResultPricePlugin = VendureSearchResultCustomPricePlugin.init({
enableFeatures: {},
settings: {
priceStrategy: priceOnProductsStrategy,
},
})
import {
VendureSearchResultCustomPricePlugin,
priceOnProductsStrategy,
} from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
const searchResultPricePlugin = VendureSearchResultCustomPricePlugin.init({
enableFeatures: {},
settings: {
priceStrategy: priceOnProductsStrategy,
},
})
Advanced Usage
Custom Price Strategy
Provide your own async function to resolve prices from any source.
- React
- React Native
import { VendureSearchResultCustomPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
import type { VendureSearchResultCustomPriceStrategy } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
const myPriceStrategy = async (productIds, sdk): Promise<VendureSearchResultCustomPriceStrategy[]> => {
const response = await sdk.createRequest(
{
operation: 'products',
fields: [{ items: ['id', 'price', 'priceWithTax', 'listPrice', 'listPriceWithTax', 'currencyCode'] }],
variables: { options: { type: 'ProductListOptions' } },
},
{ options: { filter: { id: { in: productIds } } } },
false,
)
return response.data.items?.map((item) => ({
productId: item.id,
price: item.price,
priceWithTax: item.priceWithTax,
listPrice: item.listPrice,
listPriceWithTax: item.listPriceWithTax,
currencyCode: item.currencyCode,
})) ?? []
}
const searchResultPricePlugin = VendureSearchResultCustomPricePlugin.init({
enableFeatures: {},
settings: {
priceStrategy: myPriceStrategy,
},
})
import { VendureSearchResultCustomPricePlugin } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
import type { VendureSearchResultCustomPriceStrategy } from '@haus-storefront-react/vendure-plugin-configs/search-result-custom-price'
const myPriceStrategy = async (productIds, sdk): Promise<VendureSearchResultCustomPriceStrategy[]> => {
const response = await sdk.createRequest(
{
operation: 'products',
fields: [{ items: ['id', 'price', 'priceWithTax', 'listPrice', 'listPriceWithTax', 'currencyCode'] }],
variables: { options: { type: 'ProductListOptions' } },
},
{ options: { filter: { id: { in: productIds } } } },
false,
)
return response.data.items?.map((item) => ({
productId: item.id,
price: item.price,
priceWithTax: item.priceWithTax,
listPrice: item.listPrice,
listPriceWithTax: item.listPriceWithTax,
currencyCode: item.currencyCode,
})) ?? []
}
const searchResultPricePlugin = VendureSearchResultCustomPricePlugin.init({
enableFeatures: {},
settings: {
priceStrategy: myPriceStrategy,
},
})
Made with ❤️ by Haus Tech Team