Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### mod to basket_controller.rb
- def basket_takes(id)
- if id == "all"
- session[:basket]['Space'].each {|k,v|
- apple = Inventory.find(k, :conditions => ["billable_type = ?",'Space'])
- apple.update_attribute(:stock_qty, apple.stock_qty + 1)
- }
- session[:basket].clear
- else
- apple = Inventory.find(id)
- apple.update_attribute(:stock_qty, apple.stock_qty + 1)
- session[:basket][apple.variety][apple.id] -= 1
- session[:basket][apple.variety].delete_if {|k,v| v == 0}
- session[:basket].delete_if {|k,v| v.empty?} #<^ i think this is a bit of a wtf.
- end
- end
- ### mod to apple.rb
- def initialize(id,basket)
- @apple = id.to_i
- inv = Inventory.find(@apple)
- @variety = inv.billable_type
- inv.update_attribute(:stock_qty,inv.stock_qty - 1)
- if basket[@variety] && basket[@variety].has_key?(@apple)
- @quantity = basket[@variety][@apple] + 1
- else
- @quantity = 1
- end
- end
Add Comment
Please, Sign In to add comment