diff --git a/lib/open_food_network/option_value_namer.rb b/lib/open_food_network/option_value_namer.rb index 2c497b6c1a..e7b929a029 100644 --- a/lib/open_food_network/option_value_namer.rb +++ b/lib/open_food_network/option_value_namer.rb @@ -65,15 +65,15 @@ module OpenFoodNetwork def scale_for_unit_value units = { 'weight' => { - 1.0 => { 'name' => 'g', 'system' => 'metric' }, - 28.34952 => { 'name' => 'oz', 'system' => 'imperial' }, - 453.6 => { 'name' => 'lb', 'system' => 'imperial' }, - 1000.0 => { 'name' => 'kg', 'system' => 'metric' }, + 1.0 => { 'name' => 'g', 'system' => 'metric' }, + 28.34952 => { 'name' => 'oz', 'system' => 'imperial' }, + 453.6 => { 'name' => 'lb', 'system' => 'imperial' }, + 1000.0 => { 'name' => 'kg', 'system' => 'metric' }, 1_000_000.0 => { 'name' => 'T', 'system' => 'metric' } }, 'volume' => { - 0.001 => { 'name' => 'mL', 'system' => 'metric' }, - 1.0 => { 'name' => 'L', 'system' => 'metric' }, + 0.001 => { 'name' => 'mL', 'system' => 'metric' }, + 1.0 => { 'name' => 'L', 'system' => 'metric' }, 1000.0 => { 'name' => 'kL', 'system' => 'metric' } } } @@ -86,8 +86,8 @@ module OpenFoodNetwork product_scale_system = scales[product_scale.to_f]['system'] largest_unit = scales.select { |scale, unit_info| unit_info['system'] == product_scale_system && - @variant.unit_value/scale >= 1 - }.sort.last + @variant.unit_value / scale >= 1 + }.max largest_unit = units[@variant.product.variant_unit].first if largest_unit.nil? [largest_unit[0], largest_unit[1]["name"]] diff --git a/lib/open_food_network/variant_and_line_item_naming.rb b/lib/open_food_network/variant_and_line_item_naming.rb index b38538a1a0..3b5a7de47c 100644 --- a/lib/open_food_network/variant_and_line_item_naming.rb +++ b/lib/open_food_network/variant_and_line_item_naming.rb @@ -18,14 +18,17 @@ module OpenFoodNetwork order("#{Spree::OptionType.table_name}.position asc") end - values.map { |option_value| presentation(option_value) }.to_sentence(words_connector: ", ", two_words_connector: ", ") + values.map { |option_value| + presentation(option_value) + }.to_sentence(words_connector: ", ", two_words_connector: ", ") end def presentation(option_value) if option_value.option_type.name == "unit_weight" if has_attribute?(:display_as) && display_as.present? return display_as - elsif respond_to?(:variant) && variant.present? && variant.respond_to?(:display_as) && variant.display_as.present? + elsif respond_to?(:variant) && variant.present? && + variant.respond_to?(:display_as) && variant.display_as.present? return variant.display_as end end @@ -61,7 +64,8 @@ module OpenFoodNetwork def unit_to_display if has_attribute?(:display_as) && display_as.present? display_as - elsif respond_to?(:variant) && variant.present? && variant.respond_to?(:display_as) && variant.display_as.present? + elsif respond_to?(:variant) && variant.present? && + variant.respond_to?(:display_as) && variant.display_as.present? variant.display_as else options_text