From ab69029d4ed5603e35d2f5b2cb74a429590bd6d9 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 13 Jun 2013 11:21:35 +0530 Subject: [PATCH 1/5] [shopping cart] [start] --- public/js/website_utils.js | 59 +++++++++++++++--- website/templates/html/outer.html | 9 +++ website/templates/html/product_in_list.html | 3 +- website/templates/html/product_page.html | 10 +++- website/templates/js/cart.js | 66 +++++++++++++++++++++ website/templates/js/product_page.js | 33 +++++++++-- website/templates/pages/cart.html | 17 ++++++ 7 files changed, 180 insertions(+), 17 deletions(-) create mode 100644 website/templates/js/cart.js create mode 100644 website/templates/pages/cart.html diff --git a/public/js/website_utils.js b/public/js/website_utils.js index d1b5ab7f20..73fb04b107 100644 --- a/public/js/website_utils.js +++ b/public/js/website_utils.js @@ -70,16 +70,17 @@ $(document).ready(function() { // update login var full_name = getCookie("full_name"); if(full_name) { - $("#user-tools").html(repl('%(full_name)s | \ - My Account | \ - \ - ', { - full_name: full_name, - count: getCookie("cart_count") || "0" - })); - $("#user-tools a").tooltip({"placement":"bottom"}); + $("#user-tools").addClass("hide"); + $("#user-tools-post-login").removeClass("hide"); + $("#user-full-name").text(full_name); } -}) + + wn.cart.update_display(); + $("#user-tools a").tooltip({"placement":"bottom"}); + $("#user-tools-post-login a").tooltip({"placement":"bottom"}); + + $(window).on("storage", function() { wn.cart.update_display(); }); +}); // Utility functions @@ -162,3 +163,43 @@ if (typeof Array.prototype.map !== "function") { return a; }; } + +// shopping cart +if(!wn.cart) wn.cart = {}; +$.extend(wn.cart, { + get_count: function() { + return Object.keys(this.get_cart()).length; + }, + + add_to_cart: function(itemprop) { + var cart = this.get_cart(); + cart[itemprop.item_code] = $.extend(itemprop, {qty: 1}); + this.set_cart(cart); + console.log(this.get_cart()); + }, + + remove_from_cart: function(item_code) { + var cart = this.get_cart(); + delete cart[item_code]; + this.set_cart(cart); + console.log(this.get_cart()); + }, + + get_cart: function() { + if( !("localStorage" in window) ) { + alert("Your browser seems to be ancient. Please use a modern browser."); + throw "ancient browser error"; + } + + return JSON.parse(localStorage.getItem("cart")) || {}; + }, + + set_cart: function(cart) { + localStorage.setItem("cart", JSON.stringify(cart)); + wn.cart.update_display(); + }, + + update_display: function() { + $(".cart-count").text("( " + wn.cart.get_count() + " )"); + } +}); \ No newline at end of file diff --git a/website/templates/html/outer.html b/website/templates/html/outer.html index ec71476f77..cc1181cbd2 100644 --- a/website/templates/html/outer.html +++ b/website/templates/html/outer.html @@ -3,8 +3,17 @@ {% block body %}
+
+ | + My Account | + + | + +
{% if banner_html %}
{{ banner_html }}
diff --git a/website/templates/html/product_in_list.html b/website/templates/html/product_in_list.html index e9752b3d4a..14f020bb91 100644 --- a/website/templates/html/product_in_list.html +++ b/website/templates/html/product_in_list.html @@ -1,4 +1,5 @@ -
+ + {% if obj.doclist.get({"doctype":"Item Website Specification"}) -%} diff --git a/website/templates/js/cart.js b/website/templates/js/cart.js new file mode 100644 index 0000000000..8746dd6d5a --- /dev/null +++ b/website/templates/js/cart.js @@ -0,0 +1,66 @@ +// ERPNext - web based ERP (http://erpnext.com) +// Copyright (C) 2012 Web Notes Technologies Pvt Ltd +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// js inside blog page + +$(document).ready(function() { + // make list of items in the cart + wn.cart.render(); +}); + +// shopping cart +if(!wn.cart) wn.cart = {}; +$.extend(wn.cart, { + render: function() { + var $cart_wrapper = $("#cart-added-items").empty(); + if(Object.keys(wn.cart.get_cart()).length) { + $('
\ +
\ +
\ +
\ +
Item Details
\ +
\ +
\ +
Qty
\ +

').appendTo($cart_wrapper); + + $.each(wn.cart.get_cart(), function(item_code, item) { + item.image_html = item.image ? + '
' : + '{% include "app/website/templates/html/product_missing_image.html" %}'; + item.price_html = item.price ? ('

@ ' + item.price + '

') : ""; + + $(repl('
\ +
\ +
\ +
%(image_html)s
\ +
\ +

%(item_name)s

\ +

%(description)s

\ +
\ +
\ +
\ +
\ + \ + %(price_html)s\ +
\ +

', item)).appendTo($cart_wrapper); + }); + } else { + $('

No Items added to cart.

').appendTo($cart_wrapper); + } + } +}); \ No newline at end of file diff --git a/website/templates/js/product_page.js b/website/templates/js/product_page.js index 69e9cd52fe..338f25331d 100644 --- a/website/templates/js/product_page.js +++ b/website/templates/js/product_page.js @@ -28,16 +28,41 @@ $(document).ready(function() { if(data.message.price) { $("

").html(data.message.price.ref_currency + " " + data.message.price.ref_rate).appendTo(".item-price"); - $(".item-price").toggle(true); + $(".item-price").removeClass("hide"); } if(data.message.stock==0) { - $(".item-stock").html("
Not in stock
") + $(".item-stock").html("
Not in stock
"); } else if(data.message.stock==1) { $(".item-stock").html("
\ - Available (in stock)
") + Available (in stock)

"); } } } - }) + }); + + if(wn.cart.get_cart()[$('[itemscope] [itemprop="name"]').text().trim()]) { + $(".item-remove-from-cart").removeClass("hide"); + } else { + $(".item-add-to-cart").removeClass("hide"); + } + + $("button.item-add-to-cart").on("click", function() { + wn.cart.add_to_cart({ + url: window.location.href, + image: $('[itemscope] [itemprop="image"]').attr("src"), + item_code: $('[itemscope] [itemprop="name"]').text().trim(), + item_name: $('[itemscope] [itemprop="productID"]').text().trim(), + description: $('[itemscope] [itemprop="description"]').html().trim(), + price: $('[itemscope] [itemprop="price"]').text().trim() + }); + $(".item-add-to-cart").addClass("hide"); + $(".item-remove-from-cart").removeClass("hide"); + }); + + $("button.item-remove-from-cart").on("click", function() { + wn.cart.remove_from_cart($('[itemscope] [itemprop="name"]').text().trim()); + $(".item-add-to-cart").removeClass("hide"); + $(".item-remove-from-cart").addClass("hide"); + }); }) \ No newline at end of file diff --git a/website/templates/pages/cart.html b/website/templates/pages/cart.html new file mode 100644 index 0000000000..31d50848fd --- /dev/null +++ b/website/templates/pages/cart.html @@ -0,0 +1,17 @@ +{% extends "app/website/templates/html/page.html" %} + +{% block javascript %} + {% include "app/website/templates/js/cart.js" %} +{% endblock %} + +{% set title="Shopping Cart" %} + +{% block content %} +
+

Shopping Cart

+
+
+ +
+
+{% endblock %} \ No newline at end of file From 8e2ea5fed6912b41c1fea59e6b1b3a52bb5df776 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 13 Jun 2013 14:40:57 +0530 Subject: [PATCH 2/5] [website] [partners listing] first cut --- config.json | 8 ++ setup/doctype/sales_partner/sales_partner.py | 66 ++++++------ setup/doctype/sales_partner/sales_partner.txt | 100 +++++++++++++----- website/helpers/partner.py | 11 ++ website/templates/html/partner_page.html | 28 +++++ website/templates/pages/partners.html | 30 ++++++ 6 files changed, 185 insertions(+), 58 deletions(-) create mode 100644 website/helpers/partner.py create mode 100644 website/templates/html/partner_page.html create mode 100644 website/templates/pages/partners.html diff --git a/config.json b/config.json index 33e898f221..46cd8c98f2 100644 --- a/config.json +++ b/config.json @@ -131,6 +131,10 @@ "cart": { "no_cache": true, "template": "app/website/templates/pages/cart.html" + }, + "partners": { + "template": "app/website/templates/pages/partners", + "args_method": "website.helpers.partner.get_partner_args" } }, "generators": { @@ -149,6 +153,10 @@ "Item Group":{ "template": "app/website/templates/html/product_group.html", "condition_field": "show_in_website" + }, + "Sales Partner": { + "template": "app/website/templates/html/partner_page.html", + "condition_field": "show_in_website" } } } diff --git a/setup/doctype/sales_partner/sales_partner.py b/setup/doctype/sales_partner/sales_partner.py index 285d3a9496..9e14485891 100644 --- a/setup/doctype/sales_partner/sales_partner.py +++ b/setup/doctype/sales_partner/sales_partner.py @@ -8,44 +8,50 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . from __future__ import unicode_literals import webnotes - -from webnotes.model import db_exists -from webnotes.model.bean import copy_doclist +from webnotes.utils import cint, cstr, filter_strip_join sql = webnotes.conn.sql - - class DocType: - def __init__(self, doc, doclist=[]): - self.doc = doc - self.doclist = doclist + def __init__(self, doc, doclist=None): + self.doc = doc + self.doclist = doclist - def validate(self): - import string - - if not (self.doc.address_line1) and not (self.doc.address_line2) and not (self.doc.city) and not (self.doc.state) and not (self.doc.country) and not (self.doc.pincode): - return "Please enter address" - - else: - address =["address_line1", "address_line2", "city", "state", "country", "pincode"] - comp_address='' - for d in address: - if self.doc.fields[d]: - comp_address += self.doc.fields[d] + "\n" - self.doc.address = comp_address - - def get_contacts(self,nm): - if nm: - contact_details =webnotes.conn.convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where sales_partner = '%s'"%nm)) - return contact_details - else: - return '' \ No newline at end of file + def on_update(self): + if cint(self.doc.show_in_website): + from webnotes.webutils import update_page_name + update_page_name(self.doc, self.doc.partner_name) + + if self.doc.page_name: + from webnotes.webutils import clear_cache + clear_cache(self.doc.page_name) + + def get_contacts(self,nm): + if nm: + contact_details =webnotes.conn.convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where sales_partner = '%s'"%nm)) + return contact_details + else: + return '' + + def prepare_template_args(self): + address = webnotes.conn.get_value("Address", + {"sales_partner": self.doc.name, "is_primary_address": 1}, + "*", as_dict=True) + if address: + city_state = ", ".join(filter(None, [address.city, address.state])) + address_rows = [address.address_line1, address.address_line2, + city_state, address.pincode, address.country] + + self.doc.fields.update({ + "email": address.email_id, + "partner_address": filter_strip_join(address_rows, "\n
"), + "phone": filter_strip_join(cstr(address.phone).split(","), "\n
") + }) diff --git a/setup/doctype/sales_partner/sales_partner.txt b/setup/doctype/sales_partner/sales_partner.txt index 81c75008be..6fdeb69422 100644 --- a/setup/doctype/sales_partner/sales_partner.txt +++ b/setup/doctype/sales_partner/sales_partner.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-01-10 16:34:24", + "creation": "2013-04-12 15:34:06", "docstatus": 0, - "modified": "2013-01-22 15:04:05", + "modified": "2013-06-13 14:40:04", "modified_by": "Administrator", "owner": "Administrator" }, @@ -25,6 +25,7 @@ "permlevel": 0 }, { + "amend": 0, "doctype": "DocPerm", "name": "__common__", "parent": "Sales Partner", @@ -39,14 +40,6 @@ "doctype": "DocType", "name": "Sales Partner" }, - { - "description": "Note: You Can Manage Multiple Address or Contacts via Addresses & Contacts", - "doctype": "DocField", - "fieldname": "basic_info", - "fieldtype": "Section Break", - "label": "Sales Partner Details", - "oldfieldtype": "Section Break" - }, { "doctype": "DocField", "fieldname": "partner_name", @@ -69,6 +62,14 @@ "options": "\nChannel Partner\nDistributor\nDealer\nAgent\nRetailer\nImplementation Partner\nReseller", "search_index": 0 }, + { + "doctype": "DocField", + "fieldname": "territory", + "fieldtype": "Link", + "label": "Territory", + "options": "Territory", + "reqd": 1 + }, { "doctype": "DocField", "fieldname": "column_break0", @@ -85,14 +86,6 @@ "oldfieldtype": "Currency", "reqd": 1 }, - { - "doctype": "DocField", - "fieldname": "territory", - "fieldtype": "Link", - "label": "Territory", - "options": "Territory", - "reqd": 1 - }, { "doctype": "DocField", "fieldname": "address_contacts", @@ -162,7 +155,67 @@ "options": "Budget Distribution" }, { - "amend": 0, + "doctype": "DocField", + "fieldname": "website", + "fieldtype": "Section Break", + "label": "Website" + }, + { + "doctype": "DocField", + "fieldname": "show_in_website", + "fieldtype": "Check", + "label": "Show In Website" + }, + { + "depends_on": "eval:cint(doc.show_in_website)", + "doctype": "DocField", + "fieldname": "section_break_17", + "fieldtype": "Section Break" + }, + { + "doctype": "DocField", + "fieldname": "logo", + "fieldtype": "Select", + "label": "Logo", + "options": "attach_files:" + }, + { + "doctype": "DocField", + "fieldname": "partner_website", + "fieldtype": "Data", + "label": "Partner's Website" + }, + { + "doctype": "DocField", + "fieldname": "column_break_20", + "fieldtype": "Column Break" + }, + { + "doctype": "DocField", + "fieldname": "page_name", + "fieldtype": "Data", + "label": "Page Name", + "read_only": 1 + }, + { + "depends_on": "eval:cint(doc.show_in_website)", + "doctype": "DocField", + "fieldname": "section_break_22", + "fieldtype": "Section Break" + }, + { + "doctype": "DocField", + "fieldname": "introduction", + "fieldtype": "Text", + "label": "Introduction" + }, + { + "doctype": "DocField", + "fieldname": "description", + "fieldtype": "Text Editor", + "label": "Description" + }, + { "cancel": 0, "create": 0, "doctype": "DocPerm", @@ -170,7 +223,6 @@ "write": 0 }, { - "amend": 0, "cancel": 0, "create": 0, "doctype": "DocPerm", @@ -178,18 +230,10 @@ "write": 0 }, { - "amend": 0, "cancel": 1, "create": 1, "doctype": "DocPerm", "role": "Sales Master Manager", "write": 1 - }, - { - "cancel": 1, - "create": 1, - "doctype": "DocPerm", - "role": "System Manager", - "write": 1 } ] \ No newline at end of file diff --git a/website/helpers/partner.py b/website/helpers/partner.py new file mode 100644 index 0000000000..cfe66b9862 --- /dev/null +++ b/website/helpers/partner.py @@ -0,0 +1,11 @@ +# Copyright (c) 2012 Web Notes Technologies Pvt Ltd. +# License: GNU General Public License (v3). For more information see license.txt + +from __future__ import unicode_literals +import webnotes + +def get_partner_args(): + return { + "partners": webnotes.conn.sql("""select * from `tabSales Partner` + where show_in_website=1 order by name asc""", as_dict=True), + } \ No newline at end of file diff --git a/website/templates/html/partner_page.html b/website/templates/html/partner_page.html new file mode 100644 index 0000000000..4910d07900 --- /dev/null +++ b/website/templates/html/partner_page.html @@ -0,0 +1,28 @@ +{% extends "app/website/templates/html/page.html" %} + +{% block content %} +
+
+
+ {% if logo -%} + +

