mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
add a randomized unit price for variant
unit price is composed with : - a unit_price_price which is a number that can be localized (depending on the currency) - a unit_price_unit which can be either `item` of `kg` @andrewpbrett will do stuff to have a relevant unit price for each variant
This commit is contained in:
@@ -3,7 +3,8 @@ class Api::VariantSerializer < ActiveModel::Serializer
|
||||
:options_text, :unit_value, :unit_description, :unit_to_display,
|
||||
:display_as, :display_name, :name_to_display,
|
||||
:price, :on_demand, :on_hand, :fees, :price_with_fees,
|
||||
:tag_list, :thumb_url
|
||||
:tag_list, :thumb_url,
|
||||
:unit_price_price, :unit_price_unit
|
||||
|
||||
delegate :price, to: :object
|
||||
|
||||
@@ -38,4 +39,12 @@ class Api::VariantSerializer < ActiveModel::Serializer
|
||||
"/noimage/mini.png"
|
||||
end
|
||||
end
|
||||
|
||||
def unit_price_price
|
||||
(rand * 10).round(2)
|
||||
end
|
||||
|
||||
def unit_price_unit
|
||||
rand > 0.5 ? "item" : "kg"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user