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.



34
35
36
37
38
39
40
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 34

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)


56
57
58
59
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 56

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.



46
47
48
49
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 46

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

#current_checkoutCheckout

Get the current checkout for the session.

Returns:



65
66
67
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 65

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
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 27

def current_order=(order)
  @current_order = order
  cookies.permanent.signed[:order_id] = order&.id
end

#current_shippingShipping

Get the current shipping for the session.

Returns:

  • (Shipping)


73
74
75
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 73

def current_shipping
  current_checkout.shipping
end

#current_shippingsArray<Shipping>

Get all shippings for the session.

Returns:

  • (Array<Shipping>)


81
82
83
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 81

def current_shippings
  current_checkout.shippings
end

#logoutObject



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

def logout
  super
  clear_current_order
end