Module: Workarea::Storefront::CurrentCheckout

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/workarea/storefront/current_checkout.rb

Instance Method Summary collapse

Instance Method Details

#clear_current_orderObject

Removes the current order from the session.



37
38
39
40
41
42
43
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 37

def clear_current_order
  # TODO session[:order_id] is deprecated in v3.5, remove in v3.6
  session.delete(:order_id)

  cookies.delete(:order_id)
  @current_order = nil
end

#completed_orderOrder

Get the last completed order based on the cookie. Used to show the order confirmation page.

Returns:

  • (Order)


59
60
61
62
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 59

def completed_order
  return @completed_order if defined?(@completed_order)
  @completed_order = Order.find(session[:completed_order_id]) rescue nil
end

#completed_order=(order) ⇒ Object

Sets a temporary cookie of the order ID to represent an order that was just completed in checkout. Used to show the order confirmation page.



49
50
51
52
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 49

def completed_order=(order)
  session[:completed_order_id] = order&.id
  @completed_order = order
end

#current_checkoutCheckout

Get the current checkout for the session.

Returns:



68
69
70
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 68

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

#current_orderOrder

The current order for the current session.

Returns:

  • (Order)


15
16
17
18
19
20
21
22
23
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 15

def current_order
  @current_order ||= Order.find_current(
    # TODO session[:order_id] is deprecated in v3.5, remove in v3.6
    # TODO cookies.signed[:user_id] is deprecated in v3.5, remove in v3.6

    id: cookies.signed[:order_id].presence || session[:order_id],
    user_id: session[:user_id].presence || cookies.signed[:user_id]
  )
end

#current_order=(order) ⇒ Object

Sets the current order on the session.



27
28
29
30
31
32
33
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 27

def current_order=(order)
  @current_order = order

  if order.blank? || order.persisted?
    cookies.permanent.signed[:order_id] = order&.id
  end
end

#current_shippingShipping

Get the current shipping for the session.

Returns:

  • (Shipping)


76
77
78
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 76

def current_shipping
  current_checkout.shipping
end

#current_shippingsArray<Shipping>

Get all shippings for the session.

Returns:

  • (Array<Shipping>)


84
85
86
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 84

def current_shippings
  current_checkout.shippings
end

#logoutObject



88
89
90
91
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 88

def logout
  super
  clear_current_order
end