website cleanups

This commit is contained in:
Rushabh Mehta 2014-04-21 22:10:15 +05:30
parent 0549b1c5c9
commit 3f51705ba4
10 changed files with 77 additions and 85 deletions

View File

@ -16,8 +16,9 @@ class ItemGroup(NestedSet, WebsiteGenerator):
def validate(self):
if not self.parent_website_route:
self.parent_website_route = frappe.get_website_route("Item Group",
self.parent_item_group)
if frappe.db.get_value("Item Group", self.parent_item_group, "show_in_website"):
self.parent_website_route = frappe.get_website_route("Item Group",
self.parent_item_group)
def on_update(self):
NestedSet.on_update(self)

View File

@ -55,6 +55,11 @@ class website_maker(object):
"label":"Blog",
"url": "blog"
})
website_settings.append("top_bar_items", {
"doctype": "Top Bar Item",
"label": _("Products"),
"url": frappe.db.get_value("Website Route", {"ref_doctype":"Item Group"})
})
website_settings.save()
def make_blog(self):

View File

@ -11,13 +11,18 @@ def install():
records = [
# item group
{'doctype': 'Item Group', 'item_group_name': _('All Item Groups'), 'is_group': 'Yes', 'parent_item_group': ''},
{'doctype': 'Item Group', 'item_group_name': _('Products'), 'is_group': 'No',
'parent_item_group': _('All Item Groups'), "show_in_website": 1 },
{'doctype': 'Item Group', 'item_group_name': _('Raw Material'), 'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('Services'), 'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('Sub Assemblies'), 'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('Consumable'), 'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('All Item Groups'),
'is_group': 'Yes', 'parent_item_group': ''},
{'doctype': 'Item Group', 'item_group_name': _('Products'),
'is_group': 'No', 'parent_item_group': _('All Item Groups'), "show_in_website": 1 },
{'doctype': 'Item Group', 'item_group_name': _('Raw Material'),
'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('Services'),
'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('Sub Assemblies'),
'is_group': 'No', 'parent_item_group': _('All Item Groups') },
{'doctype': 'Item Group', 'item_group_name': _('Consumable'),
'is_group': 'No', 'parent_item_group': _('All Item Groups') },
# deduction type
{'doctype': 'Deduction Type', 'name': _('Income Tax'), 'description': _('Income Tax'), 'deduction_name': _('Income Tax')},

View File

@ -22,19 +22,20 @@
{% endif %}
</div>
<div class="col-md-6">
<h3 itemprop="name" style="margin-top: 0px;">{{ item_name }}</h3>
<p class="help">Item Code: <span itemprop="productID">{{ name }}</span></p>
<h4>Product Description</h4>
<!-- <h3 itemprop="name" style="margin-top: 0px;">{{ item_name }}</h3> -->
<div itemprop="description">
{{ web_long_description or description or "[No description given]" }}
{{ web_long_description or description or _("No description given") }}
</div>
<p class="text-muted">
{{ _("Item Code") }}: <span itemprop="productID">{{ name }}</span></p>
<br>
<div style="min-height: 100px; margin: 10px 0;">
<div class="item-price-info" style="display: none;">
<h4 class="item-price" itemprop="price"></h4>
<div class="item-stock" itemprop="availablity"></div>
<div id="item-add-to-cart">
<button class="btn btn-primary">
<i class="icon-shopping-cart"></i> Add to Cart</button>
<i class="icon-shopping-cart"></i> + {{ _("Add to Cart") }}</button>
</div>
<div id="item-update-cart" class="input-group col-md-4" style="display: none;
padding-left: 0px; padding-right: 0px;">
@ -51,7 +52,7 @@
{% if doc.get({"doctype":"Item Website Specification"}) -%}
<div class="row" style="margin-top: 20px">
<div class="col-md-12">
<h4>Specifications</h4>
<h4>{{ _("Specifications") }}</h4>
<table class="table table-bordered" style="width: 100%">
{% for d in doc.get(
{"doctype":"Item Website Specification"}) -%}

View File

@ -1,7 +1,3 @@
{% block title %} {{ title }} {% endblock %}
{% block header %}<h2>{{ title }}</h2>{% endblock %}
{% block content %}
<div class="item-group-content">
{% include 'templates/includes/product_search_box.html' %}
@ -11,22 +7,9 @@
{% endif %}
{% if description %}<!-- description -->
<div itemprop="description">{{ description or ""}}</div>
{% else %}
<h3>{{ name }}</h3>
{% endif %}
</div>
<div>
{% if sub_groups %}
<hr />
<div class="row">
{% for d in sub_groups %}
<div class="col-sm-4">
<a href="{{ d.page_name }}">{{ d.name }} ({{ d.count }})</a>
</div>
{% endfor %}
</div>
<hr />
{% endif %}
{% if items %}
<div id="search-list" class="row">
{% for item in items %}
@ -37,7 +20,7 @@
<div class="alert alert-info info">Showing top 100 items.</div>
{% endif %}
{% else %}
<div class="alert alert-warning">No items listed.</div>
<div class="text-muted">No items listed.</div>
{% endif %}
</div>
</div>
@ -53,5 +36,3 @@ $(function() {
</script>
{% endblock %}
{% block sidebar %}{% include "templates/includes/sidebar.html" %}{% endblock %}

View File

@ -13,9 +13,6 @@ condition_field = "show_in_website"
def get_context(context):
item_group_context = context.doc.as_dict()
item_group_context.update({
"sub_groups": frappe.db.sql("""select name, page_name
from `tabItem Group` where parent_item_group=%s
and ifnull(show_in_website,0)=1""", context.docname, as_dict=1),
"items": get_product_list_for_group(product_group = context.docname, limit=100),
"parent_groups": get_parent_item_groups(context.docname),
"title": context.docname
@ -24,22 +21,20 @@ def get_context(context):
if context.doc.slideshow:
item_group_context.update(get_slideshow(context.doc))
for d in item_group_context.get("sub_groups"):
d.count = get_group_item_count(d.name)
return item_group_context
def get_product_list_for_group(product_group=None, start=0, limit=10):
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(product_group)])
# base query
query = """select name, item_name, page_name, website_image, item_group,
web_long_description as website_description
from `tabItem` where docstatus = 0 and show_in_website = 1
and (item_group in (%s)
or name in (select parent from `tabWebsite Item Group` where item_group in (%s))) """ % (child_groups, child_groups)
query = """select t1.name, t1.item_name, t1.page_name, t1.website_image, t1.item_group,
t1.web_long_description as website_description, t2.name as route
from `tabItem` t1, `tabWebsite Route` t2
where t1.show_in_website = 1 and (item_group in (%s)
or t1.name in (select parent from `tabWebsite Item Group` where item_group in (%s)))
and t1.name = t2.docname and t2.ref_doctype='Item' """ % (child_groups, child_groups)
query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit)
query += """order by t1.weightage desc, t1.modified desc limit %s, %s""" % (start, limit)
data = frappe.db.sql(query, {"product_group": product_group}, as_dict=1)

View File

@ -9,6 +9,6 @@
</a>
</div>
<div style="height: 100px; overflow: hidden; font-size: 80%;">
<h4 style="margin-bottom: 2px;"><a href="{{ page_name }}">{{ item_name }}</a></h4>
<div style="margin-bottom: 2px;"><a href="{{ route or page_name }}">{{ item_name }}</a></div>
</div>
</div>
</div>

View File

@ -10,6 +10,6 @@
</a>
</div>
<div style="height: 100px; overflow: hidden; font-size: 80%;">
<h4 style="margin-bottom: 2px;"><a href="{{ page_name }}">{{ item_name }}</a></h4>
<div><a href="{{ page_name }}">{{ item_name }}</a></div>
</div>
</div>
</div>

View File

@ -1,28 +1,31 @@
<div style="margin-bottom: 20px;">
<form class="form-inline form-search row">
<div class="input-group col-md-4 col-md-offset-8">
<input class="form-control" type="text" id="product-search" placeholder="Product Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="btn-product-search">
<i class="icon-search"></i></button>
</span>
</div>
</form>
<script>
// redirect to product search page
frappe.ready(function() {
$('.dropdown-toggle').dropdown();
$("#btn-product-search").click(function() {
var txt = $("#product-search").val();
if(txt) {
window.location.href="product_search?q=" + txt;
}
return false;
});
$("#product-search").keypress(function(e) {
if(e.which==13) $("#btn-product-search").click();
});
$(".form-search").on("submit", function() { return false; });
});
</script>
</div>
<script>
frappe.ready(function() {
$(".product-search").remove();
$('<div class="product-search">\
<form class="form-inline form-search">\
<div class="input-group">\
<input class="form-control" type="text" id="product-search" placeholder="Product Search...">\
<span class="input-group-btn">\
<button class="btn btn-default" type="button" id="btn-product-search">\
<i class="icon-search"></i></button>\
</span>\
</div>\
</form>\
</div>').appendTo(".page-header-right");
$('.dropdown-toggle').dropdown();
$("#btn-product-search").click(function() {
var txt = $("#product-search").val();
if(txt) {
window.location.href="product_search?q=" + txt;
}
return false;
});
$("#product-search").keypress(function(e) {
if(e.which==13) $("#btn-product-search").click();
});
$(".form-search").on("submit", function() { return false; });
});
</script>

View File

@ -12,18 +12,19 @@ no_sitemap = 1
@frappe.whitelist(allow_guest=True)
def get_product_list(search=None, start=0, limit=10):
# base query
query = """select name, item_name, page_name, website_image, item_group,
web_long_description as website_description
from `tabItem` where docstatus = 0 and show_in_website = 1 """
query = """select t1.name, t1.item_name, t1.page_name, t1.website_image, t1.item_group,
t1.web_long_description as website_description, t2.name as route
from `tabItem` t1, `tabWebsite Route` t2 where t1.show_in_website = 1
and t1.name = t2.docname and t2.ref_doctype = 'Item'"""
# search term condition
if search:
query += """and (web_long_description like %(search)s or
item_name like %(search)s or name like %(search)s)"""
query += """and (t1.web_long_description like %(search)s or t1.description like %(search)s or
t1.item_name like %(search)s or t1.name like %(search)s)"""
search = "%" + cstr(search) + "%"
# order by
query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit)
query += """order by t1.weightage desc, t1.modified desc limit %s, %s""" % (start, limit)
data = frappe.db.sql(query, {
"search": search,