blob: af7509706c983a397193253f170026bccd3f1c5b [file] [log] [blame]
Kanchan Chauhane0818f82016-04-22 14:39:02 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5import frappe
6from frappe.utils import cstr, nowdate
7from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_html
8
9no_cache = 1
10no_sitemap = 1
11
12@frappe.whitelist(allow_guest=True)
13def get_product_list(search=None, start=0, limit=6):
14 # limit = 12 because we show 12 items in the grid view
15
16 # base query
17 query = """select name, item_name, page_name, website_image, thumbnail, item_group,
18 web_long_description as website_description, parent_website_route
19 from `tabItem`
20 where show_in_website = 1
21 and disabled=0
22 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)
23 and (variant_of is null or variant_of = '')"""
24
25 # order by
26 query += """ order by weightage desc, idx desc, modified desc limit %s, %s""" % (start, limit)
27
28 data = frappe.db.sql(query, {
29 "today": nowdate()
30 }, as_dict=1)
31
32 for d in data:
33 d.route = ((d.parent_website_route + "/") if d.parent_website_route else "") \
34 + (d.page_name or "")
35
36 return [get_item_for_list_in_html(r) for r in data]
37