Merge pull request #9911 from viniciusueharaweb/9781-improve-shipping-category-not-found-error-message

[Product Import] Wrong error message when shipping category does not match predefined shipping categories
This commit is contained in:
Konrad
2022-11-10 22:48:25 +01:00
committed by GitHub
4 changed files with 23 additions and 2 deletions

View File

@@ -299,7 +299,7 @@ module ProductImport
entry.public_send("#{type}_category_id=", index[category])
else
mark_as_invalid(entry, attribute: "#{type}_category",
error: I18n.t('admin.product_import.model.not_found'))
error: I18n.t('admin.product_import.model.category_not_found'))
end
end

View File

@@ -68,7 +68,7 @@ module ProductImport
def invalid_attributes
invalid_attrs = {}
errors = @product_validations ? self.errors.messages.merge(@product_validations.messages) : self.errors.messages
errors = @product_validations ? @product_validations.messages.merge(self.errors.messages) : self.errors.messages
errors.each do |attr, message|
invalid_attrs[attr.to_s] = "#{attr.to_s.capitalize} #{message.first}"
end

View File

@@ -706,6 +706,7 @@ en:
conditional_blank: can't be blank if unit_type is blank
no_product: did not match any products in the database
not_found: not found in database
category_not_found: doesn't match allowed categories. See the correct categories to choose from on the product import page, or check that there's no misspelling.
not_updatable: cannot be updated on existing products via product import
blank: can't be blank
products_no_permission: you do not have permission to manage products for this enterprise

View File

@@ -272,6 +272,26 @@ describe ProductImport::ProductImporter do
end
end
describe "when shipping category is not found" do
let(:csv_data) {
CSV.generate do |csv|
csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
"variant_unit_name", "on_demand", "shipping_category"]
csv << ["Shipping Test", enterprise.name, "Vegetables", "5", "3.20", "500", "g", "", nil,
"not_found"]
end
}
let(:importer) { import_data csv_data }
it "raises an error" do
importer.validate_entries
entries = JSON.parse(importer.entries_json)
error = entries['2']['errors']['shipping_category']
expect(error).to include "Shipping_category doesn't match allowed categories"
end
end
describe "when enterprises are not valid" do
let(:csv_data) {
CSV.generate do |csv|