diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index 54a9ac84d5..9331023aad 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -21,9 +21,7 @@ module Admin @importer = ProductImport::ProductImporter.new(File.new(@filepath), spree_current_user, params[:settings]) @original_filename = params[:file].try(:original_filename) - @non_updatable_fields = ProductImport::EntryValidator.non_updatable_product_fields.merge( - ProductImport::EntryValidator.non_updatable_variant_fields - ) + @non_updatable_fields = ProductImport::EntryValidator.non_updatable_variant_fields return if contains_errors? @importer @ams_data = ams_data diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 532f0281bf..a6a2277afd 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -6,8 +6,6 @@ module ProductImport class EntryValidator - SKIP_VALIDATE_ON_UPDATE = [:description].freeze - # rubocop:disable Metrics/ParameterLists def initialize(current_user, import_time, spreadsheet_data, editable_enterprises, inventory_permissions, reset_counts, import_settings, all_entries) @@ -22,12 +20,6 @@ module ProductImport end # rubocop:enable Metrics/ParameterLists - def self.non_updatable_product_fields - { - description: :description, - } - end - def self.non_updatable_variant_fields { unit_type: :variant_unit_scale, @@ -357,8 +349,6 @@ module ProductImport return end - products.each { |product| product_field_errors(entry, product) } - products.flat_map(&:variants).each do |existing_variant| next unless entry.match_variant?(existing_variant) && existing_variant.deleted_at.nil? @@ -410,27 +400,12 @@ module ProductImport end end - def product_field_errors(entry, existing_product) - EntryValidator.non_updatable_product_fields.each do |display_name, attribute| - next if attributes_match?(attribute, existing_product, entry) || - attributes_blank?(attribute, existing_product, entry) - next if ignore_when_updating_product?(attribute) - - mark_as_invalid(entry, attribute: display_name, - error: I18n.t('admin.product_import.model.not_updatable')) - end - end - def attributes_match?(attribute, existing_product, entry) existing_product_value = existing_product.public_send(attribute) entry_value = entry.public_send(attribute) existing_product_value == convert_to_trusted_type(entry_value, existing_product_value) end - def ignore_when_updating_product?(attribute) - SKIP_VALIDATE_ON_UPDATE.include? attribute - end - def convert_to_trusted_type(untrusted_attribute, trusted_attribute) case trusted_attribute when Integer diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 3743aaead6..60d42c6154 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -575,7 +575,7 @@ RSpec.describe ProductImport::ProductImporter do end end - describe "updating non-updatable fields on existing products" do + describe "updating non-updatable fields on existing variants" do let(:csv_data) { CSV.generate do |csv| csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",