diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index 9f47260944..5ced1be138 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -194,6 +194,7 @@ class WebsiteItem(WebsiteGenerator): if frappe.db.exists("Wishlist Items", {"item_code": self.item_code, "parent": frappe.session.user}): context.wished = True + context.user_is_customer = check_if_user_is_customer() return context def set_variant_context(self, context): @@ -423,4 +424,21 @@ def make_website_item(doc, save=True): def on_doctype_update(): # since route is a Text column, it needs a length for indexing - frappe.db.add_index("Website Item", ["route(500)"]) \ No newline at end of file + frappe.db.add_index("Website Item", ["route(500)"]) + +def check_if_user_is_customer(user=None): + from frappe.contacts.doctype.contact.contact import get_contact_name + + if not user: + user = frappe.session.user + + contact_name = get_contact_name(user) + party = None + + if contact_name: + contact = frappe.get_doc('Contact', contact_name) + if contact.links: + party_doctype = contact.links[0].link_doctype + party = contact.links[0].link_name + + return True if party else False \ No newline at end of file diff --git a/erpnext/e_commerce/product_grid.js b/erpnext/e_commerce/product_grid.js index 8712a201a1..6f7b9cc37c 100644 --- a/erpnext/e_commerce/product_grid.js +++ b/erpnext/e_commerce/product_grid.js @@ -60,7 +60,7 @@ erpnext.ProductGrid = class {
`; - body_html += this.get_title_with_indicator(item, title); + body_html += this.get_title_with_indicator(item, title, settings); if (!item.has_variants && settings.enable_wishlist) { body_html += this.get_wishlist_icon(item); diff --git a/erpnext/e_commerce/product_view.js b/erpnext/e_commerce/product_view.js index f6727cacc5..03fd31efcd 100644 --- a/erpnext/e_commerce/product_view.js +++ b/erpnext/e_commerce/product_view.js @@ -33,15 +33,22 @@ erpnext.ProductView = class { args: args, callback: function(result) { if (!result.exc && result) { - me.render_filters(result.message[1]); + if (!result.message || !result.message[0].length) { + console.log("no items"); + // if result has no items or result is empty + me.render_no_products_section(); + } else { + console.log("there are items"); + me.render_filters(result.message[1]); - if (me.item_group) { - me.render_item_sub_categories(result.message[3]); + if (me.item_group) { + me.render_item_sub_categories(result.message[3]); + } + // Render views + me.render_list_view(result.message[0], result.message[2]); + me.render_grid_view(result.message[0], result.message[2]); + me.products = result.message[0]; } - // Render views - me.render_list_view(result.message[0], result.message[2]); - me.render_grid_view(result.message[0], result.message[2]); - me.products = result.message[0]; // Bottom paging me.add_paging_section(result.message[2]); @@ -238,15 +245,19 @@ erpnext.ProductView = class { } render_no_products_section() { - $("#products-area").append(` -
- ${ __('No products found') } + this.products_section.append(` +


+
+
+ Empty Cart +
+
${ __('No products found') }

`); } render_item_sub_categories(categories) { - if (categories) { + if (categories && categories.length) { let sub_group_html = `
${ __('Sub Categories') }
diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js index 331d04eb43..80f731e51c 100644 --- a/erpnext/public/js/shopping_cart.js +++ b/erpnext/public/js/shopping_cart.js @@ -54,7 +54,6 @@ frappe.ready(function() { // update login shopping_cart.show_shoppingcart_dropdown(); shopping_cart.set_cart_count(); - shopping_cart.bind_dropdown_cart_buttons(); shopping_cart.show_cart_navbar(); }); @@ -75,7 +74,7 @@ $.extend(shopping_cart, { }, update_cart: function(opts) { - if(frappe.session.user==="Guest") { + if (frappe.session.user==="Guest") { if(localStorage) { localStorage.setItem("last_visited", window.location.pathname); } @@ -156,29 +155,6 @@ $.extend(shopping_cart, { }); }, - - bind_dropdown_cart_buttons: function () { - $(".cart-icon").on('click', '.number-spinner button', function () { - var btn = $(this), - input = btn.closest('.number-spinner').find('input'), - oldValue = input.val().trim(), - newVal = 0; - - if (btn.attr('data-dir') == 'up') { - newVal = parseInt(oldValue) + 1; - } else { - if (oldValue > 1) { - newVal = parseInt(oldValue) - 1; - } - } - input.val(newVal); - var item_code = input.attr("data-item-code"); - shopping_cart.shopping_cart_update({item_code, qty: newVal, cart_dropdown: true}); - return false; - }); - - }, - show_cart_navbar: function () { frappe.call({ method: "erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings.is_cart_enabled", diff --git a/erpnext/public/js/wishlist.js b/erpnext/public/js/wishlist.js index 11dae355cb..1c5bee681f 100644 --- a/erpnext/public/js/wishlist.js +++ b/erpnext/public/js/wishlist.js @@ -58,6 +58,8 @@ $.extend(wishlist, { bind_remove_action: function() { // remove item from wishlist + let me = this; + $('.page_content').on("click", ".remove-wish", (e) => { const $remove_wish_btn = $(e.currentTarget); let item_code = $remove_wish_btn.data("item-code"); @@ -65,6 +67,10 @@ $.extend(wishlist, { let success_action = function() { const $card_wrapper = $remove_wish_btn.closest(".wishlist-card"); $card_wrapper.addClass("wish-removed"); + if (frappe.get_cookie("wish_count") == 0) { + $(".page_content").empty(); + me.render_empty_state(); + } }; let args = { item_code: item_code }; this.add_remove_from_wishlist("remove", args, success_action); @@ -78,6 +84,14 @@ $.extend(wishlist, { const $wish_icon = $btn.find('.wish-icon'); let me = this; + if(frappe.session.user==="Guest") { + if(localStorage) { + localStorage.setItem("last_visited", window.location.pathname); + } + window.location.href = "/login"; + return; + } + let success_action = function() { e_commerce.wishlist.set_wishlist_count(); }; @@ -122,30 +136,48 @@ $.extend(wishlist, { success_action: method to execute on successs, failure_action: method to execute on failure, async: make call asynchronously (true/false). */ - let method = "erpnext.e_commerce.doctype.wishlist.wishlist.add_to_wishlist"; - if (action === "remove") { - method = "erpnext.e_commerce.doctype.wishlist.wishlist.remove_from_wishlist"; - } - - frappe.call({ - async: async, - type: "POST", - method: method, - args: args, - callback: function (r) { - if (r.exc) { - if (failure_action && (typeof failure_action === 'function')) { - failure_action(); - } - frappe.msgprint({ - message: __("Sorry, something went wrong. Please refresh."), - indicator: "red", title: __("Note") - }); - } else if (success_action && (typeof success_action === 'function')) { - success_action(); - } + if (frappe.session.user==="Guest") { + if(localStorage) { + localStorage.setItem("last_visited", window.location.pathname); } - }); + window.location.href = "/login"; + } else { + let method = "erpnext.e_commerce.doctype.wishlist.wishlist.add_to_wishlist"; + if (action === "remove") { + method = "erpnext.e_commerce.doctype.wishlist.wishlist.remove_from_wishlist"; + } + + frappe.call({ + async: async, + type: "POST", + method: method, + args: args, + callback: function (r) { + if (r.exc) { + if (failure_action && (typeof failure_action === 'function')) { + failure_action(); + } + frappe.msgprint({ + message: __("Sorry, something went wrong. Please refresh."), + indicator: "red", title: __("Note") + }); + } else if (success_action && (typeof success_action === 'function')) { + success_action(); + } + } + }); + } + }, + + render_empty_state() { + $(".page_content").append(` +
+
+ Empty Cart +
+
${ __('Wishlist is empty !') }

+
+ `); } }); diff --git a/erpnext/templates/generators/item/item_reviews.html b/erpnext/templates/generators/item/item_reviews.html index fd03a823af..cd38bf3b14 100644 --- a/erpnext/templates/generators/item/item_reviews.html +++ b/erpnext/templates/generators/item/item_reviews.html @@ -5,11 +5,11 @@ {{ ratings_summary(reviews, reviews_per_rating, average_rating, average_whole_rating) }} - {% if frappe.session.user != "Guest" %} - + {% if frappe.session.user != "Guest" and user_is_customer %} + {% endif %}
diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js index f2b026c866..f0781ab68f 100644 --- a/erpnext/templates/includes/cart.js +++ b/erpnext/templates/includes/cart.js @@ -19,7 +19,6 @@ $.extend(shopping_cart, { shopping_cart.bind_request_quotation(); shopping_cart.bind_change_qty(); shopping_cart.bind_change_notes(); - shopping_cart.bind_dropdown_cart_buttons(); shopping_cart.bind_coupon_code(); }, @@ -129,8 +128,14 @@ $.extend(shopping_cart, { } } input.val(newVal); + + let notes = input.closest("td").siblings().find(".notes").text().trim(); var item_code = input.attr("data-item-code"); - shopping_cart.shopping_cart_update({item_code, qty: newVal}); + shopping_cart.shopping_cart_update({ + item_code, + qty: newVal, + additional_notes: notes + }); }); }, diff --git a/erpnext/templates/includes/cart/cart_items.html b/erpnext/templates/includes/cart/cart_items.html index 75441c42bc..d534b8fd7c 100644 --- a/erpnext/templates/includes/cart/cart_items.html +++ b/erpnext/templates/includes/cart/cart_items.html @@ -13,7 +13,7 @@ {{ _('Variant of') }} {{ variant_of }} {% endif %} -
+
diff --git a/erpnext/templates/pages/wishlist.html b/erpnext/templates/pages/wishlist.html index 4c039e3c1d..7a81dedb49 100644 --- a/erpnext/templates/pages/wishlist.html +++ b/erpnext/templates/pages/wishlist.html @@ -17,8 +17,12 @@
{% else %} - - {% include "erpnext/www/all-products/not_found.html" %} +
+
+ Empty Cart +
+
{{ _('Wishlist is empty!') }}

+
{% endif %} {% endblock %} \ No newline at end of file