Remove non updatable check when updating a product

After the product redactor it only checked for the "description" on
product, which is actually skipped when doing an update.
This commit is contained in:
Gaetan Craig-Riou
2024-08-26 15:05:25 +10:00
parent 377f035ea8
commit 3bb2232bc1
3 changed files with 2 additions and 29 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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",