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
diff --git a/erpnext/e_commerce/api.py b/erpnext/e_commerce/api.py
index 081e8a9..c6d27bd 100644
--- a/erpnext/e_commerce/api.py
+++ b/erpnext/e_commerce/api.py
@@ -46,4 +46,8 @@
"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 6276774..232a061 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",
@@ -61,12 +64,6 @@
"label": "Home Page is Products"
},
{
- "default": "0",
- "fieldname": "show_availability_status",
- "fieldtype": "Check",
- "label": "Show Availability Status"
- },
- {
"default": "6",
"fieldname": "products_per_page",
"fieldtype": "Int",
@@ -154,7 +151,7 @@
"default": "0",
"fieldname": "enable_variants",
"fieldtype": "Check",
- "label": "Enable Variants"
+ "label": "Enable Variant Selection"
},
{
"fieldname": "column_break_13",
@@ -298,10 +295,6 @@
"label": "Enable Wishlist"
},
{
- "fieldname": "column_break_18",
- "fieldtype": "Column Break"
- },
- {
"default": "0",
"fieldname": "enable_reviews",
"fieldtype": "Check",
@@ -347,12 +340,39 @@
"fieldtype": "HTML",
"label": "Redisearch Warning",
"options": "<p class=\"alert alert-warning\">Redisearch module not loaded. If you want to use advanced product search features, refer documentation <a class=\"alert-link\" href=\"https://frappeframework.com/docs/user/en/installation\" target=\"_blank\">here</a>.</p>"
+ },
+ {
+ "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. <b>E.g.: /login</b>",
+ "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 476c640..8c7ab1f 100644
--- a/erpnext/e_commerce/product_query.py
+++ b/erpnext/e_commerce/product_query.py
@@ -142,7 +142,6 @@
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 c083991..6b57aa9 100644
--- a/erpnext/e_commerce/product_view.js
+++ b/erpnext/e_commerce/product_view.js
@@ -327,7 +327,7 @@
$('.page_content input').prop('disabled', true);
- me.make(from_filters=true);
+ me.make(true);
$('.page_content input').prop('disabled', false);
});
}
@@ -410,7 +410,7 @@
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 cd47174..19c9170 100644
--- a/erpnext/e_commerce/shopping_cart/product_info.py
+++ b/erpnext/e_commerce/shopping_cart/product_info.py
@@ -24,12 +24,19 @@
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 5241cae..5ce7acb 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 @@
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 40d58d1..31d34bc 100644
--- a/erpnext/public/js/shopping_cart.js
+++ b/erpnext/public/js/shopping_cart.js
@@ -75,10 +75,12 @@
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 8264772..9845723 100644
--- a/erpnext/public/js/wishlist.js
+++ b/erpnext/public/js/wishlist.js
@@ -88,7 +88,9 @@
if (localStorage) {
localStorage.setItem("last_visited", window.location.pathname);
}
- window.location.href = "/login";
+
+ this.redirect_guest();
+
return;
}
@@ -140,7 +142,7 @@
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 @@
}
},
+ 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(`
<div class="cart-empty frappe-card">