Skip to content

Commit

Permalink
13026: reset variant unit name if unit is not items
Browse files Browse the repository at this point in the history
  • Loading branch information
chahmedejaz committed Dec 10, 2024
1 parent ee2a6bf commit 3e031ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/services/variant_units/variant_and_line_item_naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 3e031ab

Please sign in to comment.