Skip to content

Commit

Permalink
Create custom orders index component for solidus_legacy_promotions
Browse files Browse the repository at this point in the history
The new admin allows orders to be filtered by promotion name. However,
with the legacy promotion system extracted into an extension, we can't
rely on `Spree::Promotion` to exist in `solidus_admin`. In order to get
around this issue, we create a new index component for the admin orders
page that includes the filter, and register it in an initializer.

This also adds a spec for filtering by promotion name.
  • Loading branch information
mamhoff committed Jun 6, 2024
1 parent 742b1cf commit d29d00b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
9 changes: 1 addition & 8 deletions admin/app/components/solidus_admin/orders/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ def filters
option
]
end
},
{
label: t('.filters.promotions'),
combinator: 'or',
attribute: "promotions_id",
predicate: "in",
options: Spree::Promotion.all.pluck(:name, :id),
},
}
]
end

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

class SolidusLegacyPromotions::Orders::Index::Component < SolidusAdmin::Orders::Index::Component
def filters
super + [
{
label: t('.filters.promotions'),
combinator: 'or',
attribute: "promotions_id",
predicate: "in",
options: Spree::Promotion.all.pluck(:name, :id),
}
]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
en:
filters:
promotions: Promotions
8 changes: 8 additions & 0 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class Engine < ::Rails::Engine
end
end

initializer "solidus_legacy_promotions.add_admin_order_index_component" do
if SolidusSupport.admin_available?
config.to_prepare do
SolidusAdmin::Config.components["orders/index"] = SolidusLegacyPromotions::Orders::Index::Component
end
end
end

initializer "solidus_legacy_promotions.add_solidus_admin_menu_items" do
if SolidusSupport.admin_available?
SolidusAdmin::Config.configure do |config|
Expand Down
21 changes: 21 additions & 0 deletions legacy_promotions/spec/features/solidus_admin/orders/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe "Orders", type: :feature, solidus_admin: true do
let(:promotion) { create(:promotion, name: "10OFF") }
let!(:order_with_promotion) { create(:completed_order_with_promotion, number: "R123456789", promotion: promotion) }
let!(:order_without_promotion) { create(:completed_order_with_totals, number: "R987654321") }

before { sign_in create(:admin_user, email: '[email protected]') }

it "lists products", :js do
visit "/admin/orders"
find('button[aria-label=Filter]').click
find(:xpath, "//summary[normalize-space(text())='Promotions']").click
check "10OFF"
expect(page).to have_content("R123456789")
expect(page).not_to have_content("R987654321")
expect(page).to be_axe_clean
end
end

0 comments on commit d29d00b

Please sign in to comment.