Skip to content

Commit

Permalink
Add before action to handle option type params
Browse files Browse the repository at this point in the history
As reported in solidusio#5751, the new admin UI has a bug with the option type
selectors: only one option type can be added.

We narrowed this down to an issue handling option type params in the new
admin products controller. We noticed legacy controller contains a
before action to handle the incoming option type params, but the new one
did not. Re-adding the before action solves the bug. This is required
because the form input for option types contains comma separated values
within a string:

`<input value="1,2" type="hidden">`

Co-authored-by: An Stewart <[email protected]>
  • Loading branch information
nvandoorn and stewart committed Aug 8, 2024
1 parent 3e8be72 commit 8002ab4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions admin/app/controllers/solidus_admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ProductsController < SolidusAdmin::BaseController
search_scope(:in_stock) { _1.where(id: Spree::Variant.in_stock.distinct.select(:product_id)) }
search_scope(:out_of_stock) { _1.where.not(id: Spree::Variant.in_stock.distinct.select(:product_id)) }

before_action :split_params, only: [:update]

def index
products = apply_search_to(
Spree::Product.includes(:master, :variants),
Expand Down Expand Up @@ -98,5 +100,14 @@ def activate
flash[:notice] = t('.success')
redirect_to products_path, status: :see_other
end

def split_params
if params[:product][:taxon_ids].present?
params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
end
if params[:product][:option_type_ids].present?
params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',')
end
end
end
end

0 comments on commit 8002ab4

Please sign in to comment.