From 10b076562f8ace7d11a1bb504eef5f5337428ef9 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 19 Aug 2016 17:06:46 +1000 Subject: [PATCH] Make all calculators use FlatPercentPerItem instead of FlatPercentItemTotal --- ...wap_calculator_to_flat_percent_per_item.rb | 29 +++++++++++++++++++ db/schema.rb | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160819065331_swap_calculator_to_flat_percent_per_item.rb diff --git a/db/migrate/20160819065331_swap_calculator_to_flat_percent_per_item.rb b/db/migrate/20160819065331_swap_calculator_to_flat_percent_per_item.rb new file mode 100644 index 0000000000..eb8e206e8f --- /dev/null +++ b/db/migrate/20160819065331_swap_calculator_to_flat_percent_per_item.rb @@ -0,0 +1,29 @@ +class SwapCalculatorToFlatPercentPerItem < ActiveRecord::Migration + class Spree::Calculator < ActiveRecord::Base + end + + def up + Spree::Calculator.where(calculable_type: "EnterpriseFee", type: 'Spree::Calculator::FlatPercentItemTotal').each do |c| + swap_calculator_type c, 'Calculator::FlatPercentPerItem' + end + end + + def down + Spree::Calculator.where(calculable_type: "EnterpriseFee", type: 'Spree::Calculator::FlatPercentPerItem').each do |c| + swap_calculator_type c, 'Calculator::FlatPercentItemTotal' + end + end + + + private + + def swap_calculator_type(calculator, to_class) + value = calculator.preferred_flat_percent + + calculator.type = to_class + calculator.save + + calculator = Spree::Calculator.find calculator.id + calculator.preferred_flat_percent = value + end +end diff --git a/db/schema.rb b/db/schema.rb index 9a825e299c..48b07e3cdb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160713013358) do +ActiveRecord::Schema.define(:version => 20160819065331) do create_table "account_invoices", :force => true do |t| t.integer "user_id", :null => false @@ -582,9 +582,9 @@ ActiveRecord::Schema.define(:version => 20160713013358) do t.string "email" t.text "special_instructions" t.integer "distributor_id" + t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" - t.integer "order_cycle_id" t.integer "cart_id" t.integer "customer_id" end