Class: Comable::Customer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Customer
- Includes:
- Decoratable
- Defined in:
- app/models/comable/customer.rb
Defined Under Namespace
Classes: Cart
Instance Method Summary collapse
- #add_cart_item(obj, quantity: 1) ⇒ Object
- #cart ⇒ Object
- #cart_items ⇒ Object
-
#initialize(*args) ⇒ Customer
constructor
A new instance of Customer.
- #logged_in? ⇒ Boolean
- #not_logged_in? ⇒ Boolean
- #order(order_params = {}) ⇒ Object
- #preorder(order_params = {}) ⇒ Object
- #remove_cart_item(obj, quantity: -1)) ⇒ Object
- #reset_cart ⇒ Object
- #reset_cart_item(obj, quantity: 0) ⇒ Object
Methods included from Decoratable
Constructor Details
#initialize(*args) ⇒ Customer
Returns a new instance of Customer.
8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/comable/customer.rb', line 8 def initialize(*args) obj = args.first case obj.class.name when /Cookies/ = obj super() else super end end |
Instance Method Details
#add_cart_item(obj, quantity: 1) ⇒ Object
27 28 29 30 31 |
# File 'app/models/comable/customer.rb', line 27 def add_cart_item(obj, quantity: 1) process_cart_item(obj) do |stock| add_stock_to_cart(stock, quantity) end end |
#cart ⇒ Object
56 57 58 |
# File 'app/models/comable/customer.rb', line 56 def cart Cart.new(cart_items) end |
#cart_items ⇒ Object
49 50 51 52 53 54 |
# File 'app/models/comable/customer.rb', line 49 def cart_items Comable::CartItem.where( Comable::Customer.table_name.singularize.foreign_key => id, :guest_token => current_guest_token ) end |
#logged_in? ⇒ Boolean
19 20 21 |
# File 'app/models/comable/customer.rb', line 19 def logged_in? !new_record? end |
#not_logged_in? ⇒ Boolean
23 24 25 |
# File 'app/models/comable/customer.rb', line 23 def not_logged_in? !logged_in? end |
#order(order_params = {}) ⇒ Object
71 72 73 |
# File 'app/models/comable/customer.rb', line 71 def order(order_params = {}) Comable::CashRegister.new(customer: self, order_attributes: order_params).create_order end |
#preorder(order_params = {}) ⇒ Object
67 68 69 |
# File 'app/models/comable/customer.rb', line 67 def preorder(order_params = {}) Comable::CashRegister.new(customer: self, order_attributes: order_params).build_order end |
#remove_cart_item(obj, quantity: -1)) ⇒ Object
33 34 35 36 37 |
# File 'app/models/comable/customer.rb', line 33 def remove_cart_item(obj, quantity: -1) process_cart_item(obj) do |stock| add_stock_to_cart(stock, quantity) end end |
#reset_cart ⇒ Object
45 46 47 |
# File 'app/models/comable/customer.rb', line 45 def reset_cart cart_items.destroy_all end |
#reset_cart_item(obj, quantity: 0) ⇒ Object
39 40 41 42 43 |
# File 'app/models/comable/customer.rb', line 39 def reset_cart_item(obj, quantity: 0) process_cart_item(obj) do |stock| reset_stock_from_cart(stock, quantity) end end |