-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create custom orders index component for solidus_legacy_promotions
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
Showing
5 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
legacy_promotions/lib/components/admin/solidus_legacy_promotions/orders/index/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
3 changes: 3 additions & 0 deletions
3
legacy_promotions/lib/components/admin/solidus_legacy_promotions/orders/index/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
en: | ||
filters: | ||
promotions: Promotions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
legacy_promotions/spec/features/solidus_admin/orders/index_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |