Skip to content

Commit

Permalink
Merge pull request solidusio#5800 from mamhoff/move-adjustment-promot…
Browse files Browse the repository at this point in the history
…ion-code-id-to-legacy-promotions

Move adjustment promotion code id to legacy promotions
  • Loading branch information
tvdeyen authored Jun 24, 2024
2 parents 235b6f1 + 91ba272 commit f618eb3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 10 deletions.
6 changes: 2 additions & 4 deletions admin/spec/features/orders/adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
created_at: Time.current,
updated_at: Time.current,
included: false,
source: taxrate,
promotion_code_id: nil,
source: taxrate
)
visit "/admin/orders/R123456789"

Expand Down Expand Up @@ -60,8 +59,7 @@
created_at: Time.current,
updated_at: Time.current,
included: false,
source: nil,
promotion_code_id: nil,
source: nil
)
visit "/admin/orders/R123456789"

Expand Down
2 changes: 1 addition & 1 deletion api/lib/spree/api_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ApiConfiguration < Preferences::Configuration

preference :adjustment_attributes, :array, default: [
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
:amount, :label, :promotion_code_id,
:amount, :label,
:finalized, :eligible, :created_at, :updated_at
]

Expand Down
2 changes: 0 additions & 2 deletions api/openapi/solidus-api.oas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6126,8 +6126,6 @@ components:
type: integer
label:
type: string
promotion_code_id:
type: integer
source_id:
type: integer
source_type:
Expand Down
2 changes: 0 additions & 2 deletions core/db/migrate/20160101010000_solidus_one_four.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ def up
t.datetime "updated_at", precision: 6
t.integer "order_id", null: false
t.boolean "included", default: false
t.integer "promotion_code_id"
t.integer "adjustment_reason_id"
t.boolean "finalized", default: false, null: false
t.index ["adjustable_id", "adjustable_type"], name: "index_spree_adjustments_on_adjustable_id_and_adjustable_type"
t.index ["adjustable_id"], name: "index_adjustments_on_order_id"
t.index ["eligible"], name: "index_spree_adjustments_on_eligible"
t.index ["order_id"], name: "index_spree_adjustments_on_order_id"
t.index ["promotion_code_id"], name: "index_spree_adjustments_on_promotion_code_id"
t.index ["source_id", "source_type"], name: "index_spree_adjustments_on_source_id_and_source_type"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ def calculate_eligibility

private

def legacy_promotion?
source_type == "Spree::PromotionAction"
end

def require_promotion_code?
promotion? && !source.promotion.apply_automatically && source.promotion.codes.any?
legacy_promotion? && !source.promotion.apply_automatically && source.promotion.codes.any?
end

Spree::Adjustment.prepend self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddPromotionCodeIdToSpreeAdjustments < ActiveRecord::Migration[5.0]
def up
unless column_exists?(:spree_adjustments, :promotion_code_id)
add_column :spree_adjustments, :promotion_code_id, :integer
end
unless index_exists?(:spree_adjustments, :promotion_code_id)
add_index :spree_adjustments, :promotion_code_id, name: "index_spree_adjustments_on_promotion_code_id"
end
end
end
2 changes: 2 additions & 0 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Engine < ::Rails::Engine
Spree::Config.order_contents_class = "Spree::OrderContents"
Spree::Config.promotions = SolidusLegacyPromotions::Configuration.new
Spree::Config.adjustment_promotion_source_types << "Spree::PromotionAction"

Spree::Api::Config.adjustment_attributes << :promotion_code_id
end
end
end
11 changes: 11 additions & 0 deletions legacy_promotions/spec/lib/spree/api_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Spree::Api::Config do
describe "#adjustment_attributes" do
subject { described_class.adjustment_attributes }

it { is_expected.to include(:promotion_code_id) }
end
end
1 change: 1 addition & 0 deletions legacy_promotions/spec/models/spree/adjustment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

let(:adjustment) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: order, order: order, amount: 5) }

it { is_expected.to respond_to(:promotion_code) }
context '#recalculate' do
subject { adjustment.recalculate }
let(:adjustment) do
Expand Down

0 comments on commit f618eb3

Please sign in to comment.