module Stall::WishListHelper
Public Instance Methods
current_wish_list()
click to toggle source
# File lib/stall/wish_list_helper.rb, line 15 def current_wish_list RequestStore.store[wish_list_key] ||= load_current_wish_list end
Protected Instance Methods
current_wish_list_key()
click to toggle source
# File lib/stall/wish_list_helper.rb, line 21 def current_wish_list_key params[:wish_list_key].try(:to_sym) || :default end
find_wish_list(identifier, ensure_active_wish_list = true)
click to toggle source
# File lib/stall/wish_list_helper.rb, line 56 def find_wish_list(identifier, ensure_active_wish_list = true) if (wish_list_token = cookies.encrypted[wish_list_key(identifier)]) if (current_wish_list = ProductList.find_by_token(wish_list_token)) && (!ensure_active_wish_list || current_wish_list.active?) then return current_wish_list else # Remove any wish_list that can't be fetched, either because it's already # paid, or because it was cleaned out remove_wish_list_from_cookies(identifier) nil end end end
load_current_wish_list(identifier = current_wish_list_key)
click to toggle source
# File lib/stall/wish_list_helper.rb, line 25 def load_current_wish_list(identifier = current_wish_list_key) if (wish_list = find_wish_list(identifier)) return prepare_wish_list(wish_list) end # If no token was stored or the token does not exist anymore, create a # new wish_list and store the new token # prepare_wish_list(wish_list_class.new(identifier: identifier)) end
prepare_wish_list(wish_list)
click to toggle source
# File lib/stall/wish_list_helper.rb, line 36 def prepare_wish_list(wish_list) wish_list.tap do wish_list.customer = current_customer if current_customer # Keep track of potential customer locale switching to allow e-mailing # him in his last used locale # # Only applicable if the locale is an available locale to avoid strange # issues with some URL locale management systems that could set the # `assets` prefix as a locale, for instance. if wish_list.customer && I18n.locale.in?(I18n.available_locales) wish_list.customer.locale = I18n.locale end # Only update locale change for existing wish_lists. New wish_lists don't need # to be saved, avoiding each robot or simple visitors to create a # wish_list on large shops. wish_list.save unless wish_list.new_record? end end
wish_list_class()
click to toggle source
# File lib/stall/wish_list_helper.rb, line 79 def wish_list_class WishList end
wish_list_key(identifier = current_wish_list_key, namespace: nil)
click to toggle source
# File lib/stall/wish_list_helper.rb, line 75 def wish_list_key(identifier = current_wish_list_key, namespace: nil) ['stall', 'wish_list', namespace, identifier.to_s].compact.join('.') end