mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
updates to product_page (search) and kb fix
This commit is contained in:
@@ -33,7 +33,7 @@ KBItemToolbar = function(args, kb) {
|
|||||||
|
|
||||||
this.make_timestamp = function() {
|
this.make_timestamp = function() {
|
||||||
this.line1.innerHTML = repl('By %(name)s | %(when)s', {
|
this.line1.innerHTML = repl('By %(name)s | %(when)s', {
|
||||||
name: wn.utils.full_name(this.det.first_name, this.det.last_name),
|
name: wn.user_info(this.det.owner).fullname,
|
||||||
when: wn.datetime.comment_when(this.det.modified)
|
when: wn.datetime.comment_when(this.det.modified)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"creation": "2012-12-17 14:56:32",
|
"creation": "2012-12-17 14:56:32",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"modified": "2012-12-17 16:02:00"
|
"modified": "2012-12-18 14:23:19"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_attach": 1,
|
"allow_attach": 1,
|
||||||
@@ -823,11 +823,12 @@
|
|||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"description": "Will appear in search",
|
||||||
"depends_on": "show_in_website",
|
"depends_on": "show_in_website",
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"label": "Short Description",
|
"label": "Short Description",
|
||||||
"fieldname": "web_short_description",
|
"fieldname": "web_short_description",
|
||||||
"fieldtype": "Text",
|
"fieldtype": "Text Editor",
|
||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def get_questions():
|
|||||||
conds += ' and t1._user_tags like "%'+ t +'%"'
|
conds += ' and t1._user_tags like "%'+ t +'%"'
|
||||||
|
|
||||||
return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags,
|
return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags,
|
||||||
t2.first_name, t2.last_name, (select count(*) from tabAnswer where
|
(select count(*) from tabAnswer where
|
||||||
tabAnswer.question = t1.name) as answers
|
tabAnswer.question = t1.name) as answers
|
||||||
from tabQuestion t1, tabProfile t2
|
from tabQuestion t1, tabProfile t2
|
||||||
where t1.docstatus!=2
|
where t1.docstatus!=2
|
||||||
|
|||||||
@@ -25,14 +25,6 @@ def get_product_info(item_code):
|
|||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
@webnotes.whitelist(allow_guest=True)
|
||||||
def get_product_list(args=None):
|
def get_product_list(args=None):
|
||||||
"""
|
|
||||||
args = {
|
|
||||||
'limit_start': 0,
|
|
||||||
'limit_page_length': 20,
|
|
||||||
'search': '',
|
|
||||||
'product_group': '',
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import cstr
|
from webnotes.utils import cstr
|
||||||
|
|
||||||
@@ -40,11 +32,11 @@ def get_product_list(args=None):
|
|||||||
|
|
||||||
# base query
|
# base query
|
||||||
query = """\
|
query = """\
|
||||||
select name, item_name, page_name, website_image,
|
select name, item_name, page_name, website_image, item_group,
|
||||||
description, web_short_description
|
if(ifnull(web_short_description,'')='', web_long_description,
|
||||||
|
web_short_description) as web_short_description
|
||||||
from `tabItem`
|
from `tabItem`
|
||||||
where is_sales_item = 'Yes'
|
where docstatus = 0
|
||||||
and docstatus = 0
|
|
||||||
and show_in_website = 1"""
|
and show_in_website = 1"""
|
||||||
|
|
||||||
# search term condition
|
# search term condition
|
||||||
@@ -65,75 +57,6 @@ def get_product_list(args=None):
|
|||||||
and item_group = %(product_group)s"""
|
and item_group = %(product_group)s"""
|
||||||
|
|
||||||
# order by
|
# order by
|
||||||
query += """
|
query += """order by item_name asc, name asc limit %s, 10""" % args.start
|
||||||
order by item_name asc, name asc"""
|
|
||||||
|
|
||||||
from webnotes.widgets.query_builder import add_limit_to_query
|
|
||||||
query, args = add_limit_to_query(query, args)
|
|
||||||
|
|
||||||
return webnotes.conn.sql(query, args, as_dict=1)
|
return webnotes.conn.sql(query, args, as_dict=1)
|
||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
|
||||||
def get_product_category_list(args=None):
|
|
||||||
"""
|
|
||||||
args = {
|
|
||||||
'limit_start': 0,
|
|
||||||
'limit_page_length': 5,
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
import webnotes
|
|
||||||
|
|
||||||
if not args: args = webnotes.form_dict
|
|
||||||
|
|
||||||
query = """\
|
|
||||||
select count(name) as items, item_group
|
|
||||||
from `tabItem`
|
|
||||||
where is_sales_item = 'Yes'
|
|
||||||
and docstatus = 0
|
|
||||||
and show_in_website = 1
|
|
||||||
group by item_group
|
|
||||||
order by items desc"""
|
|
||||||
|
|
||||||
from webnotes.widgets.query_builder import add_limit_to_query
|
|
||||||
query, args = add_limit_to_query(query, args)
|
|
||||||
|
|
||||||
|
|
||||||
result = webnotes.conn.sql(query, args, as_dict=1)
|
|
||||||
|
|
||||||
# add All Products link
|
|
||||||
total_count = sum((r.get('items') or 0 for r in result))
|
|
||||||
result = [{'items': total_count, 'item_group': 'All Products'}] + (result or [])
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
|
||||||
def get_similar_product_list(args=None):
|
|
||||||
"""
|
|
||||||
args = {
|
|
||||||
'limit_start': 0,
|
|
||||||
'limit_page_length': 5,
|
|
||||||
'product_name': '',
|
|
||||||
'product_group': '',
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
import webnotes
|
|
||||||
|
|
||||||
if not args: args = webnotes.form_dict
|
|
||||||
|
|
||||||
query = """\
|
|
||||||
select name, item_name, page_name, website_image,
|
|
||||||
description, web_short_description
|
|
||||||
from `tabItem`
|
|
||||||
where is_sales_item = 'Yes'
|
|
||||||
and docstatus = 0
|
|
||||||
and show_in_website = 1
|
|
||||||
and name != %(product_name)s
|
|
||||||
and item_group = %(product_group)s
|
|
||||||
order by item_name"""
|
|
||||||
|
|
||||||
from webnotes.widgets.query_builder import add_limit_to_query
|
|
||||||
query, args = add_limit_to_query(query, args)
|
|
||||||
|
|
||||||
result = webnotes.conn.sql(query, args, as_dict=1)
|
|
||||||
|
|
||||||
return result
|
|
||||||
@@ -20,15 +20,19 @@
|
|||||||
<div class="layout-wrapper layout-wrapper-background">
|
<div class="layout-wrapper layout-wrapper-background">
|
||||||
<div class="web-content" id="content-product-{{ name }}">
|
<div class="web-content" id="content-product-{{ name }}">
|
||||||
<div class="layout-main" style="padding: 30px;">
|
<div class="layout-main" style="padding: 30px;">
|
||||||
{% include 'html/product_search.html' %}
|
{% include 'html/product_search_box.html' %}
|
||||||
<h1>{{ item_name }}</h1>
|
<h1>{{ item_name }}</h1>
|
||||||
<div class="product-page-content">
|
<div class="product-page-content">
|
||||||
<div class="span6">
|
<div class="span6">
|
||||||
{% if website_image %}
|
{% if website_image %}
|
||||||
<image class="item-main-image" src="files/{{ website_image }}" />
|
<image class="item-main-image" src="files/{{ website_image }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="img-area"></div>
|
<div class="img-area">
|
||||||
<span style="font-size: 11px">This is an auto-generated Image</span>
|
<div style='background-color: #eee; padding: 40px;
|
||||||
|
width: 32px; font-size: 32px; color: #888;'>
|
||||||
|
<i class='icon-camera'></i></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br><br>
|
<br><br>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,7 +55,7 @@
|
|||||||
{% for d in obj.doclist.get(
|
{% for d in obj.doclist.get(
|
||||||
{"doctype":"Item Website Specification"}) %}
|
{"doctype":"Item Website Specification"}) %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ d.label }}</td>
|
<td style="min-width: 150px;">{{ d.label }}</td>
|
||||||
<td>{{ d.description }}</td>
|
<td>{{ d.description }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<div class="pull-right">
|
|
||||||
<form class="form-search">
|
|
||||||
<div class="input-append">
|
|
||||||
<input type="text" class="span2 search-query" id="product-search">
|
|
||||||
<button class="btn"><i class="icon-search"></i></button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="clearfix"></div>
|
|
||||||
24
website/templates/html/product_search_box.html
Normal file
24
website/templates/html/product_search_box.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<div class="pull-right">
|
||||||
|
<form class="form-search">
|
||||||
|
<div class="input-append">
|
||||||
|
<input type="text" class="span2 search-query" id="product-search">
|
||||||
|
<button class="btn" id="btn-product-search">
|
||||||
|
<i class="icon-search"></i></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<script>
|
||||||
|
// redirect to product search page
|
||||||
|
$(document).ready(function() {
|
||||||
|
$("#btn-product-search").click(function() {
|
||||||
|
var txt = $("#product-search").val();
|
||||||
|
if(txt) {
|
||||||
|
window.location.href="product_search.html?q=" + txt;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$("#product-search").keypress(function(e) {
|
||||||
|
if(e.which==13) $("#product-search-btn").click();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
88
website/templates/pages/product_search.html
Normal file
88
website/templates/pages/product_search.html
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
{% extends "html/page.html" %}
|
||||||
|
|
||||||
|
{% block title %}Product Search{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var txt = get_url_arg("q");
|
||||||
|
$(".search-results").html("Search results for: " + txt);
|
||||||
|
|
||||||
|
window.start = 0;
|
||||||
|
var get_list = function() {
|
||||||
|
$.ajax({
|
||||||
|
method: "GET",
|
||||||
|
url: "server.py",
|
||||||
|
dataType: "json",
|
||||||
|
data: {
|
||||||
|
cmd: "website.helpers.product.get_product_list",
|
||||||
|
start: window.start,
|
||||||
|
search: txt
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data) {
|
||||||
|
render(data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var render = function(data) {
|
||||||
|
if(data.length) {
|
||||||
|
var table = $("#search-list .table");
|
||||||
|
if(!table.length)
|
||||||
|
var table = $("<table class='table'>").appendTo("#search-list");
|
||||||
|
|
||||||
|
$.each(data, function(i, d) {
|
||||||
|
if(!d.web_short_description)
|
||||||
|
d.web_short_description = "No description given."
|
||||||
|
var $tr = $(repl('<tr>\
|
||||||
|
<td style="width: 30%;">\
|
||||||
|
<img class="product-image" style="width: 80%;" src="files/%(website_image)s">\
|
||||||
|
</td>\
|
||||||
|
<td>\
|
||||||
|
<h4><a href="%(page_name)s">%(item_name)s</a></h4>\
|
||||||
|
<p class="help">Item Code: %(name)s</p>\
|
||||||
|
<p>%(web_short_description)s</p>\
|
||||||
|
</td>\
|
||||||
|
</tr>', d)).appendTo(table);
|
||||||
|
|
||||||
|
if(!d.website_image) {
|
||||||
|
$tr.find(".product-image").replaceWith("<div\
|
||||||
|
style='background-color: #eee; padding: 40px; \
|
||||||
|
width: 32px; font-size: 32px; color: #888;'>\
|
||||||
|
<i class='icon-camera'></i></div>");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
if(data.length < 10) {
|
||||||
|
$(".more-btn").replaceWith("<div class='alert'>Nothing more to show</div>");
|
||||||
|
} else {
|
||||||
|
$(".more-btn").toggle(true)
|
||||||
|
}
|
||||||
|
window.start += (data.length || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
get_list();
|
||||||
|
$(".more-btn .btn").click(function() {
|
||||||
|
get_list()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="layout-wrapper layout-wrapper-background">
|
||||||
|
<div class="web-content" id="content-product_search">
|
||||||
|
<div class="layout-main" style="padding: 30px;">
|
||||||
|
{% include 'html/product_search_box.html' %}
|
||||||
|
<h3 class="search-results">Search Results</h3>
|
||||||
|
<div id="search-list">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="more-btn" style="text-align: middle; display: none;">
|
||||||
|
<button class="btn">More...</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user