Submitting add to cart form with empty quantity value results in an exception

Created on 21 February 2020, over 4 years ago
Updated 17 November 2023, 8 months ago

Problem/Motivation

Steps to reproduce:

  • Install the Commerce demo
  • Enable "Quantity" field/widget on the order item type, "Add to cart" form display
  • Go to a sample product page
  • Delete default quantity value (1) and press "Add to cart"
  • InvalidArgumentException is thrown with a message: The provided value "" is not a numeric value
InvalidArgumentException: The provided value "" is not a numeric value. in Drupal\commerce_price\Calculator::assertNumberFormat() (line 261 of modules/contrib/commerce/modules/price/src/Calculator.php).
Drupal\commerce_price\Calculator::multiply('99.990000', '') (Line: 155)
Drupal\commerce_price\Price->multiply('') (Line: 332)
Drupal\commerce_order\Entity\OrderItem->recalculateTotalPrice() (Line: 134)
Drupal\commerce_order\Entity\OrderItem->setUnitPrice(Object) (Line: 231)
Drupal\commerce_cart\Form\AddToCartForm->buildEntity(Array, Object) (Line: 190)
Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object)

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

2.0

Component

Cart

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024