Skip to content

Commit

Permalink
fix: homepage not working (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Dec 14, 2023
1 parent 38c6fe3 commit 1457893
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions webshop/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

doctype_js = {
"Item": "public/js/override/item.js",
"Homepage": "public/js/override/homepage.js",
}

doc_events = {
Expand Down
5 changes: 5 additions & 0 deletions webshop/patches.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pre_model_sync]

[post_model_sync]

webshop.patches.add_homepage_field
32 changes: 32 additions & 0 deletions webshop/patches/add_homepage_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields

def execute():
if not frappe.db.exists("Custom Field",
{"fieldname": "products", "dt": "Homepage"}
):
custom_fields = {
"Homepage": [
dict(
fieldname="products_section_break",
label="Products",
fieldtype="Section Break",
insert_after="hero_section",
),
dict(
fieldname="products_url",
label="URL for All Products",
fieldtype="Data",
insert_after="products_section_break",
),
dict(
fieldname="products",
label="Products",
fieldtype="Table",
insert_after="products_url",
options="Homepage Featured Product",
),
],
}

create_custom_fields(custom_fields)
18 changes: 18 additions & 0 deletions webshop/public/js/override/homepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
frappe.ui.form.on('Homepage', {
setup: function(frm) {
frm.fields_dict['products'].grid.get_field('item_code').get_query = function() {
return {
filters: {'published': 1}
}
}
},
});

frappe.ui.form.on('Homepage Featured Product', {
view: function(frm, cdt, cdn) {
var child= locals[cdt][cdn];
if (child.item_code && child.route) {
window.open('/' + child.route, '_blank');
}
}
});
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-12-14 22:14:23.853797",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"item_code",
"view",
"column_break_nxmx",
"item_name",
"section_break_qlos",
"description",
"column_break_jxff",
"image",
"thumbnail",
"route"
],
"fields": [
{
"fieldname": "item_code",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item",
"options": "Website Item",
"reqd": 1
},
{
"fieldname": "column_break_nxmx",
"fieldtype": "Column Break"
},
{
"fetch_from": "item_code.item_name",
"fieldname": "item_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Item Name"
},
{
"fieldname": "view",
"fieldtype": "Button",
"in_list_view": 1,
"label": "View"
},
{
"fieldname": "section_break_qlos",
"fieldtype": "Section Break"
},
{
"fetch_from": "item_code.web_long_description",
"fieldname": "description",
"fieldtype": "Text Editor",
"in_list_view": 1,
"label": "Description"
},
{
"fieldname": "column_break_jxff",
"fieldtype": "Column Break"
},
{
"fetch_from": "item_code.website_image",
"fetch_if_empty": 1,
"fieldname": "image",
"fieldtype": "Attach Image",
"label": "Image"
},
{
"fetch_from": "item_code.thumbnail",
"fieldname": "thumbnail",
"fieldtype": "Attach Image",
"label": "Thumbnail"
},
{
"fetch_from": "item_code.route",
"fieldname": "route",
"fieldtype": "Small Text",
"label": "Route",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-12-14 22:33:25.457721",
"modified_by": "Administrator",
"module": "Webshop",
"name": "Homepage Featured Product",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class HomepageFeaturedProduct(Document):
pass

1 comment on commit 1457893

@MorezMartin
Copy link

@MorezMartin MorezMartin commented on 1457893 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sufficient for me on a new installation
I think fields/custom fields must be integrated to homepage.json file, in erpnext or in webshop by overriding homepage.json
I think the patch is not applying on a fresh install
Error remains the same
image

Please sign in to comment.