[shopping cart] show items, editable qty and show amount for that item
diff --git a/public/js/website_utils.js b/public/js/website_utils.js
index 83becc6..098f8da 100644
--- a/public/js/website_utils.js
+++ b/public/js/website_utils.js
@@ -193,7 +193,8 @@
 				method: "website.helpers.cart.update_cart",
 				args: {
 					item_code: opts.item_code,
-					qty: opts.qty
+					qty: opts.qty,
+					with_doclist: opts.with_doclist
 				},
 				btn: opts.btn,
 				callback: function(r) {
diff --git a/selling/doctype/quotation/quotation.txt b/selling/doctype/quotation/quotation.txt
index 1017221..74a4396 100644
--- a/selling/doctype/quotation/quotation.txt
+++ b/selling/doctype/quotation/quotation.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:08", 
   "docstatus": 0, 
-  "modified": "2013-06-05 19:07:51", 
+  "modified": "2013-06-19 15:55:15", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -223,7 +223,7 @@
   "label": "Order Type", 
   "oldfieldname": "order_type", 
   "oldfieldtype": "Select", 
-  "options": "\nSales\nMaintenance", 
+  "options": "\nSales\nMaintenance\nShopping Cart", 
   "print_hide": 1, 
   "read_only": 0, 
   "reqd": 1, 
diff --git a/selling/utils.py b/selling/utils.py
index 61eab59..bd04db5 100644
--- a/selling/utils.py
+++ b/selling/utils.py
@@ -134,7 +134,7 @@
 	base_ref_rate = item_bean.doclist.get({
 		"parentfield": "ref_rate_details",
 		"price_list_name": args.price_list_name, 
-		"price_list_currency": args.price_list_currency,
+		"ref_currency": args.price_list_currency,
 		"buying_or_selling": "Selling"})
 	
 	if not base_ref_rate:
diff --git a/setup/doctype/price_list/price_list.py b/setup/doctype/price_list/price_list.py
index c4feb60..e6e7b7f 100644
--- a/setup/doctype/price_list/price_list.py
+++ b/setup/doctype/price_list/price_list.py
@@ -33,6 +33,25 @@
 		if self.doc.buying_or_selling not in ["Buying", "Selling"]:
 			msgprint(_(self.meta.get_label("buying_or_selling")) + " " + _("must be one of") + " " +
 				comma_or(["Buying", "Selling"]), raise_exception=True)
+				
+		self.validate_use_for_website()
+		
+	def validate_use_for_website(self):
+		if self.doc.use_for_website:
+			if self.doc.valid_for_all_countries:
+				if webnotes.conn.sql("""select name from `tabPrice List` where use_for_website=1
+					and valid_for_all_countries=1 and name!=%s""", self.doc.name):
+						webnotes.msgprint(_("Error: Another Price List already exists that is used for website and is valid for all countries."), 
+							raise_exception=True)
+				
+			elif self.doclist.get({"parentfield": "valid_for_countries"}):
+				for d in self.doclist.get({"parentfield": "valid_for_countries"}):
+					if webnotes.conn.sql("""select country from `tabPrice List Country` plc, `tabPrice List` pl
+						where plc.parent=pl.name and pl.use_for_website=1 and 
+						ifnull(valid_for_all_countries, 0)=0 and country=%s and pl.name!=%s""", 
+						(d.country, self.doc.name)):
+							webnotes.msgprint(_("Error: Another Price List already exists that is used for website and is valid for country") 
+								+ ": " + d.country, raise_exception=True)
 	
 	def on_trash(self):
 		webnotes.conn.sql("""delete from `tabItem Price` where price_list_name = %s""", 
diff --git a/setup/doctype/price_list/price_list.txt b/setup/doctype/price_list/price_list.txt
index daffece..8115f3d 100644
--- a/setup/doctype/price_list/price_list.txt
+++ b/setup/doctype/price_list/price_list.txt
@@ -2,13 +2,13 @@
  {
   "creation": "2013-01-25 11:35:09", 
   "docstatus": 0, 
-  "modified": "2013-06-14 16:07:25", 
+  "modified": "2013-06-19 15:24:23", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
   "allow_attach": 0, 
-  "allow_copy": 1, 
+  "allow_copy": 0, 
   "allow_email": 1, 
   "allow_print": 1, 
   "autoname": "field:price_list_name", 
diff --git a/website/css/website.css b/website/css/website.css
index 7efceb2..737d3d0 100644
--- a/website/css/website.css
+++ b/website/css/website.css
@@ -117,3 +117,13 @@
   margin-top: -10px;
   margin-left: -10px;
 }
+
+.hidden-sm-inline {
+	display: none;
+}
+
+@media (min-width: 768px) {
+	.hidden-sm-inline {
+		display: inline;
+	}
+}
\ No newline at end of file
diff --git a/website/doctype/shopping_cart_settings/__init__.py b/website/doctype/shopping_cart_settings/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/website/doctype/shopping_cart_settings/__init__.py
diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.py b/website/doctype/shopping_cart_settings/shopping_cart_settings.py
new file mode 100644
index 0000000..928aa9f
--- /dev/null
+++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.py
@@ -0,0 +1,8 @@
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+class DocType:
+	def __init__(self, d, dl):
+		self.doc, self.doclist = d, dl
\ No newline at end of file
diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.txt b/website/doctype/shopping_cart_settings/shopping_cart_settings.txt
new file mode 100644
index 0000000..627c127
--- /dev/null
+++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.txt
@@ -0,0 +1,51 @@
+[
+ {
+  "creation": "2013-06-19 15:57:32", 
+  "docstatus": 0, 
+  "modified": "2013-06-19 16:01:25", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "description": "Default settings for Shopping Cart", 
+  "doctype": "DocType", 
+  "issingle": 1, 
+  "module": "Website", 
+  "name": "__common__"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "territory", 
+  "fieldtype": "Link", 
+  "label": "Default Territory", 
+  "name": "__common__", 
+  "options": "Territory", 
+  "parent": "Shopping Cart Settings", 
+  "parentfield": "fields", 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "reqd": 1
+ }, 
+ {
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "name": "__common__", 
+  "parent": "Shopping Cart Settings", 
+  "parentfield": "permissions", 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "read": 1, 
+  "role": "Website Manager", 
+  "write": 1
+ }, 
+ {
+  "doctype": "DocType", 
+  "name": "Shopping Cart Settings"
+ }, 
+ {
+  "doctype": "DocField"
+ }, 
+ {
+  "doctype": "DocPerm"
+ }
+]
\ No newline at end of file
diff --git a/website/helpers/cart.py b/website/helpers/cart.py
index b62e0bb..a24afb5 100644
--- a/website/helpers/cart.py
+++ b/website/helpers/cart.py
@@ -3,16 +3,16 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes import _, msgprint
 import webnotes.defaults
-from webnotes.utils import today, get_fullname
+from webnotes.utils import cint, get_fullname, fmt_money
 
 class WebsitePriceListMissingError(webnotes.ValidationError): pass
 
 @webnotes.whitelist()
-def update_cart(item_code, qty):
+def update_cart(item_code, qty, with_doclist=0):
 	quotation = _get_cart_quotation()
 	
+	qty = cint(qty)
 	if qty == 0:
 		quotation.set_doclist(quotation.doclist.get({"item_code": ["!=", item_code]}))
 	else:
@@ -30,7 +30,10 @@
 	quotation.ignore_permissions = True
 	quotation.save()
 	
-	return quotation.doc.name
+	if with_doclist:
+		return decorate_quotation_doclist(quotation.doclist)
+	else:
+		return quotation.doc.name
 	
 def get_lead_or_customer():
 	customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, "customer")
@@ -45,6 +48,8 @@
 			"doctype": "Lead",
 			"email_id": webnotes.session.user,
 			"lead_name": get_fullname(webnotes.session.user),
+			"territory": webnotes.conn.get_value("Shopping Cart Settings", None, "territory") or \
+				"All Territories",
 			"status": "Open" # TODO: set something better???
 		})
 		lead_bean.ignore_permissions = True
