diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 1b152773736..3a4af9bcc7a 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -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 @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index f1041c92bbb..44ce0f6c865 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/spec/system/admin/products_v3/actions_spec.rb b/spec/system/admin/products_v3/actions_spec.rb index 74ce58cbe0d..368f6d85950 100644 --- a/spec/system/admin/products_v3/actions_spec.rb +++ b/spec/system/admin/products_v3/actions_spec.rb @@ -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.