Split from #2794909: The quantity "step" must be configurable on the widget level. Deserves a proper discussion.

Currently the order item quantity uses the default precision and scale (10/2), allowing for 8 digits + 2 decimals (99 999 999.99).
Some cases require 3 decimals, and it feels like that would be a fine standard for Commerce. 7 digits + 3 decimals (9 999 999.999).
I am assuming that there is no reasonable use case for more digits, but is there a reasonable use case for more than 3 decimals?

Comments

bojanz created an issue. See original summary.

drugan’s picture

I think that if we hardcode size in the definition of the quantity field then the precision == 10 and scale == 3 would be enough for the most decimal quantity use cases. For example, if some product measured by metres, litres or kilograms then the value chosen by a customer may look like this:

1.999 m OR L OR kg

Also, it saves memory because using redundant size consumes it even the value chosen by a customer is equal to 1 then saved in database it will look like this:

1.000

drugan’s picture

Status: Active » Needs review
StatusFileSize
new1.81 KB

Though by default precision == 10, anyway I've added this setting in order to avoid surprises when default setting will possibly change and just for verbosity purposes (instead of a comment).

bojanz’s picture

Status: Needs review » Needs work

Forgot about this issue.

Missing pieces:
1) Additional steps in QuantityWidget::settingsForm()
2) Switching the widget on the form display to commerce_quantity (it's already a default in the OrderItem, but the exported form display was never updated).
3) An update hook for the storage definition (to change the precision on existing sites)
4) Post-update hooks for the view and the form display that have been updated.

drugan’s picture

Assigned: Unassigned » drugan

Okay, I'll look into it on the next week.

drugan’s picture

Title: Increase the default order item quantity precision » Increase the order item quantity scale
drugan’s picture

Status: Needs work » Needs review
StatusFileSize
new8.3 KB
drugan’s picture

Assigned: drugan » Unassigned
bojanz’s picture

While we're at it, we should fix the field definition, it is marked as "read only" (which makes no sense), but isn't marked as "required", which is important. We should also provide a "min" higher than 0 (smallest value for the current scale, so 0.001), cause there's probably no reason to support a 0 quantity.

lisastreeter’s picture

I understand if this is a weird exception (and thus should be handled with custom code), but I do have a use case for order item quantities of 0. One of our order types is a sample/reservation. A customer can request a small sample of a particular lot of a product at the same time he places a hold on an additional quantity of that lot. That gives the customer a chance to evaluate the sample for a couple months (in scientific experimentation) without worrying about the lot becoming depleted in the meantime. The quantity for the order item is the sample quantity (since this is the amount that is actually being purchased/removed from inventory). The price is set to zero. And the hold amount is managed with a custom quantity field (and sometimes increased/reduced manually through the admin UI.) All that is fine, but... it's also quite common for a customer to want to place an order for a hold without requesting a sample quantity. In that case, the order item quantity is 0.

At one point, I did try to set this sample/hold system so that it was separate from regular orders, but unfortunately, these sample orders need to have invoice numbers sequenced along with regular orders. And despite having a total price of $0, they are treated as normal orders in every other way.

One additional note: these sample/hold orders do not need to work with the cart system, since they're entered internally. So restricting the quantity for a cart item to > 0 would be perfectly fine. (Though perhaps confusing if the order item quantity could be zero but the cart quantity cannot.

geek-merlin’s picture

> cause there's probably no reason to support a 0 quantity.

We have also a workflow misfit for this, where shoppers
* first collect products which then have quantity 0
* then go to a weighting station where they add their quantities

So to be precise, we need storage to support quantity=0, but don't need (and want) form widget to support quantity=0.

geek-merlin’s picture

Status: Needs review » Needs work

hook_update_5 needs rename:

Fatal error: Cannot redeclare commerce_product_post_update_5() (previously declared in /var/www/html/web/modules/contrib/commerce/modules/product/commerce_product.post_update.php:128) in /var/www/html/web/modules/contrib/commerce/modules/product/commerce_product.post_update.php on line 210
geek-merlin’s picture

Status: Needs work » Needs review
StatusFileSize
new9.07 KB

Patch flying in that renames this function to commerce_product_post_update_2892207. No need to be consecutive here so think this is more robust.

rgpublic’s picture

Rerolled the patch for current dev.

geek-merlin’s picture

StatusFileSize
new8.97 KB

Here's a plain re-roll onto current dev #55434c4bd74.

Note that it won't make sense on current stable 2.17 as since then we have one more update hook.
So to test, composer require drupal/commerce:2.x-dev#55434c4bd74.