# Shopping cart (Newbie)

**URL:** <https://www.ruby-forum.com/t/shopping-cart-newbie/155340>\
**Category:** Rails\
**Created:** [December 10, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/shopping-cart-newbie/155340 "2008-12-10T19:06:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@ernie](https://www.ruby-forum.com/u/ernie)\
**Post date:** [December 10, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/shopping-cart-newbie/155340/1 "2008-12-10T19:06:42Z")

</div>

I have a shopping cart project that I am putting together. I am able  
to combine items and get the correct price, however the quantity does  
not show up as to how many of the same item is being bought. Here is  
my code. Any suggestions wold help out this newbie… not sure what I  
am doing wrong…Thanks!

class Basket

attr\_reader :purchases  
attr\_reader :total

def initialize  
@purchases = []  
@total = 0.0  
end

def add\_purchase(cart)  
@purchases \<\< Purchase.buy\_one(cart)  
@total += cart.price  
end

def add\_purchase(cart)  
appendFlag = true  
for purchase in @purchases  
if (cart.id == purchase.cart.id)  
appendFlag = false  
purchase.quantity += 1  
end  
end  
if(appendFlag)  
@purchases \<\< Purchase.buy\_one(cart)  
end

@total += cart.price  
end

def clear  
@purchases = []  
@total = 0.0  
end

end
