I am making a custom store that can sell half pounds of items. I've noticed through sending calls through my plugin to the craft()->commerce_cart->addToCart($cart, $itemNumber, $qty); to add an item to an order while specifying a non-integer quantity gives me the error: "Qty must be an integer"

Is there any way to allow quantity to be a non-integer? Customers will be ordering in .5 pound increments occasionally. I am not anemic to plugin development and php so I thought I'd ask the community if there was a way around this, or if I'm stuck with Qty being an integer.

Couple other options I've though of:

  1. Make a custom field to deal with qty
  2. Split my items into .5 increments so someone adding 5.5 lbs would really be adding qty 11 and there'd be special things going on with the admin and front-end to hide that fact

Given how much of Commerce internally will be relying on whole number quantities, I think option 2 is the far better plan.

You can't add custom fields to line items currently, and while you might be able to hack something using the options/notes systems, or custom order fields on the order as a whole, I'd think this would get complex to maintain quickly. Best to use your minimum selling measure as the unit and dress it up front end.... that should work well and will be substantially easier to implement and (importantly) maintain.

With stores, even more than websites, long term ease of understanding and maintenance should be a high priority goal.

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.