Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create custom orders index component for solidus_legacy_promotions #5779

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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
within("div[role=search]") do
expect(page).to have_content("Promotions")
find(:xpath, "//summary[normalize-space(text())='Promotions']").click
end
check "10OFF"
expect(page).to have_content("R123456789")
expect(page).not_to have_content("R987654321")
expect(page).to be_axe_clean
end
end