Skip to main content

ProductVariantPriceUpdateStrategy

ProductVariantPriceUpdateStrategy

This strategy determines how updates to a ProductVariantPrice is handled in regard to any other prices which may be associated with the same ProductVariant.

For instance, in a multichannel setup, if a price is updated for a ProductVariant in one Channel, this strategy can be used to update the prices in other Channels.

Using custom logic, this can be made more sophisticated - for example, you could have a one-way sync that only updates prices in child channels when the price in the default channel is updated. You could also have a conditional sync which is dependent on the permissions of the current administrator, or based on custom field flags on the ProductVariant or Channel.

Another use-case might be to update the prices of a ProductVariant in other currencies when a price is updated in one currency, based on the current exchange rate.

info

This is configured via the catalogOptions.productVariantPriceUpdateStrategy property of your VendureConfig.

Signature
interface ProductVariantPriceUpdateStrategy extends InjectableStrategy {
onPriceCreated(
ctx: RequestContext,
createdPrice: ProductVariantPrice,
prices: ProductVariantPrice[],
): UpdatedProductVariantPrice[] | Promise<UpdatedProductVariantPrice[]>;
onPriceUpdated(
ctx: RequestContext,
updatedPrice: ProductVariantPrice,
prices: ProductVariantPrice[],
): UpdatedProductVariantPrice[] | Promise<UpdatedProductVariantPrice[]>;
onPriceDeleted(
ctx: RequestContext,
deletedPrice: ProductVariantPrice,
prices: ProductVariantPrice[],
): UpdatedProductVariantPrice[] | Promise<UpdatedProductVariantPrice[]>;
}

onPriceCreated

method
(ctx: RequestContext, createdPrice: ProductVariantPrice, prices: ProductVariantPrice[]) => UpdatedProductVariantPrice[] | Promise<UpdatedProductVariantPrice[]>

This method is called when a ProductVariantPrice is created. It receives the created ProductVariantPrice and the array of all prices associated with the ProductVariant.

It should return an array of UpdatedProductVariantPrice objects which will be used to update the prices of the specific ProductVariantPrices.

onPriceUpdated

method
(ctx: RequestContext, updatedPrice: ProductVariantPrice, prices: ProductVariantPrice[]) => UpdatedProductVariantPrice[] | Promise<UpdatedProductVariantPrice[]>

This method is called when a ProductVariantPrice is updated. It receives the updated ProductVariantPrice and the array of all prices associated with the ProductVariant.

It should return an array of UpdatedProductVariantPrice objects which will be used to update the prices of the specific ProductVariantPrices.

onPriceDeleted

method
(ctx: RequestContext, deletedPrice: ProductVariantPrice, prices: ProductVariantPrice[]) => UpdatedProductVariantPrice[] | Promise<UpdatedProductVariantPrice[]>

This method is called when a ProductVariantPrice is deleted. It receives the deleted ProductVariantPrice and the array of all prices associated with the ProductVariant.

It should return an array of UpdatedProductVariantPrice objects which will be used to update the prices of the specific ProductVariantPrices.

DefaultProductVariantPriceUpdateStrategyOptions

The options available to the DefaultProductVariantPriceUpdateStrategy.

Signature
interface DefaultProductVariantPriceUpdateStrategyOptions {
syncPricesAcrossChannels: boolean;
}

syncPricesAcrossChannels

property
boolean

When true, any price changes to a ProductVariant in one Channel will update any other prices of the same currencyCode in other Channels. Note that if there are different tax settings across the channels, these will not be taken into account. To handle this case, a custom strategy should be implemented.

DefaultProductVariantPriceUpdateStrategy

The default ProductVariantPriceUpdateStrategy which by default will not update any other prices when a price is created, updated or deleted.

If the syncPricesAcrossChannels option is set to true, then when a price is updated in one Channel, the price of the same currencyCode in other Channels will be updated to match. Note that if there are different tax settings across the channels, these will not be taken into account. To handle this case, a custom strategy should be implemented.

Example

import { DefaultProductVariantPriceUpdateStrategy, VendureConfig } from '@vendure/core';

export const config: VendureConfig = {
// ...
catalogOptions: {
productVariantPriceUpdateStrategy: new DefaultProductVariantPriceUpdateStrategy({
syncPricesAcrossChannels: true,
}),
},
// ...
};
Signature
class DefaultProductVariantPriceUpdateStrategy implements ProductVariantPriceUpdateStrategy {
constructor(options: DefaultProductVariantPriceUpdateStrategyOptions)
onPriceCreated(ctx: RequestContext, price: ProductVariantPrice) => ;
onPriceUpdated(ctx: RequestContext, updatedPrice: ProductVariantPrice, prices: ProductVariantPrice[]) => ;
onPriceDeleted(ctx: RequestContext, deletedPrice: ProductVariantPrice, prices: ProductVariantPrice[]) => ;
}

constructor

method
(options: DefaultProductVariantPriceUpdateStrategyOptions) => DefaultProductVariantPriceUpdateStrategy

onPriceCreated

method

onPriceUpdated

method
(ctx: RequestContext, updatedPrice: ProductVariantPrice, prices: ProductVariantPrice[]) =>

onPriceDeleted

method
(ctx: RequestContext, deletedPrice: ProductVariantPrice, prices: ProductVariantPrice[]) =>