Skip to content

Commit

Permalink
Move promotion-related associations to legacy_promotions
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Jun 19, 2024
1 parent 81c8460 commit c860e8d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
2 changes: 0 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def states
foreign_key: :order_id,
dependent: :destroy,
inverse_of: :order
has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy
has_many :promotions, through: :order_promotions

# Payments
has_many :payments, dependent: :destroy, inverse_of: :order
Expand Down
14 changes: 0 additions & 14 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1806,20 +1806,6 @@ def validate(line_item)
end
end

describe "order deletion" do
let(:order) { create(:order) }
let(:promotion) { create(:promotion) }

subject { order.destroy }
before do
order.promotions << promotion
end

it "deletes join table entries when deleting an order" do
expect { subject }.to change { Spree::OrderPromotion.count }.from(1).to(0)
end
end

describe ".find_by_param" do
let(:order) { create(:order) }
let(:param) { order.number }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
module SpreeOrderDecorator
def self.prepended(base)
base.has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy
base.has_many :promotions, through: :order_promotions
end

def apply_shipping_promotions(_event = nil)
Spree::Config.promotions.shipping_promotion_handler_class.new(self).activate
recalculate
end

Spree::Order.prepend(self)
end
end

0 comments on commit c860e8d

Please sign in to comment.