From d1579a000290c0a345078c7140005adc5b5533bd Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 15 Sep 2021 14:00:14 +0530 Subject: [PATCH] fix: Shopping Cart and Variant Selection (Hotfix PR #27508) (cherry picked from commit 4096b1471f39a32c2e59b77791c705d81012094f) --- .../doctype/website_item/website_item.py | 6 +- erpnext/e_commerce/shopping_cart/cart.py | 6 +- .../variant_selector/item_variants_cache.py | 8 +- erpnext/public/js/shopping_cart.js | 16 ++- erpnext/templates/includes/cart.js | 10 +- .../includes/cart/cart_items_total.html | 10 ++ .../includes/cart/cart_payment_summary.html | 107 +++++++++--------- erpnext/templates/pages/cart.html | 18 +-- 8 files changed, 101 insertions(+), 80 deletions(-) create mode 100644 erpnext/templates/includes/cart/cart_items_total.html diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index 65c334c5fce5..fd5b62a81748 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -13,10 +13,6 @@ from erpnext.setup.doctype.item_group.item_group import (get_parent_item_groups, invalidate_cache_for) from erpnext.e_commerce.doctype.item_review.item_review import get_item_reviews -from erpnext.e_commerce.shopping_cart.cart import _set_price_list -from erpnext.utilities.product import get_price - -# SEARCH from erpnext.e_commerce.redisearch import ( insert_item_to_index, update_index_for_item, @@ -134,10 +130,10 @@ def validate_website_image(self): self.website_image = None def make_thumbnail(self): + """Make a thumbnail of `website_image`""" if frappe.flags.in_import or frappe.flags.in_migrate: return - """Make a thumbnail of `website_image`""" import requests.exceptions if not self.is_new() and self.website_image != frappe.db.get_value(self.doctype, self.name, "website_image"): diff --git a/erpnext/e_commerce/shopping_cart/cart.py b/erpnext/e_commerce/shopping_cart/cart.py index 28fb94b95eb7..acb46ad5a302 100644 --- a/erpnext/e_commerce/shopping_cart/cart.py +++ b/erpnext/e_commerce/shopping_cart/cart.py @@ -105,7 +105,7 @@ def place_order(): if is_stock_item: item_stock = get_web_item_qty_in_stock(item.item_code, "website_warehouse") if not cint(item_stock.in_stock): - throw(_("{1} Not in Stock").format(item.item_code)) + throw(_("{0} Not in Stock").format(item.item_code)) if item.qty > item_stock.stock_qty[0][0]: throw(_("Only {0} in Stock for item {1}").format(item_stock.stock_qty[0][0], item.item_code)) @@ -168,8 +168,10 @@ def update_cart(item_code, qty, additional_notes=None, with_items=False): return { "items": frappe.render_template("templates/includes/cart/cart_items.html", context), - "taxes": frappe.render_template("templates/includes/order/order_taxes.html", + "total": frappe.render_template("templates/includes/cart/cart_items_total.html", context), + "taxes_and_totals": frappe.render_template("templates/includes/cart/cart_payment_summary.html", + context) } else: return { diff --git a/erpnext/e_commerce/variant_selector/item_variants_cache.py b/erpnext/e_commerce/variant_selector/item_variants_cache.py index 636ae8d49170..39eb9155d5e4 100644 --- a/erpnext/e_commerce/variant_selector/item_variants_cache.py +++ b/erpnext/e_commerce/variant_selector/item_variants_cache.py @@ -67,12 +67,16 @@ def build_cache(self): as_list=1 ) - disabled_items = set([i.name for i in frappe.db.get_all('Item', {'disabled': 1})]) + unpublished_items = set([i.item_code for i in frappe.db.get_all('Website Item', filters={'published': 0}, fields=["item_code"])]) attribute_value_item_map = frappe._dict({}) item_attribute_value_map = frappe._dict({}) - item_variants_data = [r for r in item_variants_data if r[0] not in disabled_items] + # dont consider variants that are unpublished + # (either have no Website Item or are unpublished in Website Item) + item_variants_data = [r for r in item_variants_data if r[0] not in unpublished_items] + item_variants_data = [r for r in item_variants_data if frappe.db.exists("Website Item", {"item_code": r[0]})] + for row in item_variants_data: item_code, attribute, attribute_value = row # (attr, value) => [item1, item2] diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js index d99063b04542..d14740c1060d 100644 --- a/erpnext/public/js/shopping_cart.js +++ b/erpnext/public/js/shopping_cart.js @@ -105,6 +105,8 @@ $.extend(shopping_cart, { }, set_cart_count: function(animate=false) { + $(".intermediate-empty-cart").remove(); + var cart_count = frappe.get_cookie("cart_count"); if(frappe.session.user==="Guest") { cart_count = 0; @@ -119,13 +121,20 @@ $.extend(shopping_cart, { if(parseInt(cart_count) === 0 || cart_count === undefined) { $cart.css("display", "none"); - $(".cart-items").html('Cart is Empty'); $(".cart-tax-items").hide(); $(".btn-place-order").hide(); $(".cart-payment-addresses").hide(); + + let intermediate_empty_cart_msg = ` +
+ ${ __("Cart is Empty") } +
+ `; + $(".cart-table").after(intermediate_empty_cart_msg); } else { $cart.css("display", "inline"); + $("#cart-count").text(cart_count); } if(cart_count) { @@ -152,7 +161,10 @@ $.extend(shopping_cart, { callback: function(r) { if(!r.exc) { $(".cart-items").html(r.message.items); - $(".cart-tax-items").html(r.message.taxes); + $(".cart-tax-items").html(r.message.total); + $(".payment-summary").html(r.message.taxes_and_totals); + shopping_cart.set_cart_count(); + if (cart_dropdown != true) { $(".cart-icon").hide(); } diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js index ee8ec73b42a0..0c970450be61 100644 --- a/erpnext/templates/includes/cart.js +++ b/erpnext/templates/includes/cart.js @@ -57,7 +57,7 @@ $.extend(shopping_cart, { callback: function(r) { d.hide(); if (!r.exc) { - $(".cart-tax-items").html(r.message.taxes); + $(".cart-tax-items").html(r.message.total); shopping_cart.parent.find( `.address-container[data-address-type="${address_type}"]` ).html(r.message.address); @@ -214,12 +214,15 @@ $.extend(shopping_cart, { }, place_order: function(btn) { + shopping_cart.freeze(); + return frappe.call({ type: "POST", method: "erpnext.e_commerce.shopping_cart.cart.place_order", btn: btn, callback: function(r) { if(r.exc) { + shopping_cart.unfreeze(); var msg = ""; if(r._server_messages) { msg = JSON.parse(r._server_messages || []).join("
"); @@ -230,7 +233,6 @@ $.extend(shopping_cart, { .html(msg || frappe._("Something went wrong!")) .toggle(true); } else { - $('.cart-container table').hide(); $(btn).hide(); window.location.href = '/orders/' + encodeURIComponent(r.message); } @@ -239,12 +241,15 @@ $.extend(shopping_cart, { }, request_quotation: function(btn) { + shopping_cart.freeze(); + return frappe.call({ type: "POST", method: "erpnext.e_commerce.shopping_cart.cart.request_for_quotation", btn: btn, callback: function(r) { if(r.exc) { + shopping_cart.unfreeze(); var msg = ""; if(r._server_messages) { msg = JSON.parse(r._server_messages || []).join("
"); @@ -255,7 +260,6 @@ $.extend(shopping_cart, { .html(msg || frappe._("Something went wrong!")) .toggle(true); } else { - $('.cart-container table').hide(); $(btn).hide(); window.location.href = '/quotations/' + encodeURIComponent(r.message); } diff --git a/erpnext/templates/includes/cart/cart_items_total.html b/erpnext/templates/includes/cart/cart_items_total.html new file mode 100644 index 000000000000..c94fde462b14 --- /dev/null +++ b/erpnext/templates/includes/cart/cart_items_total.html @@ -0,0 +1,10 @@ + + + + + {{ _("Total") }} + + + {{ doc.get_formatted("total") }} + + \ No newline at end of file diff --git a/erpnext/templates/includes/cart/cart_payment_summary.html b/erpnext/templates/includes/cart/cart_payment_summary.html index c08b0c738883..847d45f8ffea 100644 --- a/erpnext/templates/includes/cart/cart_payment_summary.html +++ b/erpnext/templates/includes/cart/cart_payment_summary.html @@ -1,62 +1,61 @@ -
-
- {{ _("Payment Summary") }} -
-
-
- - - - - +
+ {{ _("Payment Summary") }} +
+
+
+
{{ _("Net Total (") + frappe.utils.cstr(doc.items|len) + _(" Items)") }}{{ doc.get_formatted("net_total") }}
+ + {% set total_items = frappe.utils.cstr(frappe.utils.flt(doc.total_qty, 0)) %} + + + - - {% for d in doc.taxes %} - {% if d.base_tax_amount %} - - - - - {% endif %} - {% endfor %} -
{{ _("Net Total (") + total_items + _(" Items)") }}{{ doc.get_formatted("net_total") }}
- {{ d.description }} - - {{ d.get_formatted("base_tax_amount") }} -
+ + {% for d in doc.taxes %} + {% if d.base_tax_amount %} + + + {{ d.description }} + + + {{ d.get_formatted("base_tax_amount") }} + + + {% endif %} + {% endfor %} + - - + + - - - - - -
{{ _("Grand Total") }}{{ doc.get_formatted("grand_total") }}
+ + + + + +
{{ _("Grand Total") }}{{ doc.get_formatted("grand_total") }}
- {% if cart_settings.enable_checkout %} - - {% else %} - - {% endif %} -
+ {% if cart_settings.enable_checkout %} + + {% else %} + + {% endif %}
diff --git a/erpnext/templates/pages/cart.html b/erpnext/templates/pages/cart.html index bb8ba3b24e08..c776ae48bedf 100644 --- a/erpnext/templates/pages/cart.html +++ b/erpnext/templates/pages/cart.html @@ -45,15 +45,7 @@ {% if cart_settings.enable_checkout or cart_settings.show_price_in_quotation %} - - - - {{ _("Total") }} - - - {{ doc.get_formatted("total") }} - - + {% include "templates/includes/cart/cart_items_total.html" %} {% endif %} @@ -110,7 +102,9 @@
{{ _("Terms and Conditions") }}
{% endif %} {% if cart_settings.enable_checkout %} - {% include "templates/includes/cart/cart_payment_summary.html" %} +
+ {% include "templates/includes/cart/cart_payment_summary.html" %} +
{% endif %} {% include "templates/includes/cart/cart_address.html" %} @@ -126,11 +120,11 @@
{{ _("Terms and Conditions") }}
{{ _('Your cart is Empty') }}

{% if cart_settings.enable_checkout %} - + {{ _('See past orders') }} {% else %} - + {{ _('See past quotations') }} {% endif %}