Sha256: 1e70d0ce1adaa93a0d409f3aaba894ec5f6546112c1a0768b70438401e92c2f3
Contents?: true
Size: 886 Bytes
Versions: 21
Compression:
Stored size: 886 Bytes
Contents
class DeleteInventoryUnitsWithoutShipment < ActiveRecord::Migration[4.2] # Prevent everything from running in one giant transaction in postrgres. disable_ddl_transaction! def up order_ids = Spree::InventoryUnit.where(shipment_id: nil).pluck(:order_id).uniq.compact Spree::Order.where(id: order_ids).find_each do |order| # Order may not be completed but have shipped # shipments if it has a pending unreturned exchange next if order.completed? next if order.canceled? next if order.shipments.any? { |s| s.shipped? || s.ready? || s.canceled? } say "Removing inventory units without shipment for order ##{order.number}" order.transaction do order.inventory_units.destroy_all order.shipments.destroy_all order.restart_checkout_flow end end end def down # intentionally left blank end end
Version data entries
21 entries across 21 versions & 1 rubygems