Order-line item price computation with 0 decimals and tax inclusive price settings. #46126
Sidsector9
started this conversation in
Checkout Flow
Replies: 2 comments 2 replies
-
Would doing |
Beta Was this translation helpful? Give feedback.
0 replies
-
@senadir Thanks for looking into this. Your solution will work for the prices given in this example but will fail when the product prices are $7.75 or $13.5. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are facing an edge case problem while rendering the filtered order-line item prices.
The problem: Aggregation bias caused by error propagation due to rounding with 0 decimal numbers.
We are using the WooCommerce Deposits plugin.
In the following scenario where:
0
On the block Cart page, the order-line item of a product with deposit applied is incorrect.
The Deposits extension makes use of the
rest_request_after_callbacks
filter hook to filter the order-line item subtotal. For example like the following:If you observe the image above, the sum of the prices in red is higher than the price in green.
In the callback for
rest_request_after_callbacks
, Deposit sets the prices in red as following:Because the decimal setting is set to
0
,$money_formatter->format()
rounds up the prices if the decimal is>= 0.5
and rounds down if the decimal is< 0.5
. So this is what is happening:At the same time,
$data['items'][ $key ]['totals']->line_subtotal
and$data['items'][ $key ]['totals']->line_subtotal_tax
cannot be set to floating numbers as only the integer part is considered by Woo Core on the client side:woocommerce/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/cart-line-items-table/cart-line-item-row.tsx
Lines 152 to 155 in 7fe00de
Would you have any advice to best handle a situation like this?
Beta Was this translation helpful? Give feedback.
All reactions