How to reproduce:
* Add some products with decimal quantities (weight!)
* Note that price is calculated correctly
* Click "Payment and completion"

Form error: Quantity is not a valid number.

Remaining Work:

Finish tests and fix decimal issue reported by Fred

Estimated Time Remaining: 2hrs

Comments

axel.rutz created an issue. See original summary.

subhojit777’s picture

Assigned: Unassigned » subhojit777

Looking into it.

I was able to replicate the problem. IMO the check should be made based on whether the product has fraction quantity allowed or not. I will check how Commerce core does it OR what it has.

subhojit777’s picture

Assigned: subhojit777 » Unassigned

Some work came up.

subhojit777’s picture

In a vanialla Commerce installation you can find the decimal setting for quantity here admin/commerce/config/order-item-types/default/edit/form-display/add_to_cart. Change the quantity widget to Quantity and you will see the decimal setting.

I believe we can do something similar in the POS.

smccabe’s picture

Agree, we should match the what Commerce does for the cart.

shabana.navas’s picture

Status: Active » Needs review
StatusFileSize
new3.77 KB

Patch attached. This matches what Commerce core is doing.

Status: Needs review » Needs work

The last submitted patch, 6: decimal_quantity_breaks_checkout-2951783-6.patch, failed testing. View results

jnrfred’s picture

#6 patch sets the quantity field by default to accept integer values but does not work when you check the option to allow decimal values i.e decimal values are rounded up.

shabana.navas’s picture

Thanks Fred, I'll look into that, also need to fix the failing tests.

smccabe’s picture

Issue summary: View changes
gmem’s picture

Status: Needs work » Needs review
StatusFileSize
new14.51 KB

Rerolled the patch and updated the schema, also updated the tests to remove the decimals from the quantities.

Status: Needs review » Needs work

The last submitted patch, 11: decimal_quantity_breaks_checkout-2951783-7.patch, failed testing. View results

gmem’s picture

Fixed missing schema, turns out bool != boolean. Test passes locally now.

gmem’s picture

Status: Needs work » Needs review
smccabe’s picture

Status: Needs review » Needs work

Few todos:

  • Should we default the allow decimal option to true for existing setups, so that it doesn't change there functionality?
  • We should have at least 1 test that tests a decimal quantity setting, to confirm that option works
  • Why do we set the max to 9999? i know most of our users will probably be less than that, but it seems like an unnecessary limit, maybe I'm selling 10,000 $0.05 washers or something.
gmem’s picture

This patch just adds a test for the decimal setting and fixes a small typo, decimals don't seem to be returned properly in the form however and has to be investigated - might have something to do with how it's being rounded in src/Plugin/Field/FieldWidget/PosOrderItemWidget.php L270-276 (or so).

gmem’s picture

  • Removed quantity limit.
  • Changed defaults to allow decimals to two places.
  • Added input for number of decimal places in input.
  • Rewrote some of the logic for calculating the returned quantity.
  • Rewrote test to account for new defaults.
  • Removed changes to other tests with new default.

Passing locally, although Firefox seems to round the x.00 decimals to x, despite both the value and step, which is a bit weird UX wise (Chrome renders this fine).

gmem’s picture

Status: Needs work » Needs review

Fail related to #2986424: Refactor Tests

gmem’s picture

smccabe’s picture

StatusFileSize
new12.46 KB

rerolled now that #2986424: Refactor Tests has landed

smccabe’s picture

Status: Needs review » Needs work

When I disabled decimals, I was still able to input decimal quantities. Also, I would update your tests to use something like 1.50 and 1.5453 to test the right number of decimals and confirm that things are working, as 1 and 1.00 are the same and won't show a flaw well

gmem’s picture

Updated the test to insert and test decimal values in the quantity field. I'm not sure if there's a way to completely restrict an HTML number input from having decimals input, but at the very least we can reject it properly.

gmem’s picture

Status: Needs work » Needs review
StatusFileSize
new13.65 KB

Removed round() when decimals are enabled and reverted to previous method.

smccabe’s picture

Status: Needs review » Needs work

This still isn't working right for me, although I didn't see anything obviously wrong in the code

If i try and set to 3 digits, it can get stuck not letting me user the up/down arrows of the number field, if i input a number manually, it rounds it to 2 decimal places even though I asked for 3. The step is set right, but the validation seems broken.

Also, and this is possibly not even worth fixing, but if I have decimals disable and set it to like .2 it will remove my product, because it rounds down to 0. This is pretty edge case, but it is also unexpected behaviour to the user.

gmem’s picture

So because Commerce rounds the order item quantity itself we can't really be as flexible as we'd like (e.g precise weight), instead for the quantity field we match what Commerce does for the cart page (which actually doesn't seem to be working for me). If we wanted to enable things like precise weight we'd probably need to implement another field to order_item. Also updated test to check that step is set correctly.

gmem’s picture

Status: Needs work » Needs review
StatusFileSize
new16.75 KB

Really need to remember to remove debugging screenshots... fixed.

  • smccabe committed afa499d on 8.x-2.x authored by gmem
    Issue #2951783 by gmem, smccabe, shabana.navas, subhojit777, axel.rutz,...
smccabe’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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