Fix and improve shopping cart (#9348)
* Fix and improve shopping cart * Update shopping_cart.js * Update shopping_cart.js
This commit is contained in:
parent
22773a29f7
commit
faf75c4ddd
@ -6,7 +6,7 @@ frappe.provide("erpnext.shopping_cart");
|
||||
var shopping_cart = erpnext.shopping_cart;
|
||||
|
||||
frappe.ready(function() {
|
||||
var full_name = frappe.session.user_fullname;
|
||||
var full_name = frappe.session && frappe.session.user_fullname;
|
||||
// update user
|
||||
if(full_name) {
|
||||
$('.navbar li[data-label="User"] a')
|
||||
@ -35,9 +35,8 @@ $.extend(shopping_cart, {
|
||||
});
|
||||
},
|
||||
|
||||
update_cart: function(opts) {
|
||||
var full_name = frappe.session.user_fullname;
|
||||
if(!full_name || full_name==="Guest") {
|
||||
update_cart: function(opts) {
|
||||
if(fraappe.session.user==="Guest") {
|
||||
if(localStorage) {
|
||||
localStorage.setItem("last_visited", window.location.pathname);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
|
||||
or name like %(search)s)"""
|
||||
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)
|
||||
|
||||
|
@ -75,9 +75,15 @@ def place_order():
|
||||
def update_cart(item_code, qty, with_items=False):
|
||||
quotation = _get_cart_quotation()
|
||||
|
||||
empty_card = False
|
||||
qty = flt(qty)
|
||||
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:
|
||||
quotation_items = quotation.get("items", {"item_code": item_code})
|
||||
if not quotation_items:
|
||||
@ -92,7 +98,11 @@ def update_cart(item_code, qty, with_items=False):
|
||||
apply_cart_settings(quotation=quotation)
|
||||
|
||||
quotation.flags.ignore_permissions = True
|
||||
quotation.save()
|
||||
if not empty_card:
|
||||
quotation.save()
|
||||
else:
|
||||
quotation.delete()
|
||||
quotation = None
|
||||
|
||||
set_cart_count(quotation)
|
||||
|
||||
|
@ -6,11 +6,13 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for d in doc.taxes %}
|
||||
{% if d.base_tax_amount > 0 %}
|
||||
<div class="row tax-row">
|
||||
<div class="col-xs-8 text-right">{{ d.description }}</div>
|
||||
<div class="col-xs-4 text-right">
|
||||
{{ d.get_formatted("base_tax_amount") }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<div class="row tax-grand-total-row">
|
||||
<div class="col-xs-8 text-right text-uppercase h6 text-muted">{{ _("Grand Total") }}</div>
|
||||
|
@ -39,10 +39,10 @@ window.render_product_list = function(data) {
|
||||
if(data.length < 10) {
|
||||
if(!table) {
|
||||
$(".more-btn")
|
||||
.replaceWith("<div class='alert alert-warning'>No products found.</div>");
|
||||
.replaceWith("<div class='alert alert-warning'>{{ _("No products found.") }}</div>");
|
||||
} else {
|
||||
$(".more-btn")
|
||||
.replaceWith("<div class='text-muted'>Nothing more to show.</div>");
|
||||
.replaceWith("<div class='text-muted'>{{ _("Nothing more to show.") }}</div>");
|
||||
}
|
||||
} else {
|
||||
$(".more-btn").toggle(true)
|
||||
|
@ -15,18 +15,18 @@ frappe.ready(function() {
|
||||
$(".item-cart").toggleClass("hide", (!!!r.message.price || !!!r.message.in_stock));
|
||||
if(r.message && r.message.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) {
|
||||
$(".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) {
|
||||
var qty_display = "In stock";
|
||||
var qty_display = "{{ _("In stock") }}";
|
||||
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'>\
|
||||
<i class='fa fa-check'></i> "+__(qty_display)+"</div>");
|
||||
<i class='fa fa-check'></i> "+qty_display+"</div>");
|
||||
}
|
||||
|
||||
if(r.message.qty) {
|
||||
|
Loading…
Reference in New Issue
Block a user