0

I have a specific requirement for a certain product type in Commerce to accept the line-item quantity as a float rather than an integer. Is this possible?

For example 5.34 rather than 5.

The context

  • Product Type 'Tile' is sold in sqm (squared meters)
  • User chooses required quality in sqm when they add to cart
  • Drupal works out the minimum amount of tiles required for the chosen sqm value
  • The sqm value is then adjusted based on number of whole tiles required
  • Therefore sale price may be 5.12 sqm, if 5 sqm is required (because that is the specific sqm for X whole tiles.
  • quick fix: use sqcm ;) – Andre Baumeier May 18 '15 at 18:55
  • Hey @Andre-B, this would be a simple fix but the standard for measuring floor space is sqm. From a UX perspective I think it would be very confusing for anyone ordering from the site to see or use sqcm. But helpful avenue solution nonetheless. – Scott Lawrence May 19 '15 at 0:26
1

Drupal Commerce supports decimal quantities, there just isn't a UI based configuration mechanism for using that vs. integer quantities. You have to alter the Add to Cart form and Shopping Cart form to change the #datatype property on quantity text fields to 'decimal' (or whatever you prefer) and then add appropriate validate handlers to ensure valid decimal values are being submitted. Search the code for datatype and you'll see the integer example code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.