vendure icon indicating copy to clipboard operation
vendure copied to clipboard

Gross price display in product variant price detail is not based on the one calculated by a strategy

Open floze opened this issue 1 year ago • 2 comments

Describe the bug The price including taxes displayed in the product-variant-detail section seems to be based on the plain value, i.e. not affected by a ProductVariantPriceCalculationStrategy. Everywhere else though, any "price with tax" seems to be based on the strategy calculation, if set.

To Reproduce Steps to reproduce the behavior:

  1. Have a productVariantPriceCalculationStrategy configured
  2. Go to /admin/catalog/products/1/variants/1
  3. Scroll down to "Price and tax"
  4. See error

Expected behavior The displayed gross price should be based on the strategy calculation. Maybe the strategy calculation result should even be displayed as well beside the price input.

Environment (please complete the following information):

  • @vendure/core version: v2.1.0
  • @vendure/admin-ui-plugin v2.1.0

floze avatar Nov 05 '23 14:11 floze

The issue here is that the ProductVariantPriceCalculationStrategy.calculate() method is one-way: i.e. it takes the "raw" price from the ProductVariantPrice entity in the DB and transforms it in some way.

When updating a price, there is no equivalent reverse operation that can take a "calculated" value and convert it into the "raw" value to be stored in the DB. This is why we currently just use "raw" values in the Admin UI when modifying the price(s) for a variant.

But I do see the issue where there is a mismatch between the value in the price input field and the expected "calculated" value.

So I think the best solution would be along the lines of your suggestion - to keep the existing "raw" input, but additionally show the "calculated" price too.

I would imagine it would also be desirable to be able to live-preview how the calculated price would change in response to changes to the "raw" price. That would require a new query operation to be defined which is capable to running the strategy on-the-fly.

I think for now a simple and acceptable first step is to at least show the "calculated" price near the raw input if it differs.

michaelbromley avatar Mar 04 '24 15:03 michaelbromley

Done together with #2903

dlhck avatar Sep 27 '24 13:09 dlhck