Sha256: 91da382fd3d32f5a85e08ef6f47dbfd378f706cec6989d0de846acd609faa68b

Contents?: true

Size: 1.07 KB

Versions: 30

Compression:

Stored size: 1.07 KB

Contents

module Spree
  # This class performs a data migration. It's usually run from
  # the `solidus:migrations:create_vat_prices` rake task.
  class PriceMigrator
    # Migrate all variant's prices.
    def self.migrate_default_vat_prices
      # We need to tag the exisiting prices as "default", so that the VatPriceGenerator knows
      # that they include the default zone's VAT.
      Spree::Config.admin_vat_country_iso = Spree::Zone.default_tax.countries.first.iso
      Spree::Variant.find_each do |variant|
        new(variant).migrate_vat_prices
      end
      # This line stops all weird code paths that generate refunds from happening.
      Spree::Zone.default_tax.update(default_tax: false)
    end

    attr_reader :variant

    def initialize(variant)
      @variant = variant
    end

    def migrate_vat_prices
      # With a default tax zone, all prices include VAT by default. Let's tell them which one!
      variant.prices.update_all(country_iso: Spree::Config.admin_vat_country_iso)
      Spree::Variant::VatPriceGenerator.new(variant).run
      variant.save
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
solidus_core-2.3.1 lib/spree/core/price_migrator.rb
solidus_core-2.2.2 lib/spree/core/price_migrator.rb
solidus_core-2.1.1 lib/spree/core/price_migrator.rb
solidus_core-2.0.3 lib/spree/core/price_migrator.rb
solidus_core-1.4.2 lib/spree/core/price_migrator.rb
solidus_core-1.3.2 lib/spree/core/price_migrator.rb
solidus_core-2.3.0 lib/spree/core/price_migrator.rb
solidus_core-2.3.0.rc3 lib/spree/core/price_migrator.rb
solidus_core-2.3.0.rc2 lib/spree/core/price_migrator.rb
solidus_core-2.3.0.rc1 lib/spree/core/price_migrator.rb
solidus_core-2.3.0.beta1 lib/spree/core/price_migrator.rb
solidus_core-2.0.2 lib/spree/core/price_migrator.rb
solidus_core-1.4.1 lib/spree/core/price_migrator.rb
solidus_core-2.2.1 lib/spree/core/price_migrator.rb
solidus_core-2.2.0 lib/spree/core/price_migrator.rb
solidus_core-2.2.0.rc1 lib/spree/core/price_migrator.rb
solidus_core-2.2.0.beta1 lib/spree/core/price_migrator.rb
solidus_core-2.1.0 lib/spree/core/price_migrator.rb
solidus_core-2.1.0.rc1 lib/spree/core/price_migrator.rb
solidus_core-2.0.1 lib/spree/core/price_migrator.rb