blob: 9488efe6af57d15327898a5e3b353ad973544e13 [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
Anand Doshie3bd78e2016-04-22 18:53:21 +053012def get_context(context):
13 homepage = frappe.get_doc('Homepage')
14 return {
15 'homepage': homepage
16 }
17
18
Kanchan Chauhane0818f82016-04-22 14:39:02 +053019@frappe.whitelist(allow_guest=True)
20def get_product_list(search=None, start=0, limit=6):
21 # limit = 12 because we show 12 items in the grid view
22
23 # base query
24 query = """select name, item_name, page_name, website_image, thumbnail, item_group,
25 web_long_description as website_description, parent_website_route
26 from `tabItem`
27 where show_in_website = 1
28 and disabled=0
29 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)
30 and (variant_of is null or variant_of = '')"""
31
32 # order by
33 query += """ order by weightage desc, idx desc, modified desc limit %s, %s""" % (start, limit)
34
35 data = frappe.db.sql(query, {
36 "today": nowdate()
37 }, as_dict=1)
38
39 for d in data:
40 d.route = ((d.parent_website_route + "/") if d.parent_website_route else "") \
41 + (d.page_name or "")
42
43 return [get_item_for_list_in_html(r) for r in data]
44