LaravelShoppingcart
LaravelShoppingcart copied to clipboard
Wrong calculation of total price of cart
Hey i have this problem:
I have Product with price 12.00, so I call Cart::add($product)
$product implements Buyable
and getBuyablePrice()
returns 12
My tax in config/cart.php
is 20
So the Cart::subtotal()
(item * quantity - items tax) should be 12 * 0.8 = 9.6
but it is 12
And the Cart::total()
(items * quantity) should be 12
but it's 14' And finally
Cart::tax()should be
2.4(because only items has price with tax of
12so
12 * 0.2) but it's somehow
2`.
Method | Expected | Actual (wrong) |
---|---|---|
Cart::subtotal() |
9.6 (12*0.8) |
12 |
Cart::total() |
12 (only one item in cart with price of 12 w/ tax ) |
14 |
Cart::tax() |
2.4 (12 * 0.2 ) |
2 |
Could you check this out? Thanks.
I hope i get it right^^:
If subtotal is price * qty - tax
then shouldn't it be 12 * 0.8 - (12 * 0.8) * 0.2
?
The subtotal price is 9.6 because you have 0.8 qty.
The tax has to be 1.92 because 0.96 * 0.2 = 0.192
.
Then Total should be 11.52.
I have written a small test to validate the behaviour and it seems to work as expected. Could you provide the code you use to access the mentioned values?
The price is 12 for 1 qty including tax
0.8 is multiplier for price without tax (1210.8)
subtotal should be then 1210.8 = 9.6 tax 2.4 total 12
Sorry if i get you wrong but why do you want to include the tax of a full item (1qty) when you set it to 0.8 qty? Are you sure the tax sould not be 0.96 * 0.2?
Beside that i have no clue why it gives you a subtotal of 12 if you have set the qty to 0.8. Also i am curious about why there are no decimals in your result. The package uses number_format with the values set in your cart config. Did you modify these?
It seems to work fine on my end.
Everything as it should be https://github.com/bumbummen99/LaravelShoppingcart
You get me wrong,
I call Cart::add($product, 1)
(qty is 1) (product price is 12.00
)
But the tax is set to 20% (multiplier for price without tax should be 0.8
) so the price without tax should be 9.40
My point is, when I call Cart::add()
, price is included with tax. And this package seems to handle it like price without tax.