mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Adapted product import EntryProcessor and EntryValidator to new VariantStock logic where on_hand is set at variant level (not at product level) and only after saving the variant
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user