vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.78k stars 1.03k forks source link

Promoted prices on ProductVariant #904

Open chladog opened 3 years ago

chladog commented 3 years ago

Is your feature request related to a problem? Please describe. When ProductVariant is eligible to some currently active promotion it's not possible to get "would be" price. In my current implementation I'm solving this by mirroring the promotions logic in UI app.

Here are examples of our promotions for reference: Bulk pricing:

- 1pc of product has price **X/pc**
- 3-5pcs of products in cart has price **Y/pc**
- 6+pcs of products in cart has price **Z/pc**

X+Y promotion

- promotion 2 + 1 - if you have 3pcs of product in cart it has price **(X * 2 / 3)/pc**

Discounts:

- if productvariant has CF "discountPrice" the productvariant in cart has price **discountPrice /pc**

It's hard to sync, maintain and combine such all promotions together to list the correct would be price. And basically impossible to also consider current cart contents - e.g. You have 4 of this productvariant, order 2 more of this productvariant to get "Y" price.

Describe the solution you'd like New function getPromotedPrices that would allow us to create a custom resolver for property e.g.: "promotionPrices". We should be able to pass conditions that should be taken into the calculation e.g. productVariant quantities or other order properties / contents. This function should also consider active order of the customer - e.g. if user has some content in cart that makes him eligible already the price should reflect that.

e.g.

getPromotedPrices( priceId: ID, productVariantId: ID, considerActiveOrder: boolean, order?: Partial<Order> ): [ [ priceId, price ] ]

in return we would get a Map with priceId and calculated price per piece as if promotions apply.

examples: we could call this with some cart content if we want to hint the price for such quantity

[
getPromotedPrices( 'bulkOf3', productVariantId, true, {lines: [ {productVariantId: productVariantId, quantity: 3 ]} ),
getPromotedPrices( 'bulkOf6', productVariantId, true, {lines: [ {productVariantId: productVariantId, quantity: 6 ]} )
]

and get

[ ["default", 300], [ "bulkOf3", 280 ], [ "bulkOf6", 255 ] ]

we could call this function with order.couponCodes to list prices that "would be" with some coupon active like so:

getPromotedPrices( 'newcustomercoupon', productVariantId, true, {couponCodes: ['newbie']} )

and get

[ [ "default", 300 ], [ "newcustomercoupon", 270] ]

it might be helpful to also provide a default calculator with "promotionPrices" property that would equal to:

getPromotedPrices( 'default', productVariantId, true )

which would calculate basic promoted price taking into consideration current promotions and productvariantid and would be used for basic listings.

Describe alternatives you've considered Mirroring promotion logic in frontend app.

chladog commented 3 years ago

This would also help with missing list prices for member groups

martijnvdbrug commented 2 months ago

I've added the feature label and priority, but this sounds like a good use case for a custom plugin, outside of vendure/core?

The flexible nature of Vendure promotions might make it hard to resolve promoted prices for all different kind of custom promotions. I would say if this is in core, then it should be able to handle that. If it's fine to just show promoted prices for the promotions you use in your own project, it can probably be a custom plugin?