[enhancement] add variants in website
diff --git a/erpnext/templates/generators/item.html b/erpnext/templates/generators/item.html
index af4a795..30ccbce 100644
--- a/erpnext/templates/generators/item.html
+++ b/erpnext/templates/generators/item.html
@@ -30,6 +30,22 @@
 					<h4 class="item-price" itemprop="price"></h4>
 					<div class="item-stock" itemprop="availablity"></div>
                     <div class="item-cart hide">
+                        {% if has_variants %}
+                        {% for d in attributes %}
+                        <div class="item-view-attribute"
+                                style="margin-bottom: 10px;">
+                            <h6 class="text-muted">{{ _(d.attribute) }}</h6>
+                            <select class="form-control"
+                                style="max-width: 140px"
+                                data-attribute="{{ d.attribute }}">
+                            {% for value in attribute_values[d.attribute] %}
+                            <option value="{{ value }}">{{ _(value) }}</option>
+                            {% endfor %}
+                            </select>
+                        </div>
+                        {% endfor %}
+                        {% endif %}
+                        </select>
     					<div id="item-add-to-cart">
     						<button class="btn btn-primary btn-sm">
     							{{ _("Add to Cart") }}</button>
@@ -76,13 +92,8 @@
 <script>
 	{% include "templates/includes/product_page.js" %}
 
-	$(function() {
-		if(window.logged_in && getCookie("system_user")==="yes") {
-			frappe.has_permission("Item", "{{ name }}", "write", function(r) {
-				frappe.require("/assets/frappe/js/frappe/website/editable.js");
-				frappe.make_editable($('[itemprop="description"]'), "Item", "{{ name }}", "web_long_description");
-			});
-		}
-	});
+    {% if variant_info %}
+    window.variant_info = {{ variant_info }};
+    {% endif %}
 </script>
 {% endblock %}
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index 98331a4..7468ffe 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -2,7 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.ready(function() {
-	var item_code = $('[itemscope] [itemprop="productID"]').text().trim();
+	window.item_code = $('[itemscope] [itemprop="productID"]').text().trim();
 	var qty = 0;
 
 	frappe.call({
@@ -12,7 +12,6 @@
 			item_code: "{{ name }}"
 		},
 		callback: function(r) {
-			console.log(r.message);
 			$(".item-cart").toggleClass("hide", !!!r.message.price);
 			if(r.message && r.message.price) {
 				$(".item-price")
@@ -38,7 +37,7 @@
 
 	$("#item-add-to-cart button").on("click", function() {
 		shopping_cart.update_cart({
-			item_code: item_code,
+			item_code: get_item_code(),
 			qty: 1,
 			callback: function(r) {
 				if(!r.exc) {
@@ -52,7 +51,7 @@
 
 	$("#item-update-cart button").on("click", function() {
 		shopping_cart.update_cart({
-			item_code: item_code,
+			item_code: get_item_code(),
 			qty: $("#item-update-cart input").val(),
 			btn: this,
 			callback: function(r) {
@@ -64,11 +63,6 @@
 			},
 		});
 	});
-
-	if(localStorage && localStorage.getItem("pending_add_to_cart") && full_name) {
-		localStorage.removeItem("pending_add_to_cart");
-		$("#item-add-to-cart button").trigger("click");
-	}
 });
 
 var toggle_update_cart = function(qty) {
@@ -77,3 +71,29 @@
 		.toggle(qty ? true : false)
 		.find("input").val(qty);
 }
+
+function get_item_code() {
+	if(window.variant_info) {
+		attributes = {};
+		$('[itemscope]').find(".item-view-attribute select").each(function() {
+			attributes[$(this).attr('data-attribute')] = $(this).val();
+		});
+		for(var i in variant_info) {
+			var variant = variant_info[i];
+			var match = true;
+			for(var j in variant.attributes) {
+				if(attributes[variant.attributes[j].attribute]
+					!= variant.attributes[j].attribute_value) {
+						match = false;
+						break;
+				}
+			}
+			if(match) {
+				return variant.name;
+			}
+		}
+		throw "Unable to match variant";
+	} else {
+		return item_code;
+	}
+}
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index f4c4534..c0a020b 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -14,7 +14,7 @@
 	# base query
 	query = """select name, item_name, page_name, website_image, item_group,
 			web_long_description as website_description, parent_website_route
-		from `tabItem` where show_in_website = 1"""
+		from `tabItem` where show_in_website = 1 and (variant_of is null or variant_of = '')"""
 
 	# search term condition
 	if search: