[fix] Patch template item to be shown in website, show variant's description and price on change of attribute
diff --git a/erpnext/templates/generators/item.html b/erpnext/templates/generators/item.html
index f24b1a6..ccb992b 100644
--- a/erpnext/templates/generators/item.html
+++ b/erpnext/templates/generators/item.html
@@ -38,8 +38,11 @@
<select class="form-control"
style="max-width: 140px"
data-attribute="{{ d.attribute }}">
- {% for value in attribute_values[d.attribute] %}
- <option value="{{ value }}">{{ _(value) }}</option>
+ {% for value in attribute_values[d.attribute] %}
+ <option value="{{ value }}"
+ {% if selected_attributes and selected_attributes[d.attribute]==value -%} selected {%- endif %}>
+ {{ _(value) }}
+ </option>
{% endfor %}
</select>
</div>
@@ -71,13 +74,13 @@
</div>
</div>
</div>
- {% if doc.get({"doctype":"Item Website Specification"}) -%}
- <div class="row" style="margin-top: 20px">
+ {% if website_specifications -%}
+ <div class="row item-website-specification" style="margin-top: 20px">
<div class="col-md-12">
<h4>{{ _("Specifications") }}</h4>
+
<table class="table table-bordered" style="width: 100%">
- {% for d in doc.get(
- {"doctype":"Item Website Specification"}) -%}
+ {% for d in website_specifications -%}
<tr>
<td style="width: 30%;">{{ d.label }}</td>
<td>{{ d.description }}</td>
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index 7468ffe..2345de4 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -9,7 +9,7 @@
type: "POST",
method: "erpnext.shopping_cart.product.get_product_info",
args: {
- item_code: "{{ name }}"
+ item_code: get_item_code()
},
callback: function(r) {
$(".item-cart").toggleClass("hide", !!!r.message.price);
@@ -63,6 +63,15 @@
},
});
});
+
+ $("[itemscope] .item-view-attribute select").on("change", function() {
+ var item_code = encodeURIComponent(get_item_code());
+ if (window.location.search.indexOf(item_code)!==-1) {
+ return;
+ }
+
+ frappe.load_via_ajax(window.location.pathname + "?variant=" + item_code);
+ });
});
var toggle_update_cart = function(qty) {