jonassiewertsen / statamic-butik

"Butik" is a Scandinavian term for a small and medium-sized shop. Exactly what this Statamic addon has been crafted for.
43 stars 13 forks source link

Taxes with decimals #225

Closed rrelmy closed 3 years ago

rrelmy commented 3 years ago

Describe the bug

The butik does not play very well with taxes with a decimal (example: 7.7% in switzerland). In the cp there is no issue, everything can be created as expected with floats, but in the frontend there are multiple issues (there might be more than I found!)

How to reproduce

Steps to reproduce the behavior:

  1. Clone the starter kit like documented
  2. Set the tax to 7.7
  3. Try to add an item to the basket

Items can not be added to the basket

ErrorException: A non well formed numeric value encountered vendor/jonassiewertsen/statamic-butik/src/Checkout/Item.php:110

Looks like on this line a string is passed into a float variable https://github.com/jonassiewertsen/statamic-butik/blob/e5ff7a9d0ad2a6c1485deafbebcfdb4797e645e8/src/Checkout/Item.php#L110

Further errors have been found after changing the line to $this->taxRate = (float) $item->tax->percentage; so I could continue

Return value of Jonassiewertsen\StatamicButik\Shipping\ShippingAmount::taxPercentage() must be of the type int, string returned

Another case that returns float/string instead of int https://github.com/jonassiewertsen/statamic-butik/blob/e5ff7a9d0ad2a6c1485deafbebcfdb4797e645e8/src/Shipping/ShippingAmount.php#L68

I did not check the rest of the code!

Wrong tax percentage displayed in cart (Might be an issue in the starter kit and not the addon)

Only 7 instead of 7.7 is displayed

Statamic

Tax calculation is based on the int value instead of float

€ 192,00 VAT displayed € 12,56 Expected 13.73 (if I didn't made a mistake, 192-(192/107.7*100))

Expected behavior

It should just work :shrug:

Environment

Statamic 3.0.49 Solo Laravel 8.41.0 PHP 7.4.16 jonassiewertsen/statamic-butik 3.5.5 jonassiewertsen/statamic-livewire 2.5.0

rrelmy commented 3 years ago

😕 I can't reproduce the issues after changing the currency to swiss francs and a . delimiter

    'currency_name'      => 'CHF',
    'currency_isoCode'   => 'CHF', // Make sure to use ISO_4217 https://en.wikipedia.org/wiki/ISO_4217
    'currency_symbol'    => 'CHF',
    'currency_delimiter' => '.',

but it shows another issue, multiple taxes even if only one (7.7) is configured

Statamic
jonassiewertsen commented 3 years ago

I'll check for a bugfix.

Thanks for reaching out.

jonassiewertsen commented 3 years ago

I can't reproduce the issue right now. Please reopen in case you will run into this again.