Add migration to create default shipping category and set it in shipping methods and products that do not have a shipping category yet

This is a modified version of this spree migration: af16cf1d74
This commit is contained in:
luisramos0
2019-03-13 14:28:36 +00:00
parent f914a6d869
commit 0bfeabbb3e
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
class AddShippingCategoryToShippingMethodsAndProducts < ActiveRecord::Migration
def up
# This is different from the equivalent Spree migration
# Here we are creating the default shipping category even if there are already shipping categories
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)
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20190221214542) do
ActiveRecord::Schema.define(:version => 20190313142540) do
create_table "account_invoices", :force => true do |t|
t.integer "user_id", :null => false