Module: Workarea::Api::Storefront::CurrentCheckout

Included in:
CartItemsController, CartsController, CheckoutsController
Defined in:
app/controllers/workarea/api/storefront/current_checkout.rb

Instance Method Summary collapse

Instance Method Details

#current_checkoutObject



19
20
21
22
23
24
25
26
# File 'app/controllers/workarea/api/storefront/current_checkout.rb', line 19

def current_checkout
  @current_checkout ||=
    if authentication?
      Workarea::Checkout.new(current_order, current_user)
    else
      Workarea::Checkout.new(current_order)
    end
end

#current_orderObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/workarea/api/storefront/current_checkout.rb', line 5

def current_order
  return @current_order if defined?(@current_order)

  options = { id: params[:cart_id].presence || params[:id] }
  options[:user_id] = current_user.id if authentication?
  order = Order.carts.find_by(options)

  if order.user_id.present? && current_user.id.to_s != order.user_id
    raise Authentication::InvalidError
  end

  @current_order = order
end