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

allow multiple taxons on product creation #2840

Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 10 additions & 6 deletions backend/app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ProductsController < ResourceController
before_action :load_data, except: [:index]
update.before :update_before
helper_method :clone_object_url
before_action :split_params, only: [:create, :update]

def show
redirect_to action: :edit
Expand All @@ -19,12 +20,6 @@ def index
end

def update
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
if updating_variant_property_rules?
params[:product][:variant_property_rules_attributes].each do |_index, param_attrs|
param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',')
Expand Down Expand Up @@ -73,6 +68,15 @@ def clone

private

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

def find_resource
Spree::Product.with_deleted.friendly.find(params[:id])
end
Expand Down
20 changes: 20 additions & 0 deletions backend/spec/controllers/spree/admin/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@
end
end

# regression test for https://github.com/spree/spree/issues/2791
context "adding taxons to a product" do
let(:product) { create(:product) }
let(:first_taxon) { create(:taxon) }

it "adds a single taxon to a product" do
put :update, params: { id: product.to_param, product: { taxon_ids: first_taxon.id.to_s } }
expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!")
end

context "when there are mulitple taxons" do
let(:second_taxon) { create(:taxon) }

it "adds multiple taxons to a product" do
put :update, params: { id: product.to_param, product: { taxon_ids: "#{first_taxon.id}, #{second_taxon.id}" } }
expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!")
end
end
end
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved

describe "creating variant property rules" do
let(:first_property) { create(:property) }
let(:second_property) { create(:property) }
Expand Down