-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[solidus_admin] Add product taxon management #6610
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
Merged
tvdeyen
merged 19 commits into
solidusio:main
from
benjaminwil:admin-product-organization--categories
Sep 22, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5c07f83
Delegate methods
chaimann 830bb45
Unskip feature test
benjaminwil 9489151
Add correct label translation
chaimann 0ba9595
Create product_taxons resource
chaimann 27a0311
Create component for new product category
chaimann a707389
Allow alternative item labels in solidus_select
chaimann 90132b6
Change selected items text in taxons select
chaimann d744559
Update product organization panel
chaimann 4f756d4
Display toasts from turbo frame response
chaimann 9ad909c
Extract frame with stream actions into component
chaimann 4c72c0d
Move capybara feature helpers
chaimann 15f8455
Add feature tests
chaimann 7b9b972
Add request tests
chaimann 13c6dd4
Fix rubocop offence
chaimann cb97676
Allow empty parent for new category
chaimann 9571cb4
Exclude feature_helpers from coverage report
chaimann 0b33e52
Disambiguate `<dialog>` in product feature tests
benjaminwil 8cf131c
Fix bug where taxon_ids would not be updated
benjaminwil d9c7d1a
Provide latest context re: FIXME in feature test
benjaminwil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
admin/app/components/solidus_admin/products/show/categories/new/component.html.erb
This file contains hidden or 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,17 @@ | ||
| <%= turbo_frame_tag :new_product_category, target: :product_organization_frame do %> | ||
| <%= render component("ui/modal").new(title: t(".title")) do |modal| %> | ||
| <%= form_for @taxon, url: solidus_admin.product_taxons_path(@product), method: :post, html: { id: dom_id(@taxon) } do |f| %> | ||
| <div class="flex flex-col gap-6 pb-4"> | ||
| <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> | ||
| <%= render component("ui/forms/field").select(f, :parent_id, parent_taxon_options, include_blank: t(".none")) %> | ||
| <%= render component("ui/forms/field").text_area(f, :description) %> | ||
| </div> | ||
| <% end %> | ||
| <% modal.with_actions do %> | ||
| <form method="dialog"> | ||
| <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> | ||
| </form> | ||
| <%= render component("ui/button").new(type: :submit, text: t('.submit'), form: dom_id(@taxon)) %> | ||
| <% end %> | ||
| <% end %> | ||
| <% end %> |
17 changes: 17 additions & 0 deletions
17
admin/app/components/solidus_admin/products/show/categories/new/component.rb
This file contains hidden or 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,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class SolidusAdmin::Products::Show::Categories::New::Component < SolidusAdmin::BaseComponent | ||
| def initialize(product:, taxon: nil) | ||
| @product = product | ||
| @taxon = taxon || product.taxons.build | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def parent_taxon_options | ||
| @parent_taxon_options ||= Spree::Taxon.order(:lft).pluck(:name, :id, :depth).map do | ||
| name, id, depth = _1 | ||
| ["#{" " * depth} → #{name}", id, {data: {item_label: name}}] | ||
| end | ||
| end | ||
| end | ||
5 changes: 5 additions & 0 deletions
5
admin/app/components/solidus_admin/products/show/categories/new/component.yml
This file contains hidden or 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,5 @@ | ||
| en: | ||
| cancel: "Cancel" | ||
| none: "None" | ||
| submit: "Add Category" | ||
| title: "New Category" |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
admin/app/components/solidus_admin/turbo/target_frame/component.html.erb
This file contains hidden or 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,5 @@ | ||
| <%= turbo_frame_tag @id do %> | ||
| <%= content %> | ||
| <%= turbo_stream.update(@source, nil) if @source %> | ||
| <%= turbo_stream.replace :flash_toasts, component("layout/flashes/toasts").new(toasts:) %> | ||
| <% end %> |
8 changes: 8 additions & 0 deletions
8
admin/app/components/solidus_admin/turbo/target_frame/component.rb
This file contains hidden or 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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class SolidusAdmin::Turbo::TargetFrame::Component < SolidusAdmin::BaseComponent | ||
| def initialize(id, source: nil) | ||
| @id = id | ||
| @source = source | ||
| end | ||
| end |
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
admin/app/controllers/solidus_admin/product_taxons_controller.rb
This file contains hidden or 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,58 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SolidusAdmin | ||
| class ProductTaxonsController < SolidusAdmin::BaseController | ||
| before_action :load_product, only: [:new, :create] | ||
|
|
||
| def new | ||
| render component("products/show/categories/new").new(product: @product) | ||
| end | ||
|
|
||
| def create | ||
| init_taxon | ||
| root_taxon! if @taxon.root? | ||
| @product.taxons << @taxon | ||
|
|
||
| respond_to do |format| | ||
| format.html { redirect_to @product, status: :see_other, notice: t(".success") } | ||
| end | ||
| rescue ActiveRecord::RecordInvalid | ||
| component = component("products/show/categories/new").new(product: @product, taxon: @taxon) | ||
| respond_to do |format| | ||
| format.html { render component, status: :unprocessable_entity } | ||
| format.turbo_stream do | ||
| render turbo_stream: turbo_stream.replace(:new_product_category, component), | ||
| status: :unprocessable_entity | ||
| end | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def load_product | ||
| @product = Spree::Product.friendly.find(params[:product_id]) | ||
| end | ||
|
|
||
| def init_taxon | ||
| @taxon = Spree::Taxon.new(category_params) | ||
| @taxon.taxonomy_id = @taxon.parent&.taxonomy_id | ||
| end | ||
|
|
||
| # Parent-less taxons must be associated with a taxonomy of the same name; it's guaranteed that in order to create a | ||
| # new parent-less taxon we need to create a new taxonomy. | ||
| def root_taxon! | ||
| # if Taxonomy.create! fails on the next step, we need validation errors on taxon object | ||
| # to display them on the form | ||
| @taxon.validate | ||
| Spree::Taxonomy.create!(name: @taxon.name, root: @taxon) | ||
| end | ||
|
|
||
| def authorization_subject | ||
| Spree::Classification | ||
| end | ||
|
|
||
| def category_params | ||
| params.require(:taxon).permit(:name, :parent_id, :description) | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
This file contains hidden or 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,6 @@ | ||
| en: | ||
| solidus_admin: | ||
| product_taxons: | ||
| title: "Categories" | ||
| create: | ||
| success: "Product category was successfully added." |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.