Fix and improve shopping cart (#9348)

* Fix and improve shopping cart

* Update shopping_cart.js

* Update shopping_cart.js
This commit is contained in:
Britlog
2017-06-20 09:21:32 +02:00
committed by Rushabh Mehta
parent 22773a29f7
commit faf75c4ddd
6 changed files with 25 additions and 14 deletions

View File

@@ -6,7 +6,7 @@ frappe.provide("erpnext.shopping_cart");
var shopping_cart = erpnext.shopping_cart; var shopping_cart = erpnext.shopping_cart;
frappe.ready(function() { frappe.ready(function() {
var full_name = frappe.session.user_fullname; var full_name = frappe.session && frappe.session.user_fullname;
// update user // update user
if(full_name) { if(full_name) {
$('.navbar li[data-label="User"] a') $('.navbar li[data-label="User"] a')
@@ -35,9 +35,8 @@ $.extend(shopping_cart, {
}); });
}, },
update_cart: function(opts) { update_cart: function(opts) {
var full_name = frappe.session.user_fullname; if(fraappe.session.user==="Guest") {
if(!full_name || full_name==="Guest") {
if(localStorage) { if(localStorage) {
localStorage.setItem("last_visited", window.location.pathname); localStorage.setItem("last_visited", window.location.pathname);
} }

View File

@@ -100,7 +100,7 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
or name like %(search)s)""" or name like %(search)s)"""
search = "%" + cstr(search) + "%" search = "%" + cstr(search) + "%"
query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit) query += """order by weightage desc, item_name, modified desc limit %s, %s""" % (start, limit)
data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1) data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)

View File

@@ -75,9 +75,15 @@ def place_order():
def update_cart(item_code, qty, with_items=False): def update_cart(item_code, qty, with_items=False):
quotation = _get_cart_quotation() quotation = _get_cart_quotation()
empty_card = False
qty = flt(qty) qty = flt(qty)
if qty == 0: if qty == 0:
quotation.set("items", quotation.get("items", {"item_code": ["!=", item_code]})) quotation_items = quotation.get("items", {"item_code": ["!=", item_code]})
if quotation_items:
quotation.set("items", quotation_items)
else:
empty_card = True
else: else:
quotation_items = quotation.get("items", {"item_code": item_code}) quotation_items = quotation.get("items", {"item_code": item_code})
if not quotation_items: if not quotation_items:
@@ -92,7 +98,11 @@ def update_cart(item_code, qty, with_items=False):
apply_cart_settings(quotation=quotation) apply_cart_settings(quotation=quotation)
quotation.flags.ignore_permissions = True quotation.flags.ignore_permissions = True
quotation.save() if not empty_card:
quotation.save()
else:
quotation.delete()
quotation = None
set_cart_count(quotation) set_cart_count(quotation)

View File

@@ -6,11 +6,13 @@
</div> </div>
{% endif %} {% endif %}
{% for d in doc.taxes %} {% for d in doc.taxes %}
{% if d.base_tax_amount > 0 %}
<div class="row tax-row"> <div class="row tax-row">
<div class="col-xs-8 text-right">{{ d.description }}</div> <div class="col-xs-8 text-right">{{ d.description }}</div>
<div class="col-xs-4 text-right"> <div class="col-xs-4 text-right">
{{ d.get_formatted("base_tax_amount") }}</div> {{ d.get_formatted("base_tax_amount") }}</div>
</div> </div>
{% endif %}
{% endfor %} {% endfor %}
<div class="row tax-grand-total-row"> <div class="row tax-grand-total-row">
<div class="col-xs-8 text-right text-uppercase h6 text-muted">{{ _("Grand Total") }}</div> <div class="col-xs-8 text-right text-uppercase h6 text-muted">{{ _("Grand Total") }}</div>

View File

@@ -39,10 +39,10 @@ window.render_product_list = function(data) {
if(data.length < 10) { if(data.length < 10) {
if(!table) { if(!table) {
$(".more-btn") $(".more-btn")
.replaceWith("<div class='alert alert-warning'>No products found.</div>"); .replaceWith("<div class='alert alert-warning'>{{ _("No products found.") }}</div>");
} else { } else {
$(".more-btn") $(".more-btn")
.replaceWith("<div class='text-muted'>Nothing more to show.</div>"); .replaceWith("<div class='text-muted'>{{ _("Nothing more to show.") }}</div>");
} }
} else { } else {
$(".more-btn").toggle(true) $(".more-btn").toggle(true)

View File

@@ -15,18 +15,18 @@ frappe.ready(function() {
$(".item-cart").toggleClass("hide", (!!!r.message.price || !!!r.message.in_stock)); $(".item-cart").toggleClass("hide", (!!!r.message.price || !!!r.message.in_stock));
if(r.message && r.message.price) { if(r.message && r.message.price) {
$(".item-price") $(".item-price")
.html(r.message.price.formatted_price + " per " + r.message.uom); .html(r.message.price.formatted_price + " {{ _("per") }} " + r.message.uom);
if(r.message.in_stock==0) { if(r.message.in_stock==0) {
$(".item-stock").html("<div style='color: red'> <i class='fa fa-close'></i> Not in stock</div>"); $(".item-stock").html("<div style='color: red'> <i class='fa fa-close'></i> {{ _("Not in stock") }}</div>");
} }
else if(r.message.in_stock==1) { else if(r.message.in_stock==1) {
var qty_display = "In stock"; var qty_display = "{{ _("In stock") }}";
if (r.message.show_stock_qty) { if (r.message.show_stock_qty) {
qty_display = "Available ("+r.message.stock_qty+ " in stock)"; qty_display += " ("+r.message.stock_qty+")";
} }
$(".item-stock").html("<div style='color: green'>\ $(".item-stock").html("<div style='color: green'>\
<i class='fa fa-check'></i> "+__(qty_display)+"</div>"); <i class='fa fa-check'></i> "+qty_display+"</div>");
} }
if(r.message.qty) { if(r.message.qty) {