@@ -55,8 +60,18 @@
 
 @webnotes.whitelist()
 def get_cart_quotation():
-	return [d.fields for d in _get_cart_quotation(get_lead_or_customer()).doclist]
+	doclist = _get_cart_quotation(get_lead_or_customer()).doclist
+	return decorate_quotation_doclist(doclist)
 
+def decorate_quotation_doclist(doclist):
+	for d in doclist:
+		if d.item_code:
+			d.fields.update(webnotes.conn.get_value("Item", d.item_code, 
+				["website_image", "web_short_description", "page_name"], as_dict=True))
+			d.formatted_rate = fmt_money(d.export_rate, currency=doclist[0].currency)
+			d.formatted_amount = fmt_money(d.export_amount, currency=doclist[0].currency)
+
+	return [d.fields for d in doclist]
 
 def _get_cart_quotation(party=None):
 	if not party:
@@ -71,7 +86,7 @@
 		qbean = webnotes.bean({
 			"doctype": "Quotation",
 			"naming_series": "QTN-CART-",
-			"quotation_to": "Customer",
+			"quotation_to": party.doctype,
 			"company": webnotes.defaults.get_user_default("company"),
 			"order_type": "Shopping Cart",
 			"status": "Draft",
@@ -97,7 +112,8 @@
 		price_list_name = webnotes.conn.sql("""select parent 
 			from `tabPrice List Country` plc
 			where country=%s and exists (select name from `tabPrice List` pl
-				where use_for_website=1 and pl.name = plc.parent)""", country)
+				where use_for_website=1 and ifnull(valid_for_all_countries, 0)=0 and 
+				pl.name = plc.parent)""", country)
 	
 	if price_list_name:
 		price_list_name = price_list_name[0][0]
diff --git a/website/page/website_home/website_home.js b/website/page/website_home/website_home.js
index 71f2f4d..fb612df 100644
--- a/website/page/website_home/website_home.js
+++ b/website/page/website_home/website_home.js
@@ -63,6 +63,12 @@
 				"description":wn._("Setup of fonts and background."),
 				doctype:"Style Settings"
 			},
+			{
+				"route":"Form/Shopping Cart Settings",
+				"label":wn._("Shopping Cart Settings"),
+				"description":wn._("Setup of Shopping Cart."),
+				doctype:"Shopping Cart Settings"
+			},
 		]
 	},
 	{
diff --git a/website/templates/html/product_page.html b/website/templates/html/product_page.html
index 837b105..bf1ecc0 100644
--- a/website/templates/html/product_page.html
+++ b/website/templates/html/product_page.html
@@ -40,12 +40,14 @@
 						<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">Add to Cart</button>
+							<button class="btn btn-primary">
+								<i class="icon-shopping-cart"></i> Add to Cart</button>
 						</div>
 						<div id="item-update-cart" class="input-group col-lg-6" style="display: none;">
 							<input type="text">
 							<div class="input-group-btn">
-								<button class="btn btn-primary">Update</button>
+								<button class="btn btn-primary">
+									<i class="icon-shopping-cart"></i> Update</button>
 							</div>
 						</div>
 					</div>
diff --git a/website/templates/js/cart.js b/website/templates/js/cart.js
index 121ca6a..e4bd6b2 100644
--- a/website/templates/js/cart.js
+++ b/website/templates/js/cart.js
@@ -19,12 +19,10 @@
 $(document).ready(function() {
 	// make list of items in the cart
 	// wn.cart.render();
-	// wn.cart.bind_events();
+	wn.cart.bind_events();
 	wn.call({
+		type: "POST",
 		method: "website.helpers.cart.get_cart_quotation",
-		args: {
-			_type: "POST"
-		},
 		callback: function(r) {
 			console.log(r);
 			$("#cart-container").removeClass("hide");
@@ -36,11 +34,7 @@
 					wn.cart.show_error("Oops!", "Something went wrong.");
 				}
 			} else {
-				if(r.message[0].__islocal) {
-					wn.cart.show_error("Empty :-(", "Go ahead and add something to your cart.");
-				} else {
-					wn.cart.render(r.message);
-				}
+				wn.cart.render(r.message);
 			}
 			
 		}
@@ -54,19 +48,74 @@
 		$("#cart-container").html('<div class="well"><h4>' + title + '</h4> ' + text + '</div>');
 	},
 	
+	bind_events: function() {
+		// bind update button
+		$(document).on("click", ".item-update-cart button", function() {
+			console.log("click!");
+			var item_code = $(this).attr("data-item-code");
+			wn.cart.update_cart({
+				item_code: item_code,
+				qty: $('input[data-item-code="'+item_code+'"]').val(),
+				with_doclist: 1,
+				btn: this,
+				callback: function(r) {
+					if(!r.exc) {
+						wn.cart.render(r.message);
+						var $button = $('button[data-item-code="'+item_code+'"]').addClass("btn-success");
+						setTimeout(function() { $button.removeClass("btn-success"); }, 1000);
+					}
+				},
+			});
+		});
+	},
+	
 	render: function(doclist) {
-		return;
 		var $cart_wrapper = $("#cart-items").empty();
-		if(Object.keys(wn.cart.get_cart()).length) {
-			$('<div class="row">\
-				<div class="col col-lg-9 col-sm-9">\
-					<div class="row">\
-						<div class="col col-lg-3"></div>\
-						<div class="col col-lg-9"><strong>Item Details</strong></div>\
+		
+		if($.map(doclist, function(d) { return d.item_code || null;}).length===0) {
+			wn.cart.show_error("Empty :-(", "Go ahead and add something to your cart.");
+			return;
+		}
+		
+		$.each(doclist, function(i, doc) {
+			if(doc.doctype === "Quotation Item") {
+				doc.image_html = doc.image ?
+					'<div style="height: 120px; overflow: hidden;"><img src="' + doc.image + '" /></div>' :
+					'{% include "app/website/templates/html/product_missing_image.html" %}';
+					
+				if(!doc.web_short_description) doc.web_short_description = doc.description;
+					
+				$(repl('<div class="row">\
+					<div class="col col-lg-9 col-sm-9">\
+						<div class="row">\
+							<div class="col col-lg-3">%(image_html)s</div>\
+							<div class="col col-lg-9">\
+								<h4><a href="%(page_name)s">%(item_name)s</a></h4>\
+								<p>%(web_short_description)s</p>\
+							</div>\
+						</div>\
 					</div>\
-				</div>\
-				<div class="col col-lg-3 col-sm-3"><strong>Qty</strong></div>\
-			</div><hr>').appendTo($cart_wrapper);
+					<div class="col col-lg-3 col-sm-3">\
+						<div class="input-group item-update-cart">\
+							<input type="text" placeholder="Qty" value="%(qty)s" \
+								data-item-code="%(item_code)s">\
+							<div class="input-group-btn">\
+								<button class="btn btn-primary" data-item-code="%(item_code)s">\
+									<i class="icon-shopping-cart"></i>\
+									<span class="hidden-sm-inline"> Update</span></button>\
+							</div>\
+						</div>\
+						<p style="margin-top: 10px;">at %(formatted_rate)s</p>\
+						<small class="text-muted" style="margin-top: 10px;">= %(formatted_amount)s</small>\
+					</div>\
+				</div><hr>', doc)).appendTo($cart_wrapper);
+				
+			}
+		});
+		
+		return;
+		
+		if(Object.keys(wn.cart.get_cart()).length) {
 			
 			$.each(wn.cart.get_cart(), function(item_code, item) {
 				item.image_html = item.image ?
@@ -101,30 +150,30 @@
 		}
 	},
 	
-	bind_events: function() {
-		// on change of qty
-		$(".cart-input-qty").on("change", function on_change_of_qty() {
-			wn.cart.set_value_in_cart($(this).attr("item_code"), "qty", $(this).val());
-		});
-		
-		// shopping cart button
-		$(".checkout-btn").on("click", function() {
-			console.log("checkout!");
-			console.log(wn.cart.get_cart());
-			
-			var user_is_logged_in = getCookie("full_name");
-			if(user_is_logged_in) {
-				wn.call({
-					method: "website.helpers.cart.checkout",
-					args: {cart: wn.cart.get_cart()},
-					btn: this,
-					callback: function(r) {
-						console.log(r);
-					}
-				});
-			} else {
-				window.location.href = "login?from=cart";
-			}
-		});
-	}
+	// bind_events: function() {
+	// 	// on change of qty
+	// 	$(".cart-input-qty").on("change", function on_change_of_qty() {
+	// 		wn.cart.set_value_in_cart($(this).attr("item_code"), "qty", $(this).val());
+	// 	});
+	// 	
+	// 	// shopping cart button
+	// 	$(".checkout-btn").on("click", function() {
+	// 		console.log("checkout!");
+	// 		console.log(wn.cart.get_cart());
+	// 		
+	// 		var user_is_logged_in = getCookie("full_name");
+	// 		if(user_is_logged_in) {
+	// 			wn.call({
+	// 				method: "website.helpers.cart.checkout",
+	// 				args: {cart: wn.cart.get_cart()},
+	// 				btn: this,
+	// 				callback: function(r) {
+	// 					console.log(r);
+	// 				}
+	// 			});
+	// 		} else {
+	// 			window.location.href = "login?from=cart";
+	// 		}
+	// 	});
+	// }
 });
\ No newline at end of file
diff --git a/website/templates/pages/cart.html b/website/templates/pages/cart.html
index ada1577..2619dec 100644
--- a/website/templates/pages/cart.html
+++ b/website/templates/pages/cart.html
@@ -8,7 +8,7 @@
 
 {% block content %}
 <div class="col col-lg-12">
-	<h2>Shopping Cart</h2>
+	<h2><i class="icon-shopping-cart"></i> Shopping Cart</h2>
 	<div class="progress progress-striped active">
 		<div class="progress-bar progress-bar-info" style="width: 100%;"></div>
 	</div>
@@ -16,6 +16,15 @@
 		<button class="btn btn-success pull-right" type="button">Place Order</button>
 		<div class="clearfix"></div>
 		<hr>
+		<div class="row">
+			<div class="col col-lg-9 col-sm-9">
+				<div class="row">
+					<div class="col col-lg-3"></div>
+					<div class="col col-lg-9"><strong>Item Details</strong></div>
+				</div>
+			</div>
+			<div class="col col-lg-3 col-sm-3"><strong>Qty</strong></div>
+		</div><hr>
 		<div id="cart-items">
 		</div>
 		<hr>