Answer the question
In order to leave comments, you need to log in
Does not store cookies. What could be?
Good day.
I am developing a store on Django-Oscar. After numerous edits, the block "recently viewed products" disappeared. The products on the page are available through templatetag
:
@register.inclusion_tag('customer/history/recently_viewed_products.html',
takes_context=True)
def recently_viewed_products(context):
"""
Inclusion tag listing the most recently viewed products
"""
# import pdb; pdb.set_trace() # debug yskhlyan
request = context['request']
products = history.get(request)
return {'products': products,
'request': request}
history.get(request)
looks like this:def get(request):
"""
Return a list of recently viewed products
"""
ids = extract(request)
# Reordering as the ID order gets messed up in the query
product_dict = Product.browsable.in_bulk(ids)
ids.reverse()
return [product_dict[id] for id in ids if id in product_dict]
def extract(request, response=None):
"""
Extract the IDs of products in the history cookie
"""
ids = []
cookie_name = settings.OSCAR_RECENTLY_VIEWED_COOKIE_NAME
if cookie_name in request.COOKIES:
try:
ids = json.loads(request.COOKIES[cookie_name])
except ValueError:
# This can occur if something messes up the cookie
if response:
response.delete_cookie(cookie_name)
else:
# Badly written web crawlers send garbage in double quotes
if not isinstance(ids, list):
ids = []
return ids
pdb
I looked at request.COOKIES
, and there is no necessary key in it (settings.OSCAR_RECENTLY_VIEWED_COOKIE_NAME = 'oscar_history'
) Answer the question
In order to leave comments, you need to log in
Solved a problem.
Registered in __init__.py:
default_app_config = 'apps.customer.config.CustomerConfig'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question