From 8c42388af196af44d408388501e2eaefd09b8728 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 10 Feb 2021 09:39:57 +0100 Subject: [PATCH] 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 --- app/serializers/api/variant_serializer.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb index 0306c95f95..5c99fc1730 100644 --- a/app/serializers/api/variant_serializer.rb +++ b/app/serializers/api/variant_serializer.rb @@ -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