fix: Sync Website Items on Item Change, Short Website Description

- Added Short Description in Website Item for List View
- Update Website Item on Item info change
- Un-publish Web Item if Item is disabled
- Removed unnecessary dependency on Item from query engine
- Rearranged item detail fields in Website Item
- Added Link to Website Item on Item Dashboard
This commit is contained in:
marination
2021-07-08 12:52:57 +05:30
parent 2107883301
commit c844f3a612
6 changed files with 88 additions and 44 deletions

View File

@@ -19,6 +19,8 @@
"item_name",
"item_group",
"stock_uom",
"column_break_11",
"description",
"brand",
"image",
"display_section",
@@ -28,12 +30,12 @@
"slideshow",
"thumbnail",
"section_break_17",
"short_description",
"web_long_description",
"column_break_27",
"website_warehouse",
"description",
"website_specifications",
"copy_from_item_group",
"column_break_27",
"web_long_description",
"display_additional_information_section",
"show_tabbed_section",
"tabs",
@@ -300,13 +302,23 @@
"fieldtype": "Table",
"label": "Offers to Display",
"options": "Website Offer"
},
{
"fieldname": "column_break_11",
"fieldtype": "Column Break"
},
{
"description": "Short Description for List View",
"fieldname": "short_description",
"fieldtype": "Data",
"label": "Short Website Description"
}
],
"has_web_view": 1,
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-04-22 15:29:13.541145",
"modified": "2021-07-08 12:22:23.466598",
"modified_by": "Administrator",
"module": "E-commerce",
"name": "Website Item",

View File

@@ -44,9 +44,16 @@ class WebsiteItem(WebsiteGenerator):
self.publish_unpublish_desk_item(publish=True)
if not self.get("__islocal"):
self.old_website_item_groups = frappe.db.sql_list("""select item_group
from `tabWebsite Item Group`
where parentfield='website_item_groups' and parenttype='Item' and parent=%s""", self.name)
self.old_website_item_groups = frappe.db.sql_list("""
select
item_group
from
`tabWebsite Item Group`
where
parentfield='website_item_groups'
and parenttype='Website Item'
and parent=%s
""", self.name)
def on_update(self):
invalidate_cache_for_web_item(self)
@@ -390,6 +397,28 @@ def invalidate_cache_for_web_item(doc):
invalidate_item_variants_cache_for_website(doc)
def on_doctype_update():
# since route is a Text column, it needs a length for indexing
frappe.db.add_index("Website Item", ["route(500)"])
def check_if_user_is_customer(user=None):
from frappe.contacts.doctype.contact.contact import get_contact_name
if not user:
user = frappe.session.user
contact_name = get_contact_name(user)
customer = None
if contact_name:
contact = frappe.get_doc('Contact', contact_name)
for link in contact.links:
if link.link_doctype == "Customer":
customer = link.link_name
break
return True if customer else False
@frappe.whitelist()
def make_website_item(doc, save=True):
if not doc:
@@ -418,26 +447,4 @@ def make_website_item(doc, save=True):
# Add to search cache
insert_item_to_index(website_item)
return [website_item.name, website_item.web_item_name]
def on_doctype_update():
# since route is a Text column, it needs a length for indexing
frappe.db.add_index("Website Item", ["route(500)"])
def check_if_user_is_customer(user=None):
from frappe.contacts.doctype.contact.contact import get_contact_name
if not user:
user = frappe.session.user
contact_name = get_contact_name(user)
customer = None
if contact_name:
contact = frappe.get_doc('Contact', contact_name)
for link in contact.links:
if link.link_doctype == "Customer":
customer = link.link_name
break
return True if customer else False
return [website_item.name, website_item.web_item_name]

View File

@@ -102,7 +102,7 @@ erpnext.ProductList = class {
Item Code : ${ item.item_code }
</p>
<div class="text-muted mt-2">
${ item.description || '' }
${ item.short_description || '' }
</div>
<div class="product-price">
${ item.formatted_price || '' }

View File

@@ -20,7 +20,7 @@ class ProductQuery:
self.page_length = self.settings.products_per_page or 20
self.fields = ['web_item_name', 'name', 'item_name', 'item_code', 'website_image',
'variant_of', 'has_variants', 'item_group', 'image', 'web_long_description',
'description', 'route', 'website_warehouse', 'ranking']
'short_description', 'route', 'website_warehouse', 'ranking']
self.filters = [["published", "=", 1]]
self.or_filters = []
@@ -184,7 +184,7 @@ class ProductQuery:
continue
# handle multiselect fields in filter addition
meta = frappe.get_meta('Item', cached=True)
meta = frappe.get_meta('Website Item', cached=True)
df = meta.get_field(field)
if df.fieldtype == 'Table MultiSelect':
@@ -207,16 +207,16 @@ class ProductQuery:
search_term (str): Search candidate
"""
# Default fields to search from
default_fields = {'name', 'item_name', 'description', 'item_group'}
default_fields = {'item_code', 'item_name', 'web_long_description', 'item_group'}
# Get meta search fields
meta = frappe.get_meta("Item")
meta = frappe.get_meta("Website Item")
meta_fields = set(meta.get_search_fields())
# Join the meta fields and default fields set
search_fields = default_fields.union(meta_fields)
if frappe.db.count('Item', cache=True) > 50000:
search_fields.discard('description')
if frappe.db.count('Website Item', cache=True) > 50000:
search_fields.discard('web_long_description')
# Build or filters for query
search = '%{}%'.format(search_term)