jam-cloud/ruby/lib/jam_ruby/models/anonymous_user.rb

70 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

# this was added to support the idea of an anonymous user interacting with our site; needed by the ShoppingCart
# over time it might make sense to beef this up and to use it conistently in anonymous interactions
module JamRuby
class AnonymousUser
attr_accessor :id, :cookies
def initialize(id, cookies)
@id = id
@cookies = cookies
end
def shopping_carts
ShoppingCart.where(anonymous_user_id: @id).order('created_at DESC')
end
2016-08-03 01:46:15 +00:00
def mixed_cart
Sale.is_mixed(shopping_carts)
end
2015-11-29 19:58:10 +00:00
def destroy_all_shopping_carts
ShoppingCart.destroy_all(anonymous_user_id: @id)
end
2015-11-29 19:58:10 +00:00
def destroy_jam_track_shopping_carts
ShoppingCart.destroy_all(anonymous_user_id: @id, cart_type: JamTrack::PRODUCT_TYPE)
end
def admin
false
end
2015-03-20 13:48:00 +00:00
def has_redeemable_jamtrack
raise "not a cookied anonymous user" if @cookies.nil?
APP_CONFIG.one_free_jamtrack_per_user && !@cookies[:redeemed_jamtrack]
end
def gifted_jamtracks
0
end
2018-02-15 04:16:32 +00:00
def timezone
@cookies[:'browser.timezone']
end
def free_jamtracks
if has_redeemable_jamtrack
1
else
0
end
end
def show_free_jamtrack?
ShoppingCart.user_has_redeemable_jam_track?(self)
end
def signup_hint
2015-05-28 13:20:14 +00:00
SignupHint.where(anonymous_user_id: @id).where('expires_at > ?', Time.now).first
2015-03-20 13:48:00 +00:00
end
def reload
end
2016-08-03 01:46:15 +00:00
end
end