From 91b251acd4a56e6cb0c7cebd455651baba49366e Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 26 Sep 2023 10:56:44 +1000 Subject: [PATCH] Refactor --- app/models/product_import/entry_validator.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 9166ae10ac9..1e4e6be649f 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -67,16 +67,14 @@ def enterprise_field end def mark_as_new_variant(entry, product_id) + variant_attributes = entry.assignable_attributes.except( + 'id', 'product_id', 'on_hand', 'on_demand', 'variant_unit', 'variant_unit_name', + 'variant_unit_scale', 'primary_taxon_id' + ) # Variant needs a product. Product needs to be assigned first in order for # delegate to work. name= will fail otherwise. - new_variant = Spree::Variant.new( - { product_id: } - .merge( - entry.assignable_attributes.except('id', 'product_id', 'on_hand', 'on_demand', - 'variant_unit', 'variant_unit_name', - 'variant_unit_scale', 'primary_taxon_id') - ) - ) + new_variant = Spree::Variant.new(product_id:, **variant_attributes) + new_variant.save if new_variant.persisted? if entry.attributes['on_demand'].present?