|
|
@@ -2,6 +2,7 @@ from django import template
|
|
2
|
2
|
from django.db.models import get_model
|
|
3
|
3
|
|
|
4
|
4
|
from oscar.core.loading import get_class
|
|
|
5
|
+
|
|
5
|
6
|
Product = get_model('catalogue', 'Product')
|
|
6
|
7
|
get_recently_viewed_product_ids = get_class('customer.history_helpers',
|
|
7
|
8
|
'get_recently_viewed_product_ids')
|
|
|
@@ -12,21 +13,19 @@ register = template.Library()
|
|
12
|
13
|
@register.inclusion_tag('customer/history/recently_viewed_products.html',
|
|
13
|
14
|
takes_context=True)
|
|
14
|
15
|
def recently_viewed_products(context):
|
|
15
|
|
- u"""
|
|
|
16
|
+ """
|
|
16
|
17
|
Inclusion tag listing the most recently viewed products
|
|
17
|
18
|
"""
|
|
18
|
19
|
request = context['request']
|
|
19
|
20
|
product_ids = get_recently_viewed_product_ids(request)
|
|
20
|
21
|
|
|
21
|
|
- try:
|
|
22
|
|
- current_product = context.get('product', None)
|
|
|
22
|
+ current_product = context.get('product', None)
|
|
|
23
|
+ if current_product.id in product_ids:
|
|
23
|
24
|
product_ids.remove(current_product.id)
|
|
24
|
|
- except (ValueError, AttributeError):
|
|
25
|
|
- pass
|
|
26
|
|
-
|
|
27
|
|
- product_dict = Product.browsable.in_bulk(product_ids)
|
|
28
|
25
|
|
|
29
|
26
|
# Reordering as the id order gets messed up in the query
|
|
|
27
|
+ product_dict = Product.browsable.in_bulk(product_ids)
|
|
30
|
28
|
product_ids.reverse()
|
|
31
|
29
|
products = [product_dict[id] for id in product_ids if id in product_dict]
|
|
32
|
|
- return {'products': products}
|
|
|
30
|
+ return {'products': products,
|
|
|
31
|
+ 'request': request}
|