Class: Spree::ShipmentHandler

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shipment) ⇒ ShipmentHandler


16
17
18
# File 'app/models/spree/shipment_handler.rb', line 16

def initialize(shipment)
  @shipment = shipment
end

Class Method Details

.factory(shipment) ⇒ Object


4
5
6
7
8
9
10
11
12
13
# File 'app/models/spree/shipment_handler.rb', line 4

def factory(shipment)
  # Do we have a specialized shipping-method-specific handler? e.g:
  # Given shipment.shipping_method = Spree::ShippingMethod::DigitalDownload
  # do we have Spree::ShipmentHandler::DigitalDownload?
  if sm_handler = "Spree::ShipmentHandler::#{shipment.shipping_method.name.split('::').last}".safe_constantize
    sm_handler.new(shipment)
  else
    new(shipment)
  end
end

Instance Method Details

#performObject


20
21
22
23
24
25
26
# File 'app/models/spree/shipment_handler.rb', line 20

def perform
  @shipment.inventory_units.each &:ship!
  @shipment.process_order_payments if Spree::Config[:auto_capture_on_dispatch]
  @shipment.touch :shipped_at
  update_order_shipment_state
  send_shipped_email
end