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

[4.x]: Text input in LineItem/Order adjustment Amount field causes errors and/or grey screens #3351

Closed
Kent-N opened this issue Dec 13, 2023 · 1 comment
Labels
bug commerce4 Issues related to Commerce v4

Comments

@Kent-N
Copy link

Kent-N commented Dec 13, 2023

What happened?

Description

This issue is somewhat similar to #3067

When adding or editing an adjustment, either on a LineItem or the full order, there's several issues related to input in the 'amount' field. You get errors if you leave the field empty or if Craft evaluates the field as a string. There's sometimes valid reasons to start typing a "string", such as negative numbers.

This is the error I usually get: "Cannot assign string to property craft\commerce\models\OrderAdjustment::$amount of type float at /var/www/html/vendor/craftcms/commerce/src/controllers/OrdersController.php:1442", the line can also be 1470.

Steps to reproduce

  1. View any order
  2. Click 'edit' on a LineItem or 'Edit adjustments' at the bottom on the Order.
  3. Add an adjustment
  4. Delete the default "0" and delay typing the amount you want for 1-2 seconds.
  5. 'Internal Server Error' error and most of the order screen turns grey and unresponsive.

Basically any situation where the first value in the amount field isn't numerical (or "-" + a number), an error is thrown. This causes issues if users are slow typers. Example: They want to type "-100" in the amount field, start with "-" and are a bit slow to hit the 1 key. The order recalculates with just "-" in the amount field for an adjustment. An error is thrown because it expects a float and got a string. The user is confused because they weren't even done typing and there's no meaningful error message.

Expected behavior

More graceful handling of these errors. Maybe just reset the field to 0 on invalid input.

Alternatively, throttle the recalculate/update more than 1-2 seconds after input change, so slow typers have a chance to finish typing what they want to before the order recalculates.

Actual behavior

'Internal Server Error' and grey screens.

Craft CMS version

Craft Pro 4.5.11.1

Craft Commerce version

4.3.2

PHP version

8.1.26

Operating system and version

Linux 6.1.0-0.deb11.11-amd64

Database type and version

MariaDB 10.11.5

Image driver and version

No response

Installed plugins and versions

No response

@nfourtythree
Copy link
Contributor

Hi @Kent-N

Thank you for reporting this. We have created a fix for this issue which will be included in the next release of Commerce.

Thanks!

lukeholder added a commit that referenced this issue Jan 10, 2024
…ents-amount

Fixed #3351 locking order edit when entering NaN adjustments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce4 Issues related to Commerce v4
Projects
None yet
Development

No branches or pull requests

2 participants