Class: RightnowOms::Cart
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RightnowOms::Cart
- Defined in:
- app/models/rightnow_oms/cart.rb
Instance Method Summary (collapse)
Instance Method Details
- (Object) add_item(cartable, opts = { quantity: 1 })
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/rightnow_oms/cart.rb', line 21 def add_item(cartable, opts = { quantity: 1 }) cart_item = cart_items.find_by_cartable(cartable) if cart_item cart_item.update_attributes( quantity: cart_item.quantity + opts[:quantity].to_i, ) else cart_item = cart_items.create( cartable: cartable, name: cartable.cartable_name, price: opts[:price] || cartable.cartable_price, quantity: opts[:quantity], group: opts[:group], parent_id: opts[:parent_id] ) end cart_item end |
- (Object) cartable_count
17 18 19 |
# File 'app/models/rightnow_oms/cart.rb', line 17 def cartable_count cart_items.map.sum(&:quantity) end |
- (Object) total
13 14 15 |
# File 'app/models/rightnow_oms/cart.rb', line 13 def total cart_items.map.sum(&:total_price) || 0 end |