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:
Jean-Baptiste Bellet
2021-02-10 09:39:57 +01:00
parent d97b46cd5b
commit 8c42388af1

View File

@@ -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