feat: Show brand line in search results
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 0f7b2cc..36177ff 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
@@ -323,7 +323,7 @@
"label": "Show Categories in Search Autocomplete"
},
{
- "default": "1",
+ "default": "0",
"description": "e.g. \"iPhone 12 by Apple\"",
"fieldname": "show_brand_line",
"fieldtype": "Check",
@@ -333,7 +333,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2021-05-05 13:05:52.615719",
+ "modified": "2021-05-05 13:41:11.483232",
"modified_by": "Administrator",
"module": "E-commerce",
"name": "E Commerce Settings",
diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
index a028a5f..441e85b 100644
--- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
+++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
@@ -25,7 +25,9 @@
self.validate_field_filters()
self.validate_attribute_filters()
self.validate_checkout()
+ self.validate_brand_check()
self.validate_search_index_fields()
+
if self.enabled:
self.validate_exchange_rates_exist()
@@ -76,6 +78,10 @@
self.search_index_fields = ','.join(fields)
+ def validate_brand_check(self):
+ if self.show_brand_line and not ("brand" in self.search_index_fields):
+ self.search_index_fields += ",brand"
+
def validate_exchange_rates_exist(self):
"""check if exchange rates exist for all Price List currencies (to company's currency)"""
company_currency = frappe.get_cached_value('Company', self.company, "default_currency")
diff --git a/erpnext/e_commerce/website_item_indexing.py b/erpnext/e_commerce/website_item_indexing.py
index 4e3af8b..8c0e074 100644
--- a/erpnext/e_commerce/website_item_indexing.py
+++ b/erpnext/e_commerce/website_item_indexing.py
@@ -99,8 +99,6 @@
# Reinsert to Cache
insert_item_to_index(website_item_doc)
define_autocomplete_dictionary()
- # TODO: Only reindex updated items
- create_website_items_index()
def delete_item_from_index(website_item_doc):
r = frappe.cache()
@@ -111,9 +109,16 @@
except:
return False
- # TODO: Also delete autocomplete suggestion
+ delete_from_ac_dict(website_item_doc)
+
return True
+def delete_from_ac_dict(website_item_doc):
+ '''Removes this items's name from autocomplete dictionary'''
+ r = frappe.cache()
+ name_ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=r)
+ name_ac.delete(website_item_doc.web_item_name)
+
def define_autocomplete_dictionary():
"""Creates an autocomplete search dictionary for `name`.
Also creats autocomplete dictionary for `categories` if
@@ -163,7 +168,6 @@
for k, v in web_item.items():
super(RedisWrapper, r).hset(key, k, v)
-
def get_cache_key(name):
name = frappe.scrub(name)
return f"{WEBSITE_ITEM_KEY_PREFIX}{name}"
diff --git a/erpnext/www/all-products/search.css b/erpnext/www/all-products/search.css
index ff0ca6a..687532d 100644
--- a/erpnext/www/all-products/search.css
+++ b/erpnext/www/all-products/search.css
@@ -2,4 +2,8 @@
height: 50px;
width: 50px;
object-fit: cover;
+}
+
+.brand-line {
+ color: gray;
}
\ No newline at end of file
diff --git a/erpnext/www/all-products/search.html b/erpnext/www/all-products/search.html
index c6c8708..a86a9c0 100644
--- a/erpnext/www/all-products/search.html
+++ b/erpnext/www/all-products/search.html
@@ -26,7 +26,6 @@
</div>
{% set show_categories = frappe.db.get_single_value('E Commerce Settings', 'show_categories_in_search_autocomplete') %}
-
{% if show_categories %}
<div id="categories" class="col-sm">
<h2>Categories</h2>
@@ -34,6 +33,11 @@
</ul>
</div>
{% endif %}
+
+ {% set show_brand_line = frappe.db.get_single_value('E Commerce Settings', 'show_brand_line') %}
+ {% if show_brand_line %}
+ <span id="show-brand-line"></span>
+ {% endif %}
</div>
{% endblock %}
\ No newline at end of file
diff --git a/erpnext/www/all-products/search.js b/erpnext/www/all-products/search.js
index 9ed5b21..c97e48b 100644
--- a/erpnext/www/all-products/search.js
+++ b/erpnext/www/all-products/search.js
@@ -3,13 +3,14 @@
const searchBox = document.getElementById("search-box");
const results = document.getElementById("results");
const categoryList = document.getElementById("category-suggestions");
+const showBrandLine = document.getElementById("show-brand-line");
function populateResults(data) {
html = ""
for (let res of data.message) {
html += `<li class="list-group-item list-group-item-action">
<img class="item-thumb" src="${res.thumbnail || 'img/placeholder.png'}" />
- <a href="/${res.route}">${res.web_item_name}</a>
+ <a href="/${res.route}">${res.web_item_name} <span class="brand-line">${showBrandLine && res.brand ? "by " + res.brand : ""}</span></a>
</li>`
}
results.innerHTML = html;