diff --git a/app/services/variant_units/variant_and_line_item_naming.rb b/app/services/variant_units/variant_and_line_item_naming.rb index b9d726b6691..eabfc3a7b19 100644 --- a/app/services/variant_units/variant_and_line_item_naming.rb +++ b/app/services/variant_units/variant_and_line_item_naming.rb @@ -65,6 +65,7 @@ def update_units def unit_value_attributes units = { unit_presentation: option_value_name } units.merge!(variant_unit:) if has_attribute?(:variant_unit) + units.merge!(variant_unit_name: '') if reset_variant_unit_name? units end @@ -79,5 +80,9 @@ def option_value_name VariantUnits::OptionValueNamer.new(self).name end + + def reset_variant_unit_name? + has_attribute?(:variant_unit_name) && has_attribute?(:variant_unit) && variant_unit != 'items' + end end end diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index c0974a3baa8..70068b41645 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -987,11 +987,11 @@ variant.variant_unit = 'weight' variant.variant_unit_scale = 1 - variant.variant_unit_name = 'g' variant.save! expect(variant.variant_unit).to eq 'weight' expect(variant.unit_presentation).to eq "1g" + expect(variant.variant_unit_name).to eq('') variant.update(variant_unit: 'volume')