Module: Carter::Cart::ClassMethods

Defined in:
lib/carter/cart.rb

Instance Method Summary collapse

Instance Method Details

#add_cart_association(klass) ⇒ Object

TODO doesn’t work for polymorphic assoc



66
67
68
69
# File 'lib/carter/cart.rb', line 66

def add_cart_association(klass)
  klass_key = klass.name.downcase.to_sym
  self.has_many klass_key.to_s.pluralize.to_sym, :through => :cart_items, :source => :cartable, :source_type => klass_key.to_s
end

#remove_carts(days = 7, state = :active) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/carter/cart.rb', line 54

def remove_carts(days=7, state=:active)
  expiry_date = (Time.now.midnight - days.days.to_i)
  count = 0

  self.with_state(state).expired(expiry_date).find_in_batches do |batch|
    count += self.delete(batch.map &:id)
  end

  count
end