vendure-plugin-metal-price
v1.0.0
Published
Vendure plugin for automatically updating product prices based on real-time precious metal market rates
Downloads
118
Maintainers
Readme
Vendure Metal Price Plugin
A Vendure plugin for automatically updating product prices based on real-time precious metal market rates (Gold/Silver).
Features
Custom Fields: Automatically extends
ProductVariantwith:metalPriceMaterial: The type of precious metal (Gold/Silver/None)metalPriceWeight: Weight in gramsmetalPriceLaborCost: Manufacturing cost in cents
Automatic Price Calculation:
- Formula:
New Price = (Live Price per Gram × Weight) + Labor Cost - Fetches live metal prices from external APIs
- Updates product variant prices automatically
- Formula:
GraphQL API: Exposes
updateMetalPricesmutation for manual price updates (Admin only)
Installation
npm install vendure-plugin-metal-priceUsage
- Import and register the plugin in your
vendure-config.ts:
import { VendureConfig } from '@vendure/core';
import { MetalPricePlugin } from 'vendure-plugin-metal-price';
export const config: VendureConfig = {
// ... other config
plugins: [
MetalPricePlugin,
// ... other plugins
],
};Configure product variants with metal pricing:
- Set
metalPriceMaterialto "Gold" or "Silver" - Set
metalPriceWeightto the weight in grams - Set
metalPriceLaborCostto the labor cost in cents
- Set
Trigger price updates via GraphQL:
mutation {
updateMetalPrices {
total
successful
failed
results {
variantId
success
newPrice
error
}
}
}Configuration
The plugin currently uses mocked metal prices. To integrate with a real API:
- Update the
METAL_PRICE_APIconstants insrc/constants.ts - Modify the
fetchMetalPricemethod insrc/metal-price.service.tsto use your API
License
MIT
