Class: Spree::PriceMigrator
- Inherits:
-
Object
- Object
- Spree::PriceMigrator
- Defined in:
- lib/spree/core/price_migrator.rb
Overview
This class performs a data migration. It’s usually run from the ‘solidus:migrations:create_vat_prices` rake task.
Instance Attribute Summary collapse
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Class Method Summary collapse
-
.migrate_default_vat_prices ⇒ Object
Migrate all variant’s prices.
Instance Method Summary collapse
-
#initialize(variant) ⇒ PriceMigrator
constructor
A new instance of PriceMigrator.
- #migrate_vat_prices ⇒ Object
Constructor Details
#initialize(variant) ⇒ PriceMigrator
Returns a new instance of PriceMigrator.
19 20 21 |
# File 'lib/spree/core/price_migrator.rb', line 19 def initialize(variant) @variant = variant end |
Instance Attribute Details
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
17 18 19 |
# File 'lib/spree/core/price_migrator.rb', line 17 def variant @variant end |
Class Method Details
.migrate_default_vat_prices ⇒ Object
Migrate all variant’s prices.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/spree/core/price_migrator.rb', line 6 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 |
Instance Method Details
#migrate_vat_prices ⇒ Object
23 24 25 26 27 28 |
# File 'lib/spree/core/price_migrator.rb', line 23 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 |