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
#add_item(cartable, opts = { quantity: 1 }) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/rightnow_oms/cart.rb', line 21 def add_item(cartable, opts = { quantity: 1 }) quantity = opts[:quantity] group = opts[:group] parent_id = opts[:parent_id] cart_item = cart_items.find_by_cartable(cartable) if cart_item cart_item.update_attributes( quantity: cart_item.quantity + quantity.to_i ) else cart_item = cart_items.create( cartable: cartable, name: cartable.cartable_name, price: cartable.cartable_price, quantity: quantity, group: group, parent_id: parent_id ) end cart_item end |
#cartable_count ⇒ Object
17 18 19 |
# File 'app/models/rightnow_oms/cart.rb', line 17 def cartable_count cart_items.map.sum(&:quantity) end |
#total ⇒ Object
13 14 15 |
# File 'app/models/rightnow_oms/cart.rb', line 13 def total cart_items.map.sum(&:total_price) || 0 end |