From 82f8f3caf2a0233a216e56f013abe36f2c0a6caa Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 8 Jul 2021 10:57:01 +0530 Subject: [PATCH] feat: Guest Display Settings - Re-arranged Settings checkboxes - Deleted `show_availability_status` from E Commerce Settings - Added `Hide Price for Guest` functionality - Added Custom Redirection for Guest Actions in E Commerce Settings - Minor cleanups --- erpnext/e_commerce/api.py | 6 +- .../e_commerce_settings.json | 62 ++++++++++++------- erpnext/e_commerce/product_query.py | 1 - erpnext/e_commerce/product_view.js | 4 +- .../e_commerce/shopping_cart/product_info.py | 19 ++++-- .../v13_0/populate_e_commerce_settings.py | 2 +- erpnext/public/js/shopping_cart.js | 6 +- erpnext/public/js/wishlist.js | 12 +++- 8 files changed, 76 insertions(+), 36 deletions(-) diff --git a/erpnext/e_commerce/api.py b/erpnext/e_commerce/api.py index 081e8a95a6..c6d27bd7b9 100644 --- a/erpnext/e_commerce/api.py +++ b/erpnext/e_commerce/api.py @@ -46,4 +46,8 @@ def get_product_filter_data(): "settings": engine.settings, "sub_categories": sub_categories, "items_count": result["items_count"] - } \ No newline at end of file + } + +@frappe.whitelist(allow_guest=True) +def get_guest_redirect_on_action(): + return frappe.db.get_single_value("E Commerce Settings", "redirect_on_action") \ No newline at end of file diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json index 627677481a..232a0612cc 100644 --- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json @@ -6,23 +6,26 @@ "engine": "InnoDB", "field_order": [ "home_page_is_products", - "show_availability_status", - "hide_variants", "column_break_4", "products_per_page", "display_settings_section", - "show_attachments", - "show_price", - "show_stock_availability", + "hide_variants", "enable_variants", - "column_break_13", - "show_contact_us_button", + "show_price", + "column_break_9", + "show_stock_availability", "show_quantity_in_website", - "show_apply_coupon_code_in_website", "allow_items_not_in_stock", + "column_break_13", + "show_apply_coupon_code_in_website", + "show_contact_us_button", + "show_attachments", + "guest_display_settings_section", + "hide_price_for_guest", + "redirect_on_action", "add_ons_section", "enable_wishlist", - "column_break_18", + "column_break_22", "enable_reviews", "section_break_18", "company", @@ -60,12 +63,6 @@ "fieldtype": "Check", "label": "Home Page is Products" }, - { - "default": "0", - "fieldname": "show_availability_status", - "fieldtype": "Check", - "label": "Show Availability Status" - }, { "default": "6", "fieldname": "products_per_page", @@ -154,7 +151,7 @@ "default": "0", "fieldname": "enable_variants", "fieldtype": "Check", - "label": "Enable Variants" + "label": "Enable Variant Selection" }, { "fieldname": "column_break_13", @@ -297,10 +294,6 @@ "fieldtype": "Check", "label": "Enable Wishlist" }, - { - "fieldname": "column_break_18", - "fieldtype": "Column Break" - }, { "default": "0", "fieldname": "enable_reviews", @@ -347,12 +340,39 @@ "fieldtype": "HTML", "label": "Redisearch Warning", "options": "

Redisearch module not loaded. If you want to use advanced product search features, refer documentation here.

" + }, + { + "default": "0", + "depends_on": "eval:doc.show_price", + "fieldname": "hide_price_for_guest", + "fieldtype": "Check", + "label": "Hide Price for Guest" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "collapsible": 1, + "fieldname": "guest_display_settings_section", + "fieldtype": "Section Break", + "label": "Guest Display Settings" + }, + { + "description": "Link to redirect Guest on actions that need login such as add to cart, wishlist, etc. E.g.: /login", + "fieldname": "redirect_on_action", + "fieldtype": "Data", + "label": "Redirect on Action" + }, + { + "fieldname": "column_break_22", + "fieldtype": "Column Break" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-05-28 07:09:32.639710", + "modified": "2021-07-07 21:32:17.363276", "modified_by": "Administrator", "module": "E-commerce", "name": "E Commerce Settings", diff --git a/erpnext/e_commerce/product_query.py b/erpnext/e_commerce/product_query.py index 476c6401b4..8c7ab1fad1 100644 --- a/erpnext/e_commerce/product_query.py +++ b/erpnext/e_commerce/product_query.py @@ -142,7 +142,6 @@ class ProductQuery: def query_items_with_attributes(self, attributes, start=0): """Build a query to fetch Website Items based on field & attribute filters.""" - all_items = [] item_codes = [] for attribute, values in attributes.items(): diff --git a/erpnext/e_commerce/product_view.js b/erpnext/e_commerce/product_view.js index c083991dc1..6b57aa9492 100644 --- a/erpnext/e_commerce/product_view.js +++ b/erpnext/e_commerce/product_view.js @@ -327,7 +327,7 @@ erpnext.ProductView = class { $('.page_content input').prop('disabled', true); - me.make(from_filters=true); + me.make(true); $('.page_content input').prop('disabled', false); }); } @@ -410,7 +410,7 @@ erpnext.ProductView = class { if_key_exists(obj) { let exists = false; for (let key in obj) { - if (obj.hasOwnProperty(key) && obj[key]) { + if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key]) { exists = true; break; } diff --git a/erpnext/e_commerce/shopping_cart/product_info.py b/erpnext/e_commerce/shopping_cart/product_info.py index cd47174b96..19c91707e6 100644 --- a/erpnext/e_commerce/shopping_cart/product_info.py +++ b/erpnext/e_commerce/shopping_cart/product_info.py @@ -24,12 +24,19 @@ def get_product_info_for_website(item_code, skip_quotation_creation=False): selling_price_list = cart_quotation.get("selling_price_list") if cart_quotation else _set_price_list(cart_settings, None) - price = get_price( - item_code, - selling_price_list, - cart_settings.default_customer_group, - cart_settings.company - ) + price = [] + if cart_settings.show_price: + is_guest = frappe.session.user == "Guest" + # Show Price if logged in. + # If not logged in, check if price is hidden for guest. + if not is_guest or not cart_settings.hide_price_for_guest: + price = get_price( + item_code, + selling_price_list, + cart_settings.default_customer_group, + cart_settings.company + ) + stock_status = get_web_item_qty_in_stock(item_code, "website_warehouse") product_info = { diff --git a/erpnext/patches/v13_0/populate_e_commerce_settings.py b/erpnext/patches/v13_0/populate_e_commerce_settings.py index 5241caed9f..5ce7acb8bb 100644 --- a/erpnext/patches/v13_0/populate_e_commerce_settings.py +++ b/erpnext/patches/v13_0/populate_e_commerce_settings.py @@ -9,7 +9,7 @@ def execute(): products_settings_fields = [ "hide_variants", "home_page_is_products", "products_per_page", - "show_availability_status", "enable_attribute_filters", "enable_field_filters" + "enable_attribute_filters", "enable_field_filters" ] shopping_cart_settings_fields = [ diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js index 40d58d11f7..31d34bcc64 100644 --- a/erpnext/public/js/shopping_cart.js +++ b/erpnext/public/js/shopping_cart.js @@ -75,10 +75,12 @@ $.extend(shopping_cart, { update_cart: function(opts) { if (frappe.session.user==="Guest") { - if(localStorage) { + if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } - window.location.href = "/login"; + frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then((res) => { + window.location.href = res.message || "/login"; + }); } else { shopping_cart.freeze(); return frappe.call({ diff --git a/erpnext/public/js/wishlist.js b/erpnext/public/js/wishlist.js index 8264772864..984572383a 100644 --- a/erpnext/public/js/wishlist.js +++ b/erpnext/public/js/wishlist.js @@ -88,7 +88,9 @@ $.extend(wishlist, { if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } - window.location.href = "/login"; + + this.redirect_guest(); + return; } @@ -140,7 +142,7 @@ $.extend(wishlist, { if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } - window.location.href = "/login"; + this.redirect_guest(); } else { let method = "erpnext.e_commerce.doctype.wishlist.wishlist.add_to_wishlist"; if (action === "remove") { @@ -169,6 +171,12 @@ $.extend(wishlist, { } }, + redirect_guest() { + frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then((res) => { + window.location.href = res.message || "/login"; + }); + }, + render_empty_state() { $(".page_content").append(`