Skip to content

Commit

Permalink
Import product's invalid weight as 1 item
Browse files Browse the repository at this point in the history
We previously stored a scale which made the product screen believe that
we are dealing with weight.
  • Loading branch information
mkllnk committed Oct 15, 2024
1 parent 97b6289 commit 1eb7037
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ def self.apply(quantity, variant)
measure, unit_name, unit_scale = map_unit(quantity.unit)
value = quantity.value.to_f * unit_scale

# Import invalid value as one item.
if measure.in?(%w(weight volume)) && value <= 0
measure = "items"
unit_name = "items"
value = 1
end

# Items don't have a scale, only a value on the variant.
unit_scale = nil if measure == "items"

variant.variant_unit = measure
variant.variant_unit_name = unit_name if measure == "items"
variant.variant_unit_scale = unit_scale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

expect(variant.variant_unit).to eq "items"
expect(variant.variant_unit_name).to eq "Jar"
expect(variant.variant_unit_scale).to eq 1
expect(variant.variant_unit_scale).to eq nil
expect(variant.unit_value).to eq 3
end

Expand Down Expand Up @@ -141,7 +141,7 @@

expect(variant.variant_unit).to eq "items"
expect(variant.variant_unit_name).to eq "dozen"
expect(variant.variant_unit_scale).to eq 12
expect(variant.variant_unit_scale).to eq nil
expect(variant.unit_value).to eq 24
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
expect(subject).to be_persisted
expect(subject.name).to eq("Fillet Steak - 201g x 1 Steak")
expect(subject.variant_unit).to eq("items")
expect(subject.variant_unit_scale).to eq(nil)
expect(subject.variant_unit_with_scale).to eq("items")
expect(subject.unit_value).to eq(1)
end
end
Expand Down

0 comments on commit 1eb7037

Please sign in to comment.