mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Apply import defaults to variants of new products
Spree 2 doesn't have `Product#on_hand=` any more. We actually can't save stock levels without saving the product first which creates a stock item. This hacky solution overwrites the attribute in the entry so that it gets copied to the variant later on. I think a better solution needs some refactoring as proposed in: https://github.com/openfoodfoundation/openfoodnetwork/issues/2783#issuecomment-459601530
This commit is contained in:
@@ -212,12 +212,20 @@ module ProductImport
|
||||
case setting['mode']
|
||||
when 'overwrite_all'
|
||||
object.assign_attributes(attribute => setting['value'])
|
||||
# In case of new products, some attributes are saved on the variant.
|
||||
# We write them to the entry here to be copied to the variant later.
|
||||
if entry.respond_to? "#{attribute}="
|
||||
entry.public_send("#{attribute}=", setting['value'])
|
||||
end
|
||||
when 'overwrite_empty'
|
||||
if object.public_send(attribute).blank? ||
|
||||
((attribute == 'on_hand' || attribute == 'count_on_hand') &&
|
||||
entry.on_hand_nil)
|
||||
|
||||
object.assign_attributes(attribute => setting['value'])
|
||||
if entry.respond_to? "#{attribute}="
|
||||
entry.public_send("#{attribute}=", setting['value'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user