2015-03-03 14:55:30 +05:30
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2014-04-18 16:15:31 +05:30
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
2017-05-11 18:03:12 +05:30
|
|
|
from frappe.utils import cstr, nowdate, cint
|
2014-06-18 17:33:01 +05:30
|
|
|
from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_html
|
2014-04-18 16:15:31 +05:30
|
|
|
|
|
|
|
no_cache = 1
|
|
|
|
no_sitemap = 1
|
|
|
|
|
2016-06-27 14:54:46 +05:30
|
|
|
def get_context(context):
|
|
|
|
context.show_search = True
|
|
|
|
|
2014-04-18 16:15:31 +05:30
|
|
|
@frappe.whitelist(allow_guest=True)
|
2015-12-16 12:57:02 +05:30
|
|
|
def get_product_list(search=None, start=0, limit=12):
|
|
|
|
# limit = 12 because we show 12 items in the grid view
|
|
|
|
|
2014-04-18 16:15:31 +05:30
|
|
|
# base query
|
2016-06-23 18:25:50 +05:30
|
|
|
query = """select name, item_name, item_code, route, website_image, thumbnail, item_group,
|
|
|
|
description, web_long_description as website_description
|
2015-10-29 11:35:16 +05:30
|
|
|
from `tabItem`
|
2017-04-19 13:04:53 +05:30
|
|
|
where (show_in_website = 1 or show_variant_in_website = 1)
|
2015-10-29 12:21:41 +05:30
|
|
|
and disabled=0
|
2017-04-19 13:04:53 +05:30
|
|
|
and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)"""
|
2014-04-18 16:15:31 +05:30
|
|
|
|
|
|
|
# search term condition
|
|
|
|
if search:
|
2014-08-25 18:38:08 +05:30
|
|
|
query += """ and (web_long_description like %(search)s
|
2014-08-20 11:43:18 +05:30
|
|
|
or description like %(search)s
|
|
|
|
or item_name like %(search)s
|
|
|
|
or name like %(search)s)"""
|
2014-04-18 16:15:31 +05:30
|
|
|
search = "%" + cstr(search) + "%"
|
|
|
|
|
|
|
|
# order by
|
2017-05-11 18:03:12 +05:30
|
|
|
query += """ order by weightage desc, idx desc, modified desc limit %s, %s""" % (cint(start), cint(limit))
|
2014-04-18 16:15:31 +05:30
|
|
|
|
|
|
|
data = frappe.db.sql(query, {
|
|
|
|
"search": search,
|
2015-10-29 11:35:16 +05:30
|
|
|
"today": nowdate()
|
2014-04-18 16:15:31 +05:30
|
|
|
}, as_dict=1)
|
|
|
|
|
|
|
|
return [get_item_for_list_in_html(r) for r in data]
|
|
|
|
|