Finished chapter 9
[depot.git] / app / models / cart.rb
index 0f1d52e731588dd79ac0bde3fe487761d93ad3be..bd51c383311d6a0a008208a3908955e330be963a 100644 (file)
@@ -10,12 +10,18 @@ class Cart
     if current_item
       current_item.increment_quantity
     else
-      @items << CartItem.new(product)
+      current_item = CartItem.new(product)
+      @items << current_item
     end
+    current_item
   end
   
   def total_price
     @items.sum {|item| item.price}
   end
   
+  def total_items
+    @items.sum {|item| item.quantity}
+  end
+  
 end