fix: Query filter fields from Website Item instead of Item master
- tweak `filters.py` to correctly query filter field values from Website Item
- Use Website Item for filter field options in Settings and Item Group Field Filter table
diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js
index 6302d26..a8966b0 100644
--- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js
+++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js
@@ -24,17 +24,17 @@
);
}
- frappe.model.with_doctype("Item", () => {
+ frappe.model.with_doctype("Website Item", () => {
const web_item_meta = frappe.get_meta('Website Item');
const valid_fields = web_item_meta.fields.filter(
df => ["Link", "Table MultiSelect"].includes(df.fieldtype) && !df.hidden
).map(df => ({ label: df.label, value: df.fieldname }));
- frm.fields_dict.filter_fields.grid.update_docfield_property(
+ frm.get_field("filter_fields").grid.update_docfield_property(
'fieldname', 'fieldtype', 'Select'
);
- frm.fields_dict.filter_fields.grid.update_docfield_property(
+ frm.get_field("filter_fields").grid.update_docfield_property(
'fieldname', 'options', valid_fields
);
});
diff --git a/erpnext/e_commerce/product_data_engine/filters.py b/erpnext/e_commerce/product_data_engine/filters.py
index feb89c1..e5e5e97 100644
--- a/erpnext/e_commerce/product_data_engine/filters.py
+++ b/erpnext/e_commerce/product_data_engine/filters.py
@@ -22,12 +22,14 @@
fields, filter_data = [], []
filter_fields = [row.fieldname for row in self.doc.filter_fields] # fields in settings
- # filter valid field filters i.e. those that exist in Item
- item_meta = frappe.get_meta("Item", cached=True)
- fields = [item_meta.get_field(field) for field in filter_fields if item_meta.has_field(field)]
+ # filter valid field filters i.e. those that exist in Website Item
+ web_item_meta = frappe.get_meta("Website Item", cached=True)
+ fields = [
+ web_item_meta.get_field(field) for field in filter_fields if web_item_meta.has_field(field)
+ ]
for df in fields:
- item_filters, item_or_filters = {"published_in_website": 1}, []
+ item_filters, item_or_filters = {"published": 1}, []
link_doctype_values = self.get_filtered_link_doctype_records(df)
if df.fieldtype == "Link":
@@ -50,9 +52,13 @@
]
)
+ # exclude variants if mentioned in settings
+ if frappe.db.get_single_value("E Commerce Settings", "hide_variants"):
+ item_filters["variant_of"] = ["is", "not set"]
+
# Get link field values attached to published items
item_values = frappe.get_all(
- "Item",
+ "Website Item",
fields=[df.fieldname],
filters=item_filters,
or_filters=item_or_filters,
diff --git a/erpnext/setup/doctype/item_group/item_group.js b/erpnext/setup/doctype/item_group/item_group.js
index f570c2f..cf96dc1 100644
--- a/erpnext/setup/doctype/item_group/item_group.js
+++ b/erpnext/setup/doctype/item_group/item_group.js
@@ -72,17 +72,17 @@
});
}
- frappe.model.with_doctype('Item', () => {
- const item_meta = frappe.get_meta('Item');
+ frappe.model.with_doctype('Website Item', () => {
+ const web_item_meta = frappe.get_meta('Website Item');
- const valid_fields = item_meta.fields.filter(
+ const valid_fields = web_item_meta.fields.filter(
df => ['Link', 'Table MultiSelect'].includes(df.fieldtype) && !df.hidden
).map(df => ({ label: df.label, value: df.fieldname }));
- frm.fields_dict.filter_fields.grid.update_docfield_property(
+ frm.get_field("filter_fields").grid.update_docfield_property(
'fieldname', 'fieldtype', 'Select'
);
- frm.fields_dict.filter_fields.grid.update_docfield_property(
+ frm.get_field("filter_fields").grid.update_docfield_property(
'fieldname', 'options', valid_fields
);
});