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

[5.x]: Cannot parse "-2.8421709430404E-14" to Money error with tax rate of 0 #3822

Closed
JodebaDigitalPulse opened this issue Dec 18, 2024 · 7 comments

Comments

@JodebaDigitalPulse
Copy link

JodebaDigitalPulse commented Dec 18, 2024

What happened?

Description

Getting an error "Cannot parse "-2.8421709430404E-14" to Money "

Traced back to this location in the code
craft\commerce\adjusters::_getTaxAmount() called from https://github.com/craftcms/commerce/blob/744dd561b7e6763a369465e31d98fecb6885ad09/src/adjusters/Tax.php#L263C22-L263C30

The result is a float, close to zero, but not 0

Steps to reproduce

  1. product with taxrate of 0
  2. trigger commerce/cart/update-cart from frontend

stacktrace

{
  "trace": [
    "#0 /application/vendor/moneyphp/money/src/Teller.php(394): Money\\Parser\\DecimalMoneyParser->parse()",
    "#1 /application/vendor/craftcms/commerce/src/helpers/Currency.php(117): Money\\Teller->convertToMoney()",
    "#2 /application/vendor/craftcms/commerce/src/behaviors/CurrencyAttributeBehavior.php(187): craft\\commerce\\helpers\\Currency::formatAsCurrency()",
    "#3 /application/vendor/yiisoft/yii2/base/ArrayableTrait.php(126): craft\\commerce\\behaviors\\CurrencyAttributeBehavior->craft\\commerce\\behaviors\\{closure}()",
    "#4 /application/vendor/yiisoft/yii2/base/ArrayableTrait.php(139): yii\\base\\Model->toArray()",
    "#5 [internal function]: yii\\base\\Model->yii\\base\\{closure}()",
    "#6 /application/vendor/yiisoft/yii2/base/ArrayableTrait.php(136): array_map()",
    "#7 /application/vendor/yiisoft/yii2/base/ArrayableTrait.php(139): yii\\base\\Model->toArray()",
    "#8 [internal function]: craft\\base\\Element->yii\\base\\{closure}()",
    "#9 /application/vendor/yiisoft/yii2/base/ArrayableTrait.php(136): array_map()",
    "#10 /application/vendor/craftcms/cms/src/base/Element.php(2659): craft\\base\\Element->traitToArray()",
    "#11 /application/vendor/craftcms/commerce/src/controllers/BaseFrontEndController.php(59): craft\\base\\Element->toArray()",
    "#12 /application/vendor/craftcms/commerce/src/controllers/CartController.php(566): craft\\commerce\\controllers\\BaseFrontEndController->cartArray()",
    "#13 /application/vendor/craftcms/commerce/src/controllers/CartController.php(331): craft\\commerce\\controllers\\CartController->_returnCart()",
    "#14 [internal function]: craft\\commerce\\controllers\\CartController->actionUpdateCart()",
    "#15 /application/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()",
    "#16 /application/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams()",
    "#17 /application/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction()",
    "#18 /application/vendor/craftcms/cms/src/web/Application.php(350): yii\\base\\Module->runAction()",
    "#19 /application/vendor/putyourlightson/craft-sprig-core/src/controllers/ComponentsController.php(109): craft\\web\\Application->runAction()",
    "#20 /application/vendor/putyourlightson/craft-sprig-core/src/controllers/ComponentsController.php(66): putyourlightson\\sprig\\controllers\\ComponentsController->runActionInternal()",
    "#21 [internal function]: putyourlightson\\sprig\\controllers\\ComponentsController->actionRender()",
    "#22 /application/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()",
    "#23 /application/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams()",
    "#24 /application/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction()",
    "#25 /application/vendor/craftcms/cms/src/web/Application.php(350): yii\\base\\Module->runAction()",
    "#26 /application/vendor/craftcms/cms/src/web/Application.php(649): craft\\web\\Application->runAction()",
    "#27 /application/vendor/craftcms/cms/src/web/Application.php(312): craft\\web\\Application->_processActionRequest()",
    "#28 /application/vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest()",
    "#29 /application/web/index.php(12): yii\\base\\Application->run()",
    "#30 {main}"
  ],
  "memory": 22700744,
  "exception": "[object] (Money\\Exception\\ParserException(code: 0): Cannot parse \"-2.8421709430404E-14\" to Money. at /application/vendor/moneyphp/money/src/Parser/DecimalMoneyParser.php:46)"
}

Craft CMS version

5.5.6.1

Craft Commerce version

5.2.9.1

PHP version

8.3.14

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Copy link

linear bot commented Dec 18, 2024

@LuukRM2000
Copy link

I am having the same issue

@eeeeeeeeeve
Copy link

We're also seeing the same issue on Commerce 5.2.11

@Romanavr
Copy link
Contributor

When this expected to be fixed?
We have a plenty of users who encountering it daily.

@Romanavr
Copy link
Contributor

@lukeholder Is there an update? Please fix it ASAP.
It's preventing our users from purchase flow as we have TAX rules with 0%.

@lukeholder
Copy link
Member

lukeholder commented Feb 2, 2025

I apologise for not responding to this ticket and communicating the status of this issue. As you can see above we were working on a fix in #3834 above but it was not included in the recent 5.3 release.

If you want to try the above fix we worked on, then in local development, first make sure you are upgraded to the latest release of Craft Commerce (5.3.0.1) and then change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "dev-feature/5.3-teller#7555049642caa68a58121925ed887f5ab916f6a3 as 5.3.0.1",
  "...": "..."
}

Then run composer update.

If you could please test the potential fix in local development, and let us know that it is working for you that would be great. We will also be testing it on our side over the next few hours. Once we confirm, we will push release the fix as soon as possible.

We will update our progress here.

Thanks.

@nfourtythree
Copy link
Contributor

Commerce version 5.3.1 has now been released with this fix included.

Thanks!

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

No branches or pull requests

6 participants