These steps were sufficient to upgrade Cult Cosmetics to Spree 2.0.4 from 1.3.3. Here are some details on our environment.
- We only have single-variant products
- We are not making use of stock locations (single warehouse)
- Frontend entirely overridden w/ custom bootstrap layout
- Braintree gateway
- Rails 3.2.14
- Upgraded from Ruby 1.9.3-p448 to 2.0.0-p247 in the process (no issues)
Pull requests are encouraged to update this with steps that I missed!
- MailMethods have been refactored. This breaks your existing mail config.
- Shipping Calculators have been refactored. This breaks your existing shipping calculators.
- Shipping Category is now required for all products and shipping methods. Checkout will just stop at the delivery step with no explanation if you don't have this configured.
- Lots has been changed in the frontend code, which has been refactored out into the
spree_frontend
gem. If you're overriding the views, there is plenty more to do that I'll document later, although I probably only scratched the surface.
- Update Spree and extensions in your Gemfile
gem 'spree', '~> 2.0.4'
# Should work for most extensions
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-0-stable'
bundle install
(or justbundle
if you're super-cool)bundle exec rake railties:install:migrations && bundle exec rake db:migrate
- Edit
app/assets/javascripts/admin/all.js
-//= require admin/spree_core
-//= require admin/spree_promo
+//= require admin/spree_backend
- Edit
app/assets/javascripts/store/all.js
-//= require admin/spree_core
-//= require admin/spree_promo
+//= require admin/spree_backend
- Edit
app/assets/stylesheets/admin/all.css
- *= require admin/spree_core
- *= require admin/spree_promo
+ *= require admin/spree_backend
- Edit
app/assets/stylesheets/admin/all.css
- *= require admin/spree_core
- *= require admin/spree_promo
+ *= require admin/spree_frontend
- Shipments need a stock location and your existing shipments won't have one.
rails g migration AddStockLocationToShipments
Should contain: (obviously this is more complicated if you're actually planning on using multiple Stock Locations)
location = Spree::StockLocation.find_by_name('default')
Spree::Shipment.update_all(stock_location_id: location.id)
- You need a Shipping Category if you don't already have one (they weren't required before 2.0).
Every Product && Shipping Method needs a shipping category assigned to it as well.
rails g migration CreateDefaultShippingCategory
Should contain: ```ruby default_category = Spree::ShippingCategory.first default_category ||= Spree::ShippingCategory.create!(:name => "Default")
Spree::ShippingMethod.all.each do |method|
method.shipping_categories << default_category if method.shipping_categories.blank?
end
Spree::Product.where(shipping_category_id: nil).update_all(shipping_category_id: default_category.id)
```
-
New Products also need a shipping category but this isn't obvious in the Admin. I chose to set it before a new Product is created in
app/controllers/admin/products_controller_decorator.rb
Spree::Admin::ProductsController.class_eval do new_action.before :set_shipping_category private def set_shipping_category @product.shipping_category = Spree::ShippingCategory.first # or whichever category your heart desires end end
-
This one is a doozy. Spree 2.0 uses new Shipping Calculators that are separate from the old Spree::Calculator classes. This insane migration will recreate your calculators using the new models and copy over your old preferences.
rails g migration MigrateOldShippingCalculators
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("Spree::Calculator::Shipping::#{old_calculator.class.name.demodulize}").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.save shipping_method.calculator = new_calculator end
See this comment if you have custom shipping calculators: https://gist.github.com/swrobel/6343549#comment-918763
-
Mail Methods have also been refactored, breaking your existing mail config. I prefer to just set up the ActionMailer config in my environment config files (production.rb, development.rb, etc) and use the new setting to prevent spree from overriding ActionMailer like so:
# config/initializers/spree.rb Spree.config do |config| config.override_actionmailer_config = false config.mails_from = 'Your Company <[email protected]>' # Set domain for emails ActionMailer::Base.default_url_options[:host] = config.site_url end
Otherwise, just make sure to go into the Admin and set up your Mail config again for 2.0
-
Replace any instances of
t(:translation)
in your code withSpree.t(:translation)
-
If you were using the
Spree::Config.show_zero_stock_products = false
option, use my extension to bring it back:
gem 'spree_zero_stock_products'
```ruby
# config/initializers/spree.rb
Spree.config do |config|
config.show_zero_stock_products = false # Default is true
end
```
- If you were using the
Spree::Config.allow_backorders = false
option,rails g migration SetBackorderableToFalse
:
Spree::StockItem.update_all(backorderable: false)
Spree::StockLocation.update_all(backorderable_default: false)
Thanks @swrobel. We are using your HOWTO to migrate a Spree store from 1.3 to 2.0 and it has been really useful.
Just a note: if you have custom calculators in your Spree store you will have to duplicate them into both
app/model/spree/calculator/
andapp/model/spree/calculator/shipping
directories because, when the migration runs, it tries to initialize both of them. It's currently working with spree core calculators since they have duplicated all shipping calculators as you can see here:https://github.com/spree/spree/tree/2-0-stable/core/app/models/spree/calculator
and here:
https://github.com/spree/spree/tree/2-0-stable/core/app/models/spree/calculator/shipping
If these custom calculators are used as shipping calculator only I think they could be removed form
app/models/spree/calculator/
after the migration is done.