Class: SpreeBatchCapture::Worker::Ship

Inherits:
Base
  • Object
show all
Defined in:
lib/spree_batch_capture/worker/ship.rb

Class Method Summary collapse

Class Method Details

.before_run(options) ⇒ Object



41
42
43
# File 'lib/spree_batch_capture/worker/ship.rb', line 41

def self.before_run(options)
  options[:order] = Order.find_by_id options[:order_id]
end

.default_queue_nameObject



49
50
51
# File 'lib/spree_batch_capture/worker/ship.rb', line 49

def self.default_queue_name
  return "ship"
end

.run(options) ⇒ Object

expecting an order id like this: => order_obj where order_obj is set in before_run from => 1



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/spree_batch_capture/worker/ship.rb', line 7

def self.run(options)

  order = options[:order]

  result = false

  if order && order.respond_to?(:fulfill)
    result = order.fulfill
  elsif order && order.shipments.count > 0
    order.shipments.each do |shipment|
      unless shipment.shipped?
        result = shipment.ship!
        if result
          shipment.shipped_at = Time.now
          shipment.save
        end

        break unless result # if something went wrong, don't try to continue
      else
        # already shipped so we'll just say we were successful.
        result = true
      end
    end

    order.update!

  else
    # Nothing to do so we'll just proceed as if everything was ok
    result = true
  end

  return result
end

.worker_klass_nameObject



45
46
47
# File 'lib/spree_batch_capture/worker/ship.rb', line 45

def self.worker_klass_name
  return "Ship"
end