Skip to content

Instantly share code, notes, and snippets.

View mpautasso's full-sized avatar

Mauricio Pautasso mpautasso

  • Freelance programmer
  • Río Cuarto, Argentina
View GitHub Profile
@arieliten
arieliten / cart.rb
Created March 19, 2013 14:22
Basic Shopping Cart implementation, using ActiveRecord for persistence of Order/Item and a module to encapsulate the logic of a Cart
module MyApp
class Cart
attr_accessor :order, :items # <== ActiveRecord Instance of Order & Item
def initialize(user, token)
@order ||= user.blank? ? Order.load_for_guest(token) : Order.load_for_customer(user)
@items = @order.items
end
def add(product_id, quantity=1)