Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong calculation of total price of cart #544

Open
martingalovic opened this issue Jan 20, 2019 · 5 comments
Open

Wrong calculation of total price of cart #544

martingalovic opened this issue Jan 20, 2019 · 5 comments

Comments

@martingalovic
Copy link

martingalovic commented Jan 20, 2019

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 be2.4(because only items has price with tax of12so12 * 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.

@bumbummen99
Copy link

bumbummen99 commented Jan 20, 2019

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?

@martingalovic
Copy link
Author

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

@bumbummen99
Copy link

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.

bumbummen99 added a commit to bumbummen99/LaravelShoppingcart that referenced this issue Jan 21, 2019
@jordantsap
Copy link

Everything as it should be
https://github.com/bumbummen99/LaravelShoppingcart

@martingalovic
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@jordantsap @bumbummen99 @martingalovic and others