vendure
vendure copied to clipboard
Gross price display in product variant price detail is not based on the one calculated by a strategy
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:
- Have a
productVariantPriceCalculationStrategy
configured - Go to
/admin/catalog/products/1/variants/1
- Scroll down to "Price and tax"
- 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
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.
Done together with #2903