diff --git a/engines/dfc_provider/app/services/quantitative_value_builder.rb b/engines/dfc_provider/app/services/quantitative_value_builder.rb index 10896578b50..0bf041f1eab 100644 --- a/engines/dfc_provider/app/services/quantitative_value_builder.rb +++ b/engines/dfc_provider/app/services/quantitative_value_builder.rb @@ -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 diff --git a/engines/dfc_provider/spec/services/quantitative_value_builder_spec.rb b/engines/dfc_provider/spec/services/quantitative_value_builder_spec.rb index 04783becfad..c2ba3a4bf14 100644 --- a/engines/dfc_provider/spec/services/quantitative_value_builder_spec.rb +++ b/engines/dfc_provider/spec/services/quantitative_value_builder_spec.rb @@ -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 @@ -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 diff --git a/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb b/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb index 89b628150e0..8c307fe5a59 100644 --- a/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb +++ b/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb @@ -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