11987: add flash messages for product clone

This commit is contained in:
Ahmed Ejaz
2024-06-17 23:17:32 +05:00
parent 30528cab0f
commit 05fe7cd4b9
3 changed files with 26 additions and 12 deletions

View File

@@ -72,7 +72,14 @@ module Admin
@product = Spree::Product.find(params[:id])
@cloned_product = @product.duplicate
@product_index = params[:product_index].to_i + 1
status = @cloned_product.save ? :ok : :internal_server_error
status = :ok
if @cloned_product.save
flash.now[:success] = t('.success')
else
flash.now[:error] = t('.error')
status = :internal_server_error
end
@producer_options = producers
@category_options = categories

View File

@@ -1,11 +1,15 @@
- product_body = nil
- form_with url: bulk_update_admin_products_path, method: :post, id: "products-form",
builder: BulkFormBuilder,
html: { data: { 'turbo-frame': "_self",
controller: "bulk-form",
'bulk-form-disable-selector-value': "#sort,#filters",
'bulk-form-error-value': defined?(@error_counts),
} } do |form|
- product_body = render partial: 'product_variant_row', locals: { form:, product: @cloned_product, product_index: @product_index, producer_options: @producer_options, category_options: @category_options, tax_category_options: @tax_category_options, should_slide_in: true }, formats: :html
= turbo_stream.before dom_id(@product) do
= product_body
- unless flash[:error]
- product_body = nil
- form_with url: bulk_update_admin_products_path, method: :post, id: "products-form",
builder: BulkFormBuilder,
html: { data: { 'turbo-frame': "_self",
controller: "bulk-form",
'bulk-form-disable-selector-value': "#sort,#filters",
'bulk-form-error-value': defined?(@error_counts),
} } do |form|
- product_body = render partial: 'product_variant_row', locals: { form:, product: @cloned_product, product_index: @product_index, producer_options: @producer_options, category_options: @category_options, tax_category_options: @tax_category_options, should_slide_in: true }, formats: :html
= turbo_stream.before dom_id(@product) do
= product_body
= turbo_stream.append "flashes" do
= render(partial: 'admin/shared/flashes', locals: { flashes: flash })

View File

@@ -912,6 +912,9 @@ en:
tax_category_field_name: "Tax Category"
product_row:
producer_field_name: "Producer"
clone:
success: Successfully cloned the product
error: Unable to clone the product
product_import:
title: Product Import
file_not_found: File not found or could not be opened