From 0bfeabbb3e705484eb475add46d8b43c34badf65 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 13 Mar 2019 14:28:36 +0000 Subject: [PATCH] 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: https://github.com/spree/spree/commit/af16cf1d7453bd30d204f92bff10352817bc922d --- ...ing_category_to_shipping_methods_and_products.rb | 13 +++++++++++++ db/schema.rb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb diff --git a/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb b/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb new file mode 100644 index 0000000000..b51c9a67b0 --- /dev/null +++ b/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 6e4426e2bb..ba233feb64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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