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

@ -47,3 +47,7 @@ def get_product_filter_data():
"sub_categories": sub_categories,
"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",
"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": "<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",

View File

@ -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():

View File

@ -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;
}

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)
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 = {

View File

@ -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 = [

View File

@ -78,7 +78,9 @@ $.extend(shopping_cart, {
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({

View File

@ -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(`
<div class="cart-empty frappe-card">