+ {%- endif %} +
+
+ {% if partner_website -%}

{{ partner_website }}

{%- endif %} + {% if partner_address -%}

{{ partner_address }}

{%- endif %} + {% if phone -%}

{{ phone }}

{%- endif %} + {% if email -%}

{{ email }}

{%- endif %} +
+
+
+
+

{{ partner_name }}

+

{{ description }}

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/website/templates/pages/partners.html b/website/templates/pages/partners.html new file mode 100644 index 0000000000..978987b205 --- /dev/null +++ b/website/templates/pages/partners.html @@ -0,0 +1,30 @@ +{% extends "app/website/templates/html/page.html" %} + +{% set title="Sales Partners" %} + +{% block content %} +
+

Sales Partners

+
+ {% for partner_info in partners %} +
+
+ {% if partner_info.logo -%} + + + + {%- endif %} +
+
+ +

{{ partner_info.partner_name }}

+
+

{{ partner_info.territory }} - {{ partner_info.partner_type }}

+

{{ partner_info.introduction }}

+
+
+
+ {% endfor %} +
+{% endblock %} \ No newline at end of file From 1e92aeddb47df4fd21cc0cd181f0b8abdc954cf3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 13 Jun 2013 15:25:38 +0530 Subject: [PATCH 3/5] [website] set max width to 728px and show email icon in partner's email --- website/css/website.css | 4 ++++ website/templates/html/partner_page.html | 16 +++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/website/css/website.css b/website/css/website.css index 36e306d5eb..4af35dcc72 100644 --- a/website/css/website.css +++ b/website/css/website.css @@ -1,3 +1,7 @@ +.container { + max-width: 728px !important; +} + h1, h2, h3, h4, h5 { font-weight: bold; } diff --git a/website/templates/html/partner_page.html b/website/templates/html/partner_page.html index 4910d07900..37cf0b053a 100644 --- a/website/templates/html/partner_page.html +++ b/website/templates/html/partner_page.html @@ -9,15 +9,13 @@ alt="{{ partner_name }}" title="{{ partner_name }}" />

