Hubs managers can choose the adapted weight and measure units for their shops given their own local situation

Job for me and @oeoeaio from product-curation to do a micro-inception on this get some idea of how hard it might be. Here’s summary of our brief - 15 mins, not thorough - thoughts.

Think it breaks down into these 4 things

  1. Ability to display and use US customary measurement units - workaround (available now)
  2. Access to US customary units when creating products, including auto-adjust to pick sensible unit for partial or large variants (e.g. set kg and have 0.2kg auto-display as 200g)
  3. Which units available for products - instance / enterprise
  4. Conversions of units for different customers e.g. have a product set in kg but display in lbs for USA customers (as raised by @tschumilas)

1. Display and use US-custom units

First up, there is quick and dirty workaround that people could already be using - just select items and set the custom unit that you want e.g.

and

Within this ‘solution’ there is no way to have different variants within the same product display as say lbs and ozs . . so you could end up with weird looking units, but workable

2. Access to US-custom units in product creation

But that is obviously not ideal. So the next step would be to have additional (or replacement) unit options appear to choose from when adding a product so that you can actually select standard weight / volume measures
image

We think this is might be just a case of creating some additional lines in lib/open_food_network/option_value_namer.rb for us-weight and us-volume or something
def scale_for_unit_value
units = {‘weight’ => {1.0 => ‘g’, 1000.0 => ‘kg’, 1000000.0 => ‘T’},
‘volume’ => {0.001 => ‘mL’, 1.0 => ‘L’, 1000.0 => ‘kL’}}

and getting the conversions right to enable the auto-adjust of units, so it handles big and small for these units e.g.

it looks like there is an additional - similar but different thing in product import code - app/models/product_import/unit_converter.rb - not sure if worth refactoring to have all handled from one place or if is different. didn’t spend time working it out.

and there is also a js side implementation to be considered - app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee

3. Which units are available for products?

Q: enable at instance level to choose which of these unit options appear and are available to enterprises AND/OR enable instances to customise for themselves - perhaps just tick on/off which ones they want to see

We didn’t discuss that, possibly could occur in inception - first cut could just be set in instance config so no need to even have interface for it, then deal with more customisability later if needed

4. Customise / convert display units for different Customers

The actual calculation to convert g to oz etc is obviously not complex (thanks to this etc ;). So the question is where or how this be handled. Options might include:

  • shop preference - and have a different shopfront for usa and canada customers for example
  • customer preference

Seems like this would be beyond ‘minimum viable feature’ and could be worked out after the basics above were done

Disclaimer: As mentioned above this was a quick discussion to fly a finger in the wind about how big / hard this is.

Assuming 1, 2 and maybe 3 - we think this is pretty doable. We had a bit of a discussion (with @sstead also) whether there are other places where unit conversions (just scaling within same unit) might cause problems - like group buy, bulk order management, reports etc and our first thinking is that it shouldn’t.

Rob had a slight concern about decimal places / not clean round conversions like metric - but we figured there must be a standard somewhere for how many places etc to keep if needed, and we’re only converting one way not then trying to use that and convert back, we think, so we think probably ok . .

Wonder if @Matt-Yorkley might be good person to do this, given head in all this stuff for product import recently. You may actually be more across / have better idea than Rob and I if there are other implications

Thoughts? Is this roughly what needs to happen? Have we missed many implications?

1 Like