Problem/Motivation

It seems like when we were preparing for D9 we lost a few improvements made along the way. One was validation for non-numeric and empty values. The other is the inclusion of the price token in the error message displayed when an invalid amount is entered.

Non-Numeric Validation

When I enter a string with non numeric characters like "A1" or simply leave the field blank "" and press "Add to Cart" an uncaught exception is produced. Here are the errors:

InvalidArgumentException: The provided value "" is not a numeric value. in Drupal\commerce_price\Calculator::assertNumberFormat() (line 261 of /var/www/html/web/modules/contrib/commerce/modules/price/src/Calculator.php).

InvalidArgumentException: The provided value "dad" is not a numeric value. in Drupal\commerce_price\Calculator::assertNumberFormat() (line 261 of /var/www/html/web/modules/contrib/commerce/modules/price/src/Calculator.php).

This was originally addressed in this issue (#3075504).

Make validation message include @price token
It is a benefit for developers to be able to use the @price token when performing string overrides to change the validation message we produce when a price is below the minimum amount.

We addressed this in issue #3077250, but lost it along the way.

Steps to reproduce

Both bugs:

Create a clean D9 installation. Install Commerce ^2.28 via stock instructions. Install the commerce_choose_price 8.x-1.x widget.

Enable commerce, commerce_order, commerce_product, commerce_cart, commerce_checkout, commece_product and commerce_choose_price.

Configure the default product and order item type to use the choose price widget.

Non-Numeric Validation

Visit the product and enter a non-numeric or blank value. Press "Add to Cart".

Make validation message include @price token

Attempt to include the price in a string override of our current message "The chosen price is too low".

Proposed resolution

Return these two fixes that were dropped.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lkacenja created an issue. See original summary.

lkacenja’s picture

Title: Non-numeric or empty values produce an uncaught exception » Return numeric price validation and tokenized message
Issue summary: View changes

Broadening scope of ticket to include a couple things we lost along the way.

  • 7d613be committed on 3255026-return-numeric-price
    #3255026 Fix non-numeric and empty price exception. Return @price token...

greggles’s picture

Status: Active » Needs review

In my opinion this is "RTBC" since these changes were already committed and they were removed without a reason, which seems like a mistake.

cyu’s picture

Status: Needs review » Reviewed & tested by the community

I'm using this patch now and both of those fixes work well for me. Thanks.

  • 7d613be committed on 8.x-1.x
    #3255026 Fix non-numeric and empty price exception. Return @price token...
greggles’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for that confirmation and your ongoing help with the module, cYu. I've merged this now and will make a new release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.