{%- endif %} -
-
- {% if partner_website -%}

{{ partner_website }}

{%- endif %} - {% if partner_address -%}

{{ partner_address }}

{%- endif %} - {% if phone -%}

{{ phone }}

{%- endif %} - {% if email -%}

{{ email }}

{%- endif %} -
-
+
+ {% if partner_website -%}

{{ partner_website }}

{%- endif %} + {% if partner_address -%}

{{ partner_address }}

{%- endif %} + {% if phone -%}

{{ phone }}

{%- endif %} + {% if email -%}

{{ email }}

{%- endif %} +

{{ partner_name }}

From 3c5b1a54609c9b783c25b64508fc2a886f3aa5d3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 13 Jun 2013 15:38:16 +0530 Subject: [PATCH 4/5] [partner listing] clear partners page on save --- setup/doctype/sales_partner/sales_partner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/doctype/sales_partner/sales_partner.py b/setup/doctype/sales_partner/sales_partner.py index 9e14485891..dc46b20e17 100644 --- a/setup/doctype/sales_partner/sales_partner.py +++ b/setup/doctype/sales_partner/sales_partner.py @@ -33,6 +33,7 @@ class DocType: if self.doc.page_name: from webnotes.webutils import clear_cache clear_cache(self.doc.page_name) + clear_cache("partners") def get_contacts(self,nm): if nm: From 32f9f366e516d5db0eeaf0d6a1e405f443e890ce Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 13 Jun 2013 16:11:03 +0530 Subject: [PATCH 5/5] [progress bar] [fix] --- website/templates/pages/blog.html | 2 +- website/templates/pages/orders.html | 2 +- website/templates/pages/tickets.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website/templates/pages/blog.html b/website/templates/pages/blog.html index fcb542bff8..d7eaba4de3 100644 --- a/website/templates/pages/blog.html +++ b/website/templates/pages/blog.html @@ -19,7 +19,7 @@
-
+
diff --git a/website/templates/pages/orders.html b/website/templates/pages/orders.html index b5b0dd9193..f43a474877 100644 --- a/website/templates/pages/orders.html +++ b/website/templates/pages/orders.html @@ -18,7 +18,7 @@ wn.currency_symbols = {{ currency_symbols }};
-
+
diff --git a/website/templates/pages/tickets.html b/website/templates/pages/tickets.html index 27881efa4d..f1ee58a9be 100644 --- a/website/templates/pages/tickets.html +++ b/website/templates/pages/tickets.html @@ -13,7 +13,7 @@
-
+