From 91e57cb893c454fa8f6c9bd18c87cdc8cd418a40 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 15 Aug 2018 23:29:28 +0100 Subject: [PATCH] Removed Cart table, its dependency on spree orders table and removed some more dead code related to this --- .../spree/orders_controller_decorator.rb | 14 -------------- app/models/spree/order_decorator.rb | 1 - app/models/spree/user_decorator.rb | 1 - db/migrate/20180812214434_drop_carts.rb | 7 +++++++ db/schema.rb | 12 +----------- 5 files changed, 8 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20180812214434_drop_carts.rb diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 47425bcbf2c..e435b645227 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -202,20 +202,6 @@ def populate_variant_attributes end end - def populate_cart hash - if spree_current_user - unless spree_current_user.cart - spree_current_user.build_cart - cart = Cart.create(user: spree_current_user) - spree_current_user.cart = cart - spree_current_user.save - end - distributor = Enterprise.find(hash[:distributor_id]) - order_cycle = OrderCycle.find(hash[:order_cycle_id]) if hash[:order_cycle_id] - spree_current_user.cart.add_variant hash[:variants].keys.first, hash[:variants].values.first, distributor, order_cycle, current_currency - end - end - # Rails to_json encodes Float::INFINITY as Infinity, which is not valid JSON # Return it as a large integer (max 32 bit signed int) def wrap_json_infinity(n) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index c6def73d680..bc8142694bc 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -10,7 +10,6 @@ Spree::Order.class_eval do belongs_to :order_cycle belongs_to :distributor, class_name: 'Enterprise' - belongs_to :cart belongs_to :customer has_one :proxy_order has_one :subscription, through: :proxy_order diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index 8ae76a11b44..cf375e7e65d 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -9,7 +9,6 @@ has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner has_many :account_invoices has_many :billable_periods, foreign_key: :owner_id, inverse_of: :owner - has_one :cart has_many :customers has_many :credit_cards diff --git a/db/migrate/20180812214434_drop_carts.rb b/db/migrate/20180812214434_drop_carts.rb new file mode 100644 index 00000000000..f3dfb36ee77 --- /dev/null +++ b/db/migrate/20180812214434_drop_carts.rb @@ -0,0 +1,7 @@ +class DropCarts < ActiveRecord::Migration + def change + remove_foreign_key :spree_orders, column: :cart_id + remove_column :spree_orders, :cart_id + drop_table :carts + end +end diff --git a/db/schema.rb b/db/schema.rb index d3121a1f40d..13c0c125b85 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 => 20180510083800) do +ActiveRecord::Schema.define(:version => 20180812214434) do create_table "account_invoices", :force => true do |t| t.integer "user_id", :null => false @@ -53,12 +53,6 @@ add_index "billable_periods", ["account_invoice_id"], :name => "index_billable_periods_on_account_invoice_id" - create_table "carts", :force => true do |t| - t.integer "user_id" - end - - add_index "carts", ["user_id"], :name => "index_carts_on_user_id" - create_table "column_preferences", :force => true do |t| t.integer "user_id", :null => false t.string "action_name", :null => false @@ -621,7 +615,6 @@ t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" - t.integer "cart_id" t.integer "customer_id" end @@ -1203,8 +1196,6 @@ add_foreign_key "billable_periods", "enterprises", name: "bill_items_enterprise_id_fk" add_foreign_key "billable_periods", "spree_users", name: "bill_items_owner_id_fk", column: "owner_id" - add_foreign_key "carts", "spree_users", name: "carts_user_id_fk", column: "user_id" - add_foreign_key "coordinator_fees", "enterprise_fees", name: "coordinator_fees_enterprise_fee_id_fk" add_foreign_key "coordinator_fees", "order_cycles", name: "coordinator_fees_order_cycle_id_fk" @@ -1285,7 +1276,6 @@ add_foreign_key "spree_option_values_variants", "spree_option_values", name: "spree_option_values_variants_option_value_id_fk", column: "option_value_id" add_foreign_key "spree_option_values_variants", "spree_variants", name: "spree_option_values_variants_variant_id_fk", column: "variant_id" - add_foreign_key "spree_orders", "carts", name: "spree_orders_cart_id_fk" add_foreign_key "spree_orders", "customers", name: "spree_orders_customer_id_fk" add_foreign_key "spree_orders", "enterprises", name: "spree_orders_distributor_id_fk", column: "distributor_id" add_foreign_key "spree_orders", "order_cycles", name: "spree_orders_order_cycle_id_fk"