Sha256: f25c075bc58855c74645f9f7f116ab7f95bcebed688f6a798e8a77267fe36b1b

Contents?: true

Size: 857 Bytes

Versions: 9

Compression:

Stored size: 857 Bytes

Contents

# This migration comes from spree (originally 20130830001159)
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 = eval(old_calculator.class.name.sub("::Calculator::", "::Calculator::Shipping::")).new
      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

9 entries across 9 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195805_migrate_old_shipping_calculators.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091746_migrate_old_shipping_calculators.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091746_migrate_old_shipping_calculators.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516181934_migrate_old_shipping_calculators.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516181934_migrate_old_shipping_calculators.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516181934_migrate_old_shipping_calculators.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516181934_migrate_old_shipping_calculators.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516181934_migrate_old_shipping_calculators.spree.rb
spree_purchase_order-3.2.0 spec/dummy/db/migrate/20180516181934_migrate_old_shipping_calculators.spree.rb