diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb index 6286646023..bd9ef94d45 100644 --- a/app/models/product_import/entry_processor.rb +++ b/app/models/product_import/entry_processor.rb @@ -163,7 +163,7 @@ module ProductImport end product = Spree::Product.new - product.assign_attributes(entry.attributes.except('id')) + product.assign_attributes(entry.attributes.except('id', 'on_hand', 'on_demand')) product.supplier_id = entry.producer_id assign_defaults(product, entry) @@ -249,6 +249,7 @@ module ProductImport variant = product.variants.first variant.display_name = entry.display_name if entry.display_name variant.on_demand = entry.on_demand if entry.on_demand + variant.on_hand = entry.on_hand if entry.on_hand variant.import_date = @import_time variant.save end diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 11c0aab7dd..ce7eae7b19 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -54,7 +54,11 @@ module ProductImport end def mark_as_new_variant(entry, product_id) - new_variant = Spree::Variant.new(entry.attributes.except('id', 'product_id')) + new_variant = Spree::Variant.new(entry.attributes.except('id', 'product_id', 'on_hand', 'on_demand')) + new_variant.save + new_variant.on_demand = entry.attributes['on_demand'] if entry.attributes['on_demand'].present? + new_variant.on_hand = entry.attributes['on_hand'] if entry.attributes['on_hand'].present? + new_variant.product_id = product_id check_on_hand_nil(entry, new_variant) @@ -283,7 +287,11 @@ module ProductImport end def attributes_match?(attribute, existing_product, entry) - existing_product.public_send(attribute) == entry.public_send(attribute) + if existing_product.public_send(attribute).is_a?(Numeric) || entry.public_send(attribute).is_a?(Numeric) + return existing_product.public_send(attribute).to_i == entry.public_send(attribute).to_i + else + return existing_product.public_send(attribute).to_s == entry.public_send(attribute).to_s + end end def attributes_blank?(attribute, existing_product, entry)