Skip to content

Commit

Permalink
Merge pull request #12857 from chahmedejaz/task/12626-add-clone-failu…
Browse files Browse the repository at this point in the history
…re-explaination

[BUU] Fix No explanation why cloning failed
  • Loading branch information
filipefurtad0 authored Sep 27, 2024
2 parents 852dd41 + 9d5806b commit da0660c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions app/controllers/admin/products_v3_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def clone
@producer_options = producers
@category_options = categories
@tax_category_options = tax_category_options
rescue ActiveRecord::ActiveRecordError => _e
flash.now[:error] = t('.error')
rescue ActiveRecord::ActiveRecordError => e
flash.now[:error] = clone_error_message(e)
status = :unprocessable_entity
@product_index = "-1" # Create a unique enough index
end
Expand Down Expand Up @@ -213,6 +213,15 @@ def products_bulk_params
params.permit(products: ::PermittedAttributes::Product.attributes)
.to_h.with_indifferent_access
end

def clone_error_message(error)
case error
when ActiveRecord::RecordInvalid
error.record.errors.full_messages.to_sentence
else
t('.error')
end
end
end
end
# rubocop:enable Metrics/ClassLength
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ en:
price: "Price"
primary_taxon_id: "Product Category"
shipping_category_id: "Shipping Category"
variant_unit: "Variant Unit"
variant_unit: "Unit Scale"
variant_unit_name: "Variant Unit Name"
unit_value: "Unit value"
spree/variant:
Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin/products_v3/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def save_preferences

click_product_clone "Apples"

expect(page).to have_content "Unable to clone the product"
expect(page).to have_content "Unit Scale can't be blank"

within "table.products" do
# Products does not include the cloned product.
Expand Down

0 comments on commit da0660c

Please sign in to comment.