Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dacook committed Sep 26, 2023
1 parent 50eb8f3 commit 91b251a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions app/models/product_import/entry_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 91b251a

Please sign in to comment.