| Class | Cart |
| In: |
app/models/cart.rb
|
| Parent: | Object |
| items | [R] |
# File app/models/cart.rb, line 7
7: def add_product(product)
8: current_item = @items.find {|item| item.product == product}
9: if current_item
10: current_item.increment_quantity
11: else
12: current_item = CartItem.new(product)
13: @items << current_item
14: end
15: current_item
16: end
# File app/models/cart.rb, line 18
18: def total_items
19: @items.sum { |item| item.quantity }
20: end