Forum: Ruby on Rails Combining Purchases

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F5e4c067ef53ec2ac2a3192dde7edd38?d=identicon&s=25 Ernie (Guest)
on 2008-12-09 23:45
(Received via mailing list)
I am able to combine purchase, however the quantity is not showing,
any suggestions?
Code:

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
This topic is locked and can not be replied to.