added filtering by discount to product search
This commit is contained in:
@@ -125,7 +125,7 @@ def find_related_products_v3(keyword):
|
||||
return set(products_qs)
|
||||
|
||||
|
||||
def find_related_products_v6(keyword, shipping_cost=None):
|
||||
def find_related_products_v6(keyword, shipping_cost=None, discount=None):
|
||||
"""
|
||||
Ranked product search
|
||||
|
||||
@@ -143,6 +143,7 @@ def find_related_products_v6(keyword, shipping_cost=None):
|
||||
rank=SearchRank(vector, query)
|
||||
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
||||
|
||||
# filter for shipping cost
|
||||
if shipping_cost is True:
|
||||
# only instances with shipping costs
|
||||
products_qs = products_qs.filter(
|
||||
@@ -153,6 +154,17 @@ def find_related_products_v6(keyword, shipping_cost=None):
|
||||
# only intances without shpping costs
|
||||
products_qs = products_qs.filter(Q(shipping_cost=None)|Q(shipping_cost=0.00))
|
||||
|
||||
# filter for discount
|
||||
if discount is True:
|
||||
# only instances with shipping costs
|
||||
products_qs = products_qs.filter(
|
||||
Q(discount__isnull=False)&
|
||||
Q(discount__gte=1)
|
||||
)
|
||||
elif discount is False:
|
||||
# only intances without shpping costs
|
||||
products_qs = products_qs.filter(Q(discount=None)|Q(discount=0.00))
|
||||
|
||||
return set(products_qs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user