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
This commit is contained in:
marination 2021-07-08 10:57:01 +05:30
parent b450f1c583
commit 82f8f3caf2
8 changed files with 76 additions and 36 deletions

View File

@ -46,4 +46,8 @@ def get_product_filter_data():
"settings": engine.settings, "settings": engine.settings,
"sub_categories": sub_categories, "sub_categories": sub_categories,
"items_count": result["items_count"] "items_count": result["items_count"]
} }
@frappe.whitelist(allow_guest=True)
def get_guest_redirect_on_action():
return frappe.db.get_single_value("E Commerce Settings", "redirect_on_action")

View File

@ -6,23 +6,26 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"home_page_is_products", "home_page_is_products",
"show_availability_status",
"hide_variants",
"column_break_4", "column_break_4",
"products_per_page", "products_per_page",
"display_settings_section", "display_settings_section",
"show_attachments", "hide_variants",
"show_price",
"show_stock_availability",
"enable_variants", "enable_variants",
"column_break_13", "show_price",
"show_contact_us_button", "column_break_9",
"show_stock_availability",
"show_quantity_in_website", "show_quantity_in_website",
"show_apply_coupon_code_in_website",
"allow_items_not_in_stock", "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", "add_ons_section",
"enable_wishlist", "enable_wishlist",
"column_break_18", "column_break_22",
"enable_reviews", "enable_reviews",
"section_break_18", "section_break_18",
"company", "company",
@ -60,12 +63,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "Home Page is Products" "label": "Home Page is Products"
}, },
{
"default": "0",
"fieldname": "show_availability_status",
"fieldtype": "Check",
"label": "Show Availability Status"
},
{ {
"default": "6", "default": "6",
"fieldname": "products_per_page", "fieldname": "products_per_page",
@ -154,7 +151,7 @@
"default": "0", "default": "0",
"fieldname": "enable_variants", "fieldname": "enable_variants",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Enable Variants" "label": "Enable Variant Selection"
}, },
{ {
"fieldname": "column_break_13", "fieldname": "column_break_13",
@ -297,10 +294,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "Enable Wishlist" "label": "Enable Wishlist"
}, },
{
"fieldname": "column_break_18",
"fieldtype": "Column Break"
},
{ {
"default": "0", "default": "0",
"fieldname": "enable_reviews", "fieldname": "enable_reviews",
@ -347,12 +340,39 @@
"fieldtype": "HTML", "fieldtype": "HTML",
"label": "Redisearch Warning", "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>" "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, "index_web_pages_for_search": 1,
"issingle": 1, "issingle": 1,
"links": [], "links": [],
"modified": "2021-05-28 07:09:32.639710", "modified": "2021-07-07 21:32:17.363276",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "E-commerce", "module": "E-commerce",
"name": "E Commerce Settings", "name": "E Commerce Settings",

View File

@ -142,7 +142,6 @@ class ProductQuery:
def query_items_with_attributes(self, attributes, start=0): def query_items_with_attributes(self, attributes, start=0):
"""Build a query to fetch Website Items based on field & attribute filters.""" """Build a query to fetch Website Items based on field & attribute filters."""
all_items = []
item_codes = [] item_codes = []
for attribute, values in attributes.items(): for attribute, values in attributes.items():

View File

@ -327,7 +327,7 @@ erpnext.ProductView = class {
$('.page_content input').prop('disabled', true); $('.page_content input').prop('disabled', true);
me.make(from_filters=true); me.make(true);
$('.page_content input').prop('disabled', false); $('.page_content input').prop('disabled', false);
}); });
} }
@ -410,7 +410,7 @@ erpnext.ProductView = class {
if_key_exists(obj) { if_key_exists(obj) {
let exists = false; let exists = false;
for (let key in obj) { for (let key in obj) {
if (obj.hasOwnProperty(key) && obj[key]) { if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key]) {
exists = true; exists = true;
break; break;
} }

View File

@ -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) selling_price_list = cart_quotation.get("selling_price_list") if cart_quotation else _set_price_list(cart_settings, None)
price = get_price( price = []
item_code, if cart_settings.show_price:
selling_price_list, is_guest = frappe.session.user == "Guest"
cart_settings.default_customer_group, # Show Price if logged in.
cart_settings.company # 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") stock_status = get_web_item_qty_in_stock(item_code, "website_warehouse")
product_info = { product_info = {

View File

@ -9,7 +9,7 @@ def execute():
products_settings_fields = [ products_settings_fields = [
"hide_variants", "home_page_is_products", "products_per_page", "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 = [ shopping_cart_settings_fields = [

View File

@ -75,10 +75,12 @@ $.extend(shopping_cart, {
update_cart: function(opts) { update_cart: function(opts) {
if (frappe.session.user==="Guest") { if (frappe.session.user==="Guest") {
if(localStorage) { if (localStorage) {
localStorage.setItem("last_visited", window.location.pathname); 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 { } else {
shopping_cart.freeze(); shopping_cart.freeze();
return frappe.call({ return frappe.call({

View File

@ -88,7 +88,9 @@ $.extend(wishlist, {
if (localStorage) { if (localStorage) {
localStorage.setItem("last_visited", window.location.pathname); localStorage.setItem("last_visited", window.location.pathname);
} }
window.location.href = "/login";
this.redirect_guest();
return; return;
} }
@ -140,7 +142,7 @@ $.extend(wishlist, {
if (localStorage) { if (localStorage) {
localStorage.setItem("last_visited", window.location.pathname); localStorage.setItem("last_visited", window.location.pathname);
} }
window.location.href = "/login"; this.redirect_guest();
} else { } else {
let method = "erpnext.e_commerce.doctype.wishlist.wishlist.add_to_wishlist"; let method = "erpnext.e_commerce.doctype.wishlist.wishlist.add_to_wishlist";
if (action === "remove") { 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() { render_empty_state() {
$(".page_content").append(` $(".page_content").append(`
<div class="cart-empty frappe-card"> <div class="cart-empty frappe-card">