From 0001ffa9702d60e117e24304e4c34de39dde9cec Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 26 Jun 2024 17:04:49 +1000 Subject: [PATCH] Fix product index The param product_index wasn't present, so it was always choosing 1. The products on page are indexed 0-14, so of course it would always conflict. It would be simpler if we just used product IDs as the index, I think I did earlier but don't remember why not. Anyway, using a negative number seems to work. If there's an error, there will only be one at a time. --- app/controllers/admin/products_v3_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 27133e0891..15a30163b6 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -70,19 +70,20 @@ module Admin def clone @product = Spree::Product.find(params[:id]) - @product_index = params[:product_index].to_i + 1 status = :ok begin @cloned_product = @product.duplicate flash.now[:success] = t('.success') + @product_index = "-#{@cloned_product.id}" @producer_options = producers @category_options = categories @tax_category_options = tax_category_options rescue StandardError => _e flash.now[:error] = t('.error') status = :internal_server_error + @product_index = "-1" # Create a unique enough index end respond_with do |format|