Class: Workarea::Login

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, current_order) ⇒ Login

Returns a new instance of Login.



5
6
7
8
# File 'app/services/workarea/login.rb', line 5

def initialize(user, current_order)
  @user = user
  @current_order = current_order
end

Instance Attribute Details

#current_orderObject (readonly)

Returns the value of attribute current_order.



3
4
5
# File 'app/services/workarea/login.rb', line 3

def current_order
  @current_order
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'app/services/workarea/login.rb', line 3

def user
  @user
end

Instance Method Details

#performObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/workarea/login.rb', line 18

def perform
  user.

  if previous_order &&
       !previous_order.checking_out? &&
       previous_order.items.present? &&
       previous_order != current_order

    OrderMerge.new(previous_order).merge(current_order)
    @current_order = previous_order
  elsif current_order.persisted?
    if current_order.started_checkout?
      Checkout.new(current_order).continue_as(user)
    else
      current_order.update_attributes!(user_id: user.id)
    end
  end

  self
end

#previous_orderObject



10
11
12
13
14
15
16
# File 'app/services/workarea/login.rb', line 10

def previous_order
  @previous_order ||= Order
                        .carts
                        .where(user_id: user.id)
                        .order_by(:created_at.desc)
                        .first
end