mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Populate the line item unit value, when line_item created and update old data in migration
This commit is contained in:
@@ -127,6 +127,7 @@ Spree::Order.class_eval do
|
||||
else
|
||||
current_item = Spree::LineItem.new(:quantity => quantity, max_quantity: max_quantity)
|
||||
current_item.variant = variant
|
||||
current_item.unit_value = variant.unit_value
|
||||
if currency
|
||||
current_item.currency = currency unless currency.nil?
|
||||
current_item.price = variant.price_in(currency).amount
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class PopulateLineItemUnitValue < ActiveRecord::Migration
|
||||
def up
|
||||
execute "UPDATE spree_line_items SET unit_value = spree_variants.unit_value FROM spree_variants WHERE spree_line_items.variant_id = spree_variants.id"
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user