Skip to content

Commit

Permalink
Merge pull request #13027 from chahmedejaz/bugfix/13026-reset-variant…
Browse files Browse the repository at this point in the history
…-unit-name

Changing a variant unit scale from items to weight/volume does not remove variant unit name
  • Loading branch information
filipefurtad0 authored Dec 20, 2024
2 parents 0f706a9 + 3e031ab commit e2e2285
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 e2e2285

Please sign in to comment.