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.
This commit is contained in:
David Cook
2024-06-26 17:04:49 +10:00
parent 349862c72e
commit 0001ffa970

View File

@@ -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|