Module: CartFinder
- Extended by:
- ActiveSupport::Concern
- Included in:
- ConsoleSalesController, SalesController, Store::StoreController
- Defined in:
- app/concerns/cart_finder.rb
Overview
This is for use with session-based carts. Token-based carts (V3 widget) can’t use these methods
Instance Method Summary collapse
- #cart_name(klass = Cart) ⇒ Object
- #create_new_cart(klass = Cart) ⇒ Object
- #current_box_office_cart ⇒ Object
- #current_cart(klass = Cart) ⇒ Object
-
#current_cart=(cart) ⇒ Object
Use with care.
- #current_sales_console_cart ⇒ Object
- #session_cart(klass = Cart) ⇒ Object
- #session_key(klass) ⇒ Object
Instance Method Details
#cart_name(klass = Cart) ⇒ Object
43 44 45 |
# File 'app/concerns/cart_finder.rb', line 43 def cart_name(klass = Cart) klass.name.gsub("::","").underscore end |
#create_new_cart(klass = Cart) ⇒ Object
29 30 31 32 33 |
# File 'app/concerns/cart_finder.rb', line 29 def create_new_cart(klass = Cart) @current_cart = klass.create session[session_key(klass)] = @current_cart ? @current_cart.id : nil @current_cart end |
#current_box_office_cart ⇒ Object
17 18 19 |
# File 'app/concerns/cart_finder.rb', line 17 def current_box_office_cart current_cart(BoxOffice::Cart) end |
#current_cart(klass = Cart) ⇒ Object
21 22 23 |
# File 'app/concerns/cart_finder.rb', line 21 def current_cart(klass = Cart) (!session_cart(klass) || session_cart(klass).approved?) ? create_new_cart(klass) : session_cart(klass) end |
#current_cart=(cart) ⇒ Object
Use with care. Only assign updated carts (in the case of discounts) TODO: Enforce that this isn’t used to actually switch to another cart object
39 40 41 |
# File 'app/concerns/cart_finder.rb', line 39 def current_cart=(cart) @current_cart = cart end |
#current_sales_console_cart ⇒ Object
13 14 15 |
# File 'app/concerns/cart_finder.rb', line 13 def current_sales_console_cart current_cart(ConsoleSale::Cart) end |
#session_cart(klass = Cart) ⇒ Object
25 26 27 |
# File 'app/concerns/cart_finder.rb', line 25 def session_cart(klass = Cart) @current_cart ||= Cart.find_by_id(session[session_key(klass)]) end |
#session_key(klass) ⇒ Object
47 48 49 |
# File 'app/concerns/cart_finder.rb', line 47 def session_key(klass) (cart_name(klass) + "_id").to_sym end |