Needs review
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Developer experience
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
4 Jul 2017 at 19:44 UTC
Updated:
21 May 2020 at 16:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
drugan commentedI 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
Comment #3
drugan commentedThough 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).
Comment #4
bojanz commentedForgot 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.
Comment #5
drugan commentedOkay, I'll look into it on the next week.
Comment #6
drugan commentedComment #7
drugan commentedPR: https://github.com/drupalcommerce/commerce/pull/849
Comment #8
drugan commentedComment #9
bojanz commentedWhile 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.
Comment #10
lisastreeter commentedI 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.
Comment #11
geek-merlin> 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.
Comment #12
geek-merlinhook_update_5 needs rename:
Comment #13
geek-merlinPatch flying in that renames this function to
commerce_product_post_update_2892207. No need to be consecutive here so think this is more robust.Comment #14
rgpublicRerolled the patch for current dev.
Comment #15
geek-merlinHere'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.