diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb index 8130c0ba8a9..396bee150ad 100644 --- a/core/app/models/spree/line_item.rb +++ b/core/app/models/spree/line_item.rb @@ -19,9 +19,6 @@ class LineItem < Spree::Base has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :destroy has_many :inventory_units, inverse_of: :line_item - has_many :line_item_actions, dependent: :destroy - has_many :actions, through: :line_item_actions - before_validation :normalize_quantity before_validation :set_required_attributes diff --git a/core/db/migrate/20160101010000_solidus_one_four.rb b/core/db/migrate/20160101010000_solidus_one_four.rb index 317e9c99d5c..fe5e54facc8 100644 --- a/core/db/migrate/20160101010000_solidus_one_four.rb +++ b/core/db/migrate/20160101010000_solidus_one_four.rb @@ -197,16 +197,6 @@ def up t.index ["variant_id"], name: "index_inventory_units_on_variant_id" end - create_table "spree_line_item_actions", force: :cascade do |t| - t.integer "line_item_id", null: false - t.integer "action_id", null: false - t.integer "quantity", default: 0 - t.datetime "created_at", precision: 6 - t.datetime "updated_at", precision: 6 - t.index ["action_id"], name: "index_spree_line_item_actions_on_action_id" - t.index ["line_item_id"], name: "index_spree_line_item_actions_on_line_item_id" - end - create_table "spree_line_items", force: :cascade do |t| t.integer "variant_id" t.integer "order_id" diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb b/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb index f7d76204e41..58147729943 100644 --- a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb +++ b/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb @@ -2,6 +2,11 @@ module SolidusLegacyPromotions module SpreeLineItemDecorator + def self.prepended(base) + base.has_many :line_item_actions, dependent: :destroy + base.has_many :actions, through: :line_item_actions + end + def total_before_tax amount + adjustments.select { |value| !value.tax? && value.eligible? }.sum(&:amount) end diff --git a/core/app/models/spree/line_item_action.rb b/legacy_promotions/app/models/line_item_action.rb similarity index 100% rename from core/app/models/spree/line_item_action.rb rename to legacy_promotions/app/models/line_item_action.rb diff --git a/legacy_promotions/db/migrate/20160101010001_solidus_one_four_promotions.rb b/legacy_promotions/db/migrate/20160101010001_solidus_one_four_promotions.rb index 645019b44b3..733f9e01ccf 100644 --- a/legacy_promotions/db/migrate/20160101010001_solidus_one_four_promotions.rb +++ b/legacy_promotions/db/migrate/20160101010001_solidus_one_four_promotions.rb @@ -122,5 +122,17 @@ def up t.index ["starts_at"], name: "index_spree_promotions_on_starts_at" end end + + unless table_exists?(:spree_line_item_actions) + create_table "spree_line_item_actions", force: :cascade do |t| + t.integer "line_item_id", null: false + t.integer "action_id", null: false + t.integer "quantity", default: 0 + t.datetime "created_at", precision: 6 + t.datetime "updated_at", precision: 6 + t.index ["action_id"], name: "index_spree_line_item_actions_on_action_id" + t.index ["line_item_id"], name: "index_spree_line_item_actions_on_line_item_id" + end + end end end