Class | Cart
In: | app/models/cart.rb
Parent: | Object

### Methods

add_product new total_items total_price

### Attributes

items | [R] |

### Public Class methods

new()

[Source]

       # File app/models/cart.rb, line 3
    3:   def initialize
    4:     @items = []
    5:   end

### Public Instance methods

add_product(product)

[Source]

        # 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

total_items()

[Source]

        # File app/models/cart.rb, line 18
    18:   def total_items
    19:     @items.sum { |item| item.quantity }
    20:   end

total_price()

[Source]

        # File app/models/cart.rb, line 22
    22:   def total_price
    23:     @items.sum { |item| item.price }
    24:   end

[Validate]