2015-03-03 09:25:30 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2014-04-18 10:45:31 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
2015-10-29 06:05:16 +00:00
|
|
|
from frappe.utils import cstr, nowdate
|
2014-06-18 12:03:01 +00:00
|
|
|
from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_html
|
2014-04-18 10:45:31 +00:00
|
|
|
|
|
|
|
no_cache = 1
|
|
|
|
no_sitemap = 1
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True)
|
2015-12-16 07:27:02 +00:00
|
|
|
def get_product_list(search=None, start=0, limit=12):
|
|
|
|
# limit = 12 because we show 12 items in the grid view
|
|
|
|
|
2014-04-18 10:45:31 +00:00
|
|
|
# base query
|
2015-10-07 09:00:19 +00:00
|
|
|
query = """select name, item_name, page_name, website_image, thumbnail, item_group,
|
2014-08-20 06:13:18 +00:00
|
|
|
web_long_description as website_description, parent_website_route
|
2015-10-29 06:05:16 +00:00
|
|
|
from `tabItem`
|
|
|
|
where show_in_website = 1
|
2015-10-29 06:51:41 +00:00
|
|
|
and disabled=0
|
2015-10-29 06:05:16 +00:00
|
|
|
and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)
|
|
|
|
and (variant_of is null or variant_of = '')"""
|
2014-04-18 10:45:31 +00:00
|
|
|
|
|
|
|
# search term condition
|
|
|
|
if search:
|
2014-08-25 13:08:08 +00:00
|
|
|
query += """ and (web_long_description like %(search)s
|
2014-08-20 06:13:18 +00:00
|
|
|
or description like %(search)s
|
|
|
|
or item_name like %(search)s
|
|
|
|
or name like %(search)s)"""
|
2014-04-18 10:45:31 +00:00
|
|
|
search = "%" + cstr(search) + "%"
|
|
|
|
|
|
|
|
# order by
|
2014-08-25 13:08:08 +00:00
|
|
|
query += """ order by weightage desc, modified desc limit %s, %s""" % (start, limit)
|
2014-04-18 10:45:31 +00:00
|
|
|
|
|
|
|
data = frappe.db.sql(query, {
|
|
|
|
"search": search,
|
2015-10-29 06:05:16 +00:00
|
|
|
"today": nowdate()
|
2014-04-18 10:45:31 +00:00
|
|
|
}, as_dict=1)
|
|
|
|
|
2014-08-20 06:13:18 +00:00
|
|
|
for d in data:
|
|
|
|
d.route = ((d.parent_website_route + "/") if d.parent_website_route else "") \
|
2015-08-07 10:18:53 +00:00
|
|
|
+ (d.page_name or "")
|
2014-08-20 06:13:18 +00:00
|
|
|
|
2014-04-18 10:45:31 +00:00
|
|
|
return [get_item_for_list_in_html(r) for r in data]
|
|
|
|
|