From 642cd85cb9bc477b1cf748c0c29d788889140c00 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Tue, 31 Oct 2023 18:40:24 +0100 Subject: [PATCH] update WeightsAndMeasures#scale_for_unit_value to only return units that are selected on 'Available Units' list --- app/services/weights_and_measures.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/services/weights_and_measures.rb b/app/services/weights_and_measures.rb index ada5523e22..d9e2c42cb8 100644 --- a/app/services/weights_and_measures.rb +++ b/app/services/weights_and_measures.rb @@ -46,7 +46,9 @@ class WeightsAndMeasures }.freeze def scales_for_variant_unit - @units[@variant.product.variant_unit] + @scales_for_variant_unit ||= @units[@variant.product.variant_unit].reject { |_scale, unit_info| + available_units.exclude?(unit_info['name']) + } end # Find the largest available and compatible unit where unit_value comes @@ -63,4 +65,8 @@ class WeightsAndMeasures largest_unit end + + def available_units + Spree::Config.preferences[:available_units].split(",") + end end