usePriceListProducts
The usePriceListProducts composable provides utilities for managing price list products and transformations. It handles converting between different product formats, managing quantity-based pricing rules, and facilitating product pricing workflows.
NOTE
These features are specifically made for price lists and wholesale pricing management. They are not general purpose product management tools.
Features
- Product transformation for different display formats
- Price break management for volume pricing
- Flexible pricing structures with margin, discount, and fixed pricing
Usage
Basic Usage
const {
transformProductsForList,
getVolumePricing,
getPriceListProduct,
addToPriceListProducts,
getNewPriceListProducts,
convertPriceModeToRuleField,
} = usePriceListProducts();
// Transform products for display
const displayProducts = transformProductsForList(
priceListProducts,
priceListEntity,
);Properties and Methods
transformProductsForList
transformProductsForList(
priceListProducts: PriceListProduct[],
entityData: ProductPriceList
): PriceListProductList[]Transforms raw price list products into a format suitable for display in lists or tables.
Parameters:
priceListProducts: Array of raw price list productsentityData: Price list entity containing currency and settings
Returns: Array of transformed products with display-ready properties
Features: Filters base quantities, converts prices, adds thumbnails
getVolumePricing
getVolumePricing(
productId: string,
products: PriceListProduct[],
entityData: ProductPriceList
): PriceListRule[]Extracts and formats quantity-based pricing levels for a specific product.
Parameters:
productId: Target product identifierproducts: Array of all price list productsentityData: Price list entity data
Returns: Sorted array of quantity-based pricing rules
Features: Filters by product ID, excludes base quantities, sorts by quantity
getPriceListProduct
getPriceListProduct(
productId: string,
value: number | null,
valueType: PriceListRuleField | undefined,
quantity?: number
): PriceListProductCreates a price list product object with the specified pricing rule.
Parameters:
productId: Product identifiervalue: Numeric value for the pricing rulevalueType: Type of pricing rule ('price', 'margin', 'discountPercent')quantity: Quantity threshold (default: 1)
Returns: Formatted price list product object
Features: Conditional property setting, flexible pricing types
addToPriceListProducts
addToPriceListProducts(
product: PriceListProduct,
priceListProducts: PriceListProduct[]
): voidAdds or updates a product in the price list products array.
Parameters:
product: Product to add or updatepriceListProducts: Target array (modified in place)
Behavior: Updates existing entries or adds new ones
Matching: Based on product ID and staggered count
getNewPriceListProducts
getNewPriceListProducts(
newProducts: PriceListProduct[],
currentProducts: PriceListProduct[],
productId: string
): PriceListProduct[]Merges new products with existing ones for a specific product ID.
Parameters:
newProducts: Array of new product rulescurrentProducts: Current product arrayproductId: Target product identifier
Returns: Merged array with updates applied
Features: Handles additions, updates, and deletions
convertPriceModeToRuleField
convertPriceModeToRuleField(
priceMode?: PriceListPriceMode
): PriceListRuleField | undefinedConverts a price mode enumeration to the corresponding rule field type.
Parameters:
priceMode: Price mode ('margin', 'discount', 'fixed', 'auto')
Returns: Corresponding rule field or undefined
Mapping:
'margin'→'margin''discount'→'discountPercent''fixed'→'price''auto'→undefined
Type Definitions
function usePriceListProducts(): UsePriceListProductsReturnType;
interface UsePriceListProductsReturnType {
transformProductsForList: (
priceListProducts: PriceListProduct[],
entityData: ProductPriceList,
) => PriceListProductList[];
getVolumePricing: (
productId: string,
products: PriceListProduct[],
entityData: ProductPriceList,
) => PriceListRule[];
getPriceListProduct: (
productId: string,
value: number | null,
valueType: PriceListRuleField | undefined,
quantity?: number,
) => PriceListProduct;
addToPriceListProducts: (
product: PriceListProduct,
priceListProducts: PriceListProduct[],
) => void;
getNewPriceListProducts: (
newProducts: PriceListProduct[],
currentProducts: PriceListProduct[],
productId: string,
) => PriceListProduct[];
convertPriceModeToRuleField: (
priceMode?: PriceListPriceMode,
) => PriceListRuleField | undefined;
}
interface PriceListRule {
_id?: string;
internalId?: string;
quantity?: number;
margin?: number;
discountPercent?: number;
price?: number;
applied?: boolean;
global?: boolean;
lastFieldChanged?: PriceListRuleField;
}
interface PriceListProductList {
_id: string;
name: string;
thumbnail: string;
purchasePrice: Price;
regularPrice: Price;
listPrice?: Price;
discount: number;
margin: number;
volumePricing: PriceListRule[];
priceMode: PriceListPriceMode;
}
type PriceListPriceMode =
| 'fixed'
| 'margin'
| 'discount'
| 'rule'
| 'auto'
| 'autoRule'
| 'autoFixed';