Shopping cart and dropdown cart update
diff --git a/erpnext/public/css/website.css b/erpnext/public/css/website.css
index db8f2fc..065e281 100644
--- a/erpnext/public/css/website.css
+++ b/erpnext/public/css/website.css
@@ -130,6 +130,9 @@
.cart-container {
margin: 50px 0px;
}
+.cart-container .checkout {
+ margin-bottom: 15px;
+}
.cart-container .cart-item-header .h6 {
padding: 7px 15px;
}
@@ -163,12 +166,12 @@
.cart-container .cart-addresses {
margin-top: 50px;
}
-.cart-items .cart-dropdown,
+.cart-items-dropdown .cart-dropdown,
.item_name_dropdown {
display: none;
}
.cart-dropdown-container {
- width: 320px;
+ width: 400px;
padding: 15px;
}
.cart-dropdown-container .item-price {
@@ -178,7 +181,11 @@
.cart-dropdown-container .cart-item-header {
border-bottom: 1px solid #d1d8dd;
}
-.cart-dropdown-container .cart-items .cart-dropdown {
+.cart-dropdown-container .cart-items-dropdown {
+ max-height: 350px;
+ overflow: auto;
+}
+.cart-dropdown-container .cart-items-dropdown .cart-dropdown {
display: block;
margin-top: 15px;
}
@@ -196,6 +203,16 @@
.cart-dropdown-container .col-name-description {
margin-bottom: 8px;
}
+.number-spinner {
+ width: 100px;
+ margin-top: 5px;
+}
+.cart-btn {
+ border-color: #ccc;
+}
+.cart-qty {
+ text-align: center;
+}
.product-list-link .row {
border-bottom: 1px solid #EBEFF2;
}
diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js
index 40f5b98..6cf255d 100644
--- a/erpnext/public/js/shopping_cart.js
+++ b/erpnext/public/js/shopping_cart.js
@@ -20,6 +20,7 @@
callback: function(r) {
if (r.message) {
$('.shopping-cart-menu').html(r.message);
+ $('#cart-overlay').addClass('show');
}
}
});
diff --git a/erpnext/public/less/website.less b/erpnext/public/less/website.less
index 5d89265..4aa3940 100644
--- a/erpnext/public/less/website.less
+++ b/erpnext/public/less/website.less
@@ -165,6 +165,10 @@
.cart-container {
margin: 50px 0px;
+
+ .checkout {
+ margin-bottom:15px;
+ }
.cart-item-header .h6 {
padding: 7px 15px;
@@ -210,15 +214,16 @@
}
}
-.cart-items .cart-dropdown,
+.cart-items-dropdown .cart-dropdown,
.item_name_dropdown {
- display:none;
+ display: none;
}
-.cart-dropdown-container {
- width: 320px;
- padding: 15px;
+.cart-dropdown-container {
+ width: 400px;
+ padding: 15px;
+
.item-price {
display: block !important;
padding-bottom: 10px;
@@ -227,8 +232,13 @@
.cart-item-header {
border-bottom: 1px solid #d1d8dd;
}
-
- .cart-items .cart-dropdown {
+
+ .cart-items-dropdown {
+ max-height: 350px;
+ overflow: auto;
+ }
+
+ .cart-items-dropdown .cart-dropdown {
display:block;
margin-top:15px;
}
@@ -249,7 +259,18 @@
.col-name-description {
margin-bottom:8px;
}
+}
+.number-spinner {
+ width:100px;
+ margin-top:5px;
+}
+
+.cart-btn {
+ border-color: #ccc;
+}
+.cart-qty {
+ text-align:center;
}
.product-list-link {
@@ -306,5 +327,4 @@
.product-image-wrapper {
padding-bottom: 40px;
-}
-
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item_price/item_price.py b/erpnext/stock/doctype/item_price/item_price.py
index 6025ef7..43390be 100644
--- a/erpnext/stock/doctype/item_price/item_price.py
+++ b/erpnext/stock/doctype/item_price/item_price.py
@@ -13,7 +13,7 @@
def validate(self):
self.validate_item()
self.validate_price_list()
- self.check_duplicate_item()
+ # self.check_duplicate_item()
self.update_price_list_details()
self.update_item_details()
@@ -25,13 +25,13 @@
enabled = frappe.db.get_value("Price List", self.price_list, "enabled")
if not enabled:
throw(_("Price List {0} is disabled").format(self.price_list))
-
- def check_duplicate_item(self):
- if frappe.db.sql("""select name from `tabItem Price`
- where item_code=%s and price_list=%s and name!=%s""", (self.item_code, self.price_list, self.name)):
-
- frappe.throw(_("Item {0} appears multiple times in Price List {1}").format(self.item_code, self.price_list),
- ItemPriceDuplicateItem)
+ #
+ # def check_duplicate_item(self):
+ # if frappe.db.sql("""select name from `tabItem Price`
+ # where item_code=%s and price_list=%s and name!=%s""", (self.item_code, self.price_list, self.name)):
+ #
+ # frappe.throw(_("Item {0} appears multiple times in Price List {1}").format(self.item_code, self.price_list),
+ # ItemPriceDuplicateItem)
def update_price_list_details(self):
self.buying, self.selling, self.currency = \
diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js
index d56721d..cbb9390 100644
--- a/erpnext/templates/includes/cart.js
+++ b/erpnext/templates/includes/cart.js
@@ -70,6 +70,38 @@
},
});
});
+
+ $(".cart-items").on('click', '.number-spinner button', function () {
+ var btn = $(this),
+ oldValue = btn.closest('.number-spinner').find('input').val().trim(),
+ newVal = 0;
+
+ if (btn.attr('data-dir') == 'up') {
+ console.log(oldValue);
+ newVal = parseInt(oldValue) + 1;
+ } else {
+ if (oldValue > 1) {
+ newVal = parseInt(oldValue) - 1;
+ }
+ }
+ btn.closest('.number-spinner').find('input').val(newVal);
+ var item_code = btn.closest('.number-spinner').find('input').attr("data-item-code");
+ frappe.freeze();
+ shopping_cart.update_cart({
+ item_code: item_code,
+ qty: newVal,
+ with_items: 1,
+ btn: this,
+ callback: function(r) {
+ frappe.unfreeze();
+ if(!r.exc) {
+ $(".cart-items").html(r.message.items);
+ $(".cart-tax-items").html(r.message.taxes);
+ $(".cart-icon").hide();
+ }
+ },
+ });
+ });
},
render_tax_row: function($cart_taxes, doc, shipping_rules) {
diff --git a/erpnext/templates/includes/cart/cart_dropdown.html b/erpnext/templates/includes/cart/cart_dropdown.html
index 18148ad..071b281 100644
--- a/erpnext/templates/includes/cart/cart_dropdown.html
+++ b/erpnext/templates/includes/cart/cart_dropdown.html
@@ -11,8 +11,8 @@
</div>
{% if doc.items %}
- <div class="cart-items">
- {% include "templates/includes/cart/cart_items.html" %}
+ <div class="cart-items-dropdown">
+ {% include "templates/includes/cart/cart_items_dropdown.html" %}
</div>
<div class="checkout-btn">
<a href="/cart" class="btn btn-block btn-primary">{{ _("Checkout") }}</a>
diff --git a/erpnext/templates/includes/cart/cart_items.html b/erpnext/templates/includes/cart/cart_items.html
index 976467d..b2e6858 100644
--- a/erpnext/templates/includes/cart/cart_items.html
+++ b/erpnext/templates/includes/cart/cart_items.html
@@ -1,4 +1,5 @@
{% from "erpnext/templates/includes/order/order_macros.html" import item_name_and_description %}
+{% from "erpnext/templates/includes/order/order_macros.html" import item_name_and_description_cart %}
{% for d in doc.items %}
<div class="row checkout">
@@ -6,10 +7,21 @@
{{ item_name_and_description(d) }}
</div>
<div class="col-sm-2 col-xs-3 text-right col-qty">
- <span style="max-width: 50px; display: inline-block">
+ <span style="display: inline-block">
+ <div class="input-group number-spinner">
+ <span class="input-group-btn">
+ <button class="btn btn-default cart-btn" data-dir="dwn">
+ –</button>
+ </span>
<input class="form-control text-right cart-qty"
value = "{{ d.get_formatted('qty') }}"
- data-item-code="{{ d.item_code }}"></span>
+ data-item-code="{{ d.item_code }}">
+ <span class="input-group-btn">
+ <button class="btn btn-default cart-btn" data-dir="up" style="margin-left:-2px;">
+ +</button>
+ </span>
+ </div>
+ </span>
</div>
<div class="col-sm-2 col-xs-3 text-right col-amount">
{{ d.get_formatted("amount") }}
@@ -17,14 +29,4 @@
_("Rate: {0}").format(d.get_formatted("rate")) }}</p>
</div>
</div>
-
-<div class="row cart-dropdown">
- <div class="col-sm-8 col-xs-8 col-name-description">
- {{ item_name_and_description(d) }}
- </div>
- <div class="col-sm-4 col-xs-4 text-right col-amount">
- {{ d.get_formatted("amount") }}
-
- </div>
-</div>
{% endfor %}
\ No newline at end of file
diff --git a/erpnext/templates/includes/cart/cart_items_dropdown.html b/erpnext/templates/includes/cart/cart_items_dropdown.html
new file mode 100644
index 0000000..9a3dbf8
--- /dev/null
+++ b/erpnext/templates/includes/cart/cart_items_dropdown.html
@@ -0,0 +1,13 @@
+{% from "erpnext/templates/includes/order/order_macros.html" import item_name_and_description_cart %}
+
+{% for d in doc.items %}
+<div class="row cart-dropdown">
+ <div class="col-sm-8 col-xs-8 col-name-description">
+ {{ item_name_and_description_cart(d) }}
+ </div>
+ <div class="col-sm-4 col-xs-4 text-right col-amount">
+ {{ d.get_formatted("amount") }}
+
+ </div>
+</div>
+{% endfor %}
\ No newline at end of file
diff --git a/erpnext/templates/includes/navbar/navbar_items.html b/erpnext/templates/includes/navbar/navbar_items.html
index 9cdbd98..c7af2fd 100644
--- a/erpnext/templates/includes/navbar/navbar_items.html
+++ b/erpnext/templates/includes/navbar/navbar_items.html
@@ -1,12 +1,12 @@
{% extends 'frappe/templates/includes/navbar/navbar_items.html' %}
{% block navbar_right_extension %}
- <li class="dropdown shopping-cart">
+ <li class="shopping-cart">
<div class="cart-icon small">
<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="navLogin">
Cart <span class="badge-wrapper" id="cart-count"></span>
</a>
- <div class="dropdown-menu shopping-cart-menu"></div>
+ <div id="cart-overlay" class="dropdown-menu shopping-cart-menu"></div>
</div>
</li>
{% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/includes/order/order_macros.html b/erpnext/templates/includes/order/order_macros.html
index 3f8affe..e56f88b 100644
--- a/erpnext/templates/includes/order/order_macros.html
+++ b/erpnext/templates/includes/order/order_macros.html
@@ -12,15 +12,50 @@
<div class="text-muted small item-description">{{ d.description }}</div>
</div>
</div>
-
+{% endmacro %}
+{% macro item_name_and_description_cart(d) %}
<div class="row item_name_dropdown">
<div class="col-xs-4 col-sm-4 order-image-col">
<div class="order-image">
- <span class="cart-count-badge pull-right small"> {{ d.get_formatted('qty') }} </span>{{ product_image_square(d.image) }}
+ {{ product_image_square(d.image) }}
</div>
</div>
<div class="col-xs-8 col-sm-8">
- {{ d.item_code }}
+ {{ d.item_code|truncate(25) }}
+ <div class="input-group number-spinner">
+ <span class="input-group-btn">
+ <button class="btn btn-default cart-btn" data-dir="dwn">
+ –</button>
+ </span>
+ <input class="form-control text-right cart-qty"
+ value = "{{ d.get_formatted('qty') }}"
+ data-item-code="{{ d.item_code }}">
+ <span class="input-group-btn">
+ <button class="btn btn-default cart-btn" data-dir="up">
+ +</button>
+ </span>
+ </div>
</div>
</div>
-{% endmacro %}
\ No newline at end of file
+{% endmacro %}
+
+<script>
+frappe.ready(function() {
+ $(".cart-items-dropdown").on('click', '.number-spinner button', function () {
+ var btn = $(this),
+ oldValue = btn.closest('.number-spinner').find('input').val().trim(),
+ newVal = 0;
+
+ if (btn.attr('data-dir') == 'up') {
+ newVal = parseInt(oldValue) + 1;
+ } else {
+ if (oldValue > 1) {
+ newVal = parseInt(oldValue) - 1;
+ } else {
+ newVal = 1;
+ }
+ }
+ btn.closest('.number-spinner').find('input').val(newVal);
+});
+}
+</script>
\ No newline at end of file
diff --git a/erpnext/templates/pages/cart.html b/erpnext/templates/pages/cart.html
index 35e4989..7f6bf01 100644
--- a/erpnext/templates/pages/cart.html
+++ b/erpnext/templates/pages/cart.html
@@ -30,7 +30,7 @@
<div class="col-sm-8 col-xs-6 h6 text-uppercase">
{{ _("Item") }}
</div>
- <div class="col-sm-2 col-xs-3 text-right h6 text-uppercase">
+ <div class="col-sm-2 col-xs-3 text-center h6 text-uppercase">
{{ _("Qty") }}
</div>
<div class="col-sm-2 col-xs-3 text-right h6 text-uppercase">