Make all calculators use FlatPercentPerItem instead of FlatPercentItemTotal

This commit is contained in:
Rohan Mitchell
2016-08-19 17:06:46 +10:00
parent 701c047a0a
commit 10b076562f
2 changed files with 31 additions and 2 deletions

View File

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

View File

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