11987: refactored code

This commit is contained in:
Ahmed Ejaz
2024-06-18 00:44:10 +05:00
parent 05fe7cd4b9
commit d2737bd8b0
2 changed files with 18 additions and 16 deletions

View File

@@ -70,21 +70,21 @@ module Admin
def clone
@product = Spree::Product.find(params[:id])
@cloned_product = @product.duplicate
@product_index = params[:product_index].to_i + 1
status = :ok
if @cloned_product.save
begin
@cloned_product = @product.duplicate
flash.now[:success] = t('.success')
else
@producer_options = producers
@category_options = categories
@tax_category_options = tax_category_options
rescue StandardError => _e
flash.now[:error] = t('.error')
status = :internal_server_error
end
@producer_options = producers
@category_options = categories
@tax_category_options = tax_category_options
respond_with do |format|
format.turbo_stream { render :clone, status: }
end

View File

@@ -1,13 +1,15 @@
- 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
- form_with 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