Class: Cart

Inherits:
Record
  • Object
show all
Defined in:
lib/models/cart.rb

Constant Summary collapse

CART_HOLD_DURATION =

10 minutes

10 * 60

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.perform_destroy_stale_carts(site) ⇒ Object



9
10
11
12
13
14
# File 'lib/models/cart.rb', line 9

def self.perform_destroy_stale_carts(site)
  # ignore carts which have been purchased
  query = site.carts.where(transaction: nil)
  query = query.where(updated_at: {'$lt' => Time.at(Time.now.utc.to_i - CART_HOLD_DURATION)})
  query.all.each(&:destroy)
end

Instance Method Details

#delete_all_product_holdsObject



5
6
7
# File 'lib/models/cart.rb', line 5

def delete_all_product_holds
  product_holds.each(&:destroy)
end