# class Cart

### Public Instance Methods

add_product(product_id) click to toggle source
href="Cart.html#method-i-add_product">#add_product

    # File app/models/cart.rb, line 7
    def add_product(product_id)
      current_item = line_items.find_by(product_id: product_id)
      if current_item
        current_item.quantity += 1
      else
        current_item = line_items.build(product_id: product_id)
        current_item.price = current_item.product.price
      end
      current_item
    end

total_price() click to toggle source

START:#total_price

    # File app/models/cart.rb, line 20
    def total_price
      line_items.to_a.sum { |item| item.total_price }
    end