Class: Spree::OrderCancellations

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/order_cancellations.rb

Overview

This class represents all of the actions one can take to modify an Order after it is complete

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderCancellations

Returns a new instance of OrderCancellations.



13
14
15
# File 'app/models/spree/order_cancellations.rb', line 13

def initialize(order)
  @order = order
end

Instance Method Details

#short_ship(inventory_units, whodunnit: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/spree/order_cancellations.rb', line 17

def short_ship(inventory_units, whodunnit:nil)
  if inventory_units.map(&:order_id).uniq != [@order.id]
    raise ArgumentError, "Not all inventory units belong to this order"
  end

  unit_cancels = []

  Spree::OrderMutex.with_lock!(@order) do

    Spree::InventoryUnit.transaction do
      inventory_units.each do |iu|
        unit_cancels << short_ship_unit(iu, whodunnit: whodunnit)
      end

      update_shipped_shipments(inventory_units)
      Spree::OrderMailer.inventory_cancellation_email(@order, inventory_units.to_a).deliver_later if Spree::OrderCancellations.send_cancellation_mailer
    end

    @order.update!

    if short_ship_tax_notifier
      short_ship_tax_notifier.call(unit_cancels)
    end
  end

  unit_cancels
end