Sha256: 5ad543a091520ab6b1233552490254bdc60f3c7617695748ee5a47bc4e43c266
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
namespace :solidus_product_assembly do desc 'Link legacy inventory units to an order line item' task :upgrade => :environment do shipments = Spree::Shipment.includes(:inventory_units).where("spree_inventory_units.line_item_id IS NULL") shipments.each do |shipment| shipment.inventory_units.includes(:variant).group_by(&:variant).each do |variant, units| line_item = shipment.order.line_items.detect { |line_item| line_item.variant_id == variant.id } unless line_item begin master = shipment.order.products.detect { |p| variant.assemblies.include? p }.master supposed_line_item = shipment.order.line_items.detect { |line_item| line_item.variant_id == master.id } if supposed_line_item Spree::InventoryUnit.where(id: units.map(&:id)).update_all "line_item_id = #{supposed_line_item.id}" else puts "Couldn't find a matching line item for #{variant.name}" end rescue puts "Couldn't find a matching line item for #{variant.name}" end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
solidus_product_assembly-1.0.0 | lib/tasks/spree2_upgrade.rake |