add drop down list for unit preference

This commit is contained in:
Andy Brett
2020-09-07 13:26:09 -07:00
parent adb29a9c8f
commit 5a5cbbd318
3 changed files with 20 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ module Calculator
class Weight < Spree::Calculator
extend Spree::LocalizedNumber
preference :per_unit, :decimal, default: 0.0
preference :unit, :string, default: "kg"
preference :unit_from_list, :string, default: "kg"
localize_number :preferred_per_unit
def self.description
@@ -16,6 +16,10 @@ module Calculator
(total_weight(line_items) * preferred_per_unit).round(2)
end
def preferred_unit_from_list_values
["kg", "lb"]
end
private
def total_weight(line_items)