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.



31
32
33
34
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 31

def clear_current_order
  session.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)


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

def completed_order
  if cookies.signed[:completed_order].present?
    @completed_order ||= Order.find(cookies.signed[:completed_order])
  end
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.



40
41
42
43
44
45
46
47
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 40

def completed_order=(order)
  cookies.signed[:completed_order] = {
    value: order.id,
    expires: Workarea.config.completed_order_timeout.from_now
  }

  @completed_order = order
end

#current_checkoutCheckout

Get the current checkout for the session.

Returns:



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

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

def current_order
  @current_order ||= Order.find_current(
    id: session[:order_id],
    user_id: cookies.signed[:user_id]
  )
end

#current_order=(order) ⇒ Object

Sets the current order on the session.



24
25
26
27
# File 'app/controllers/workarea/storefront/current_checkout.rb', line 24

def current_order=(order)
  @current_order = order
  session[:order_id] = order.try(:id)
end

#current_shippingShipping

Get the current shipping for the session.

Returns:

  • (Shipping)


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

def current_shipping
  current_checkout.shipping
end

#current_shippingsArray<Shipping>

Get all shippings for the session.

Returns:

  • (Array<Shipping>)


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

def current_shippings
  current_checkout.shippings
end