From 82fa5416cefa9f8cefec9b826175b25afc451d14 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 29 Nov 2016 15:23:36 +0100 Subject: [PATCH] fix creation of prices with float values --- app/controllers/api/coupons_controller.rb | 2 +- app/controllers/api/events_controller.rb | 4 ++-- app/controllers/api/plans_controller.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/coupons_controller.rb b/app/controllers/api/coupons_controller.rb index e65abca1a..9057a2123 100644 --- a/app/controllers/api/coupons_controller.rb +++ b/app/controllers/api/coupons_controller.rb @@ -83,7 +83,7 @@ class API::CouponsController < API::ApiController @parameters else @parameters = params - @parameters[:coupon][:amount_off] = @parameters[:coupon][:amount_off].to_i * 100.0 if @parameters[:coupon][:amount_off] + @parameters[:coupon][:amount_off] = @parameters[:coupon][:amount_off].to_f * 100.0 if @parameters[:coupon][:amount_off] @parameters = @parameters.require(:coupon).permit(:name, :code, :percent_off, :amount_off, :validity_per_user, :valid_until, :max_usages, :active) end diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index a02590a9b..ef4144d6f 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -86,12 +86,12 @@ class API::EventsController < API::ApiController event_preparams.merge!(availability_attributes: {id: event_preparams[:availability_id], start_at: start_at, end_at: end_at, available_type: 'event'}) .except!(:start_date, :end_date, :start_time, :end_time, :all_day) # convert main price to centimes - event_preparams.merge!(amount: (event_preparams[:amount].to_i * 100 if event_preparams[:amount].present?)) + event_preparams.merge!(amount: (event_preparams[:amount].to_f * 100 if event_preparams[:amount].present?)) # delete non-complete "other" prices and convert them to centimes unless event_preparams[:event_price_categories_attributes].nil? event_preparams[:event_price_categories_attributes].delete_if { |price_cat| price_cat[:price_category_id].empty? or price_cat[:amount].empty? } event_preparams[:event_price_categories_attributes].each do |price_cat| - price_cat[:amount] = price_cat[:amount].to_i * 100 + price_cat[:amount] = price_cat[:amount].to_f * 100 end end # return the resulting params object diff --git a/app/controllers/api/plans_controller.rb b/app/controllers/api/plans_controller.rb index 968875df3..f732d39bd 100644 --- a/app/controllers/api/plans_controller.rb +++ b/app/controllers/api/plans_controller.rb @@ -81,9 +81,9 @@ @parameters else @parameters = params - @parameters[:plan][:amount] = @parameters[:plan][:amount].to_i * 100.0 if @parameters[:plan][:amount] + @parameters[:plan][:amount] = @parameters[:plan][:amount].to_f * 100.0 if @parameters[:plan][:amount] @parameters[:plan][:prices_attributes] = @parameters[:plan][:prices_attributes].map do |price| - { amount: price[:amount].to_i * 100.0, id: price[:id] } + { amount: price[:amount].to_f * 100.0, id: price[:id] } end if @parameters[:plan][:prices_attributes] @parameters = @parameters.require(:plan).permit(:base_name, :type, :group_id, :amount, :interval, :interval_count, :is_rolling,