Skip to content

Commit

Permalink
add_product メソッドを改良
Browse files Browse the repository at this point in the history
数量を考慮
  • Loading branch information
kyanny committed Jan 20, 2010
1 parent 75b7270 commit c353084
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion depot/app/models/cart.rb
Expand Up @@ -6,6 +6,11 @@ def initialize
end

def add_product (product)
@items << product
current_item = @items.find { |item| item.product == product }
if current_item
current_item.increment_quantity
else
@items << CartItem.new(product)
end
end
end

0 comments on commit c353084

Please sign in to comment.