Sha256: 0730c02d695a06d487199eb4c85318771dfa8c4cb34a3936161296d58ad1210b
Contents?: true
Size: 797 Bytes
Versions: 21
Compression:
Stored size: 797 Bytes
Contents
class MigrateOldShippingCalculators < ActiveRecord::Migration[4.2] def up Spree::ShippingMethod.all.each do |shipping_method| old_calculator = shipping_method.calculator next if old_calculator.class < Spree::ShippingCalculator # We don't want to mess with new shipping calculators new_calculator = old_calculator.class.name.sub("::Calculator::", "::Calculator::Shipping::").constantize new_calculator.preferences.keys.each do |pref| # Preferences can't be read/set by name, you have to prefix preferred_ pref_method = "preferred_#{pref}" new_calculator.send("#{pref_method}=", old_calculator.send(pref_method)) end new_calculator.calculable = old_calculator.calculable new_calculator.save end end def down end end
Version data entries
21 entries across 21 versions & 1 rubygems