From b29c5d6e844d5843c7113ddd75626b2af905f52a Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 25 May 2021 01:35:22 +0530 Subject: [PATCH] fix: Discount Filters and Web templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed discount filters (didn’t work after js render change) - Fix Item Card Group template height and style - Add placeholder to missing images in Product Category Cards template - Code cleanup --- .../e_commerce/product_configurator/utils.py | 2 +- erpnext/e_commerce/product_grid.js | 1 + erpnext/e_commerce/product_list.js | 1 + erpnext/e_commerce/product_query.py | 17 +- erpnext/e_commerce/product_view.js | 142 ++++++++++++++-- .../product_category_cards.html | 9 +- erpnext/patches/v13_0/create_website_items.py | 6 +- erpnext/public/js/wishlist.js | 6 +- erpnext/public/scss/shopping_cart.scss | 13 ++ erpnext/templates/includes/macros.html | 16 +- erpnext/templates/pages/customer_reviews.py | 6 +- erpnext/templates/pages/wishlist.py | 9 +- erpnext/www/all-products/index.js | 152 ++---------------- erpnext/www/shop-by-category/index.html | 12 -- erpnext/www/shop-by-category/index.py | 27 ++-- 15 files changed, 215 insertions(+), 204 deletions(-) diff --git a/erpnext/e_commerce/product_configurator/utils.py b/erpnext/e_commerce/product_configurator/utils.py index 9faaa5dc5d..5ea32f9f9f 100644 --- a/erpnext/e_commerce/product_configurator/utils.py +++ b/erpnext/e_commerce/product_configurator/utils.py @@ -115,7 +115,7 @@ def get_next_attribute_and_values(item_code, selected_attributes): next_attribute = attribute break - valid_options_for_attributes = frappe._dict({}) + valid_options_for_attributes = frappe._dict() for a in attribute_list: valid_options_for_attributes[a] = set() diff --git a/erpnext/e_commerce/product_grid.js b/erpnext/e_commerce/product_grid.js index 6f7b9cc37c..a716efa90a 100644 --- a/erpnext/e_commerce/product_grid.js +++ b/erpnext/e_commerce/product_grid.js @@ -12,6 +12,7 @@ erpnext.ProductGrid = class { this.products_section.addClass("hidden"); } + this.products_section.empty(); this.make(); } diff --git a/erpnext/e_commerce/product_list.js b/erpnext/e_commerce/product_list.js index 2836c3acc1..fa35c7e66c 100644 --- a/erpnext/e_commerce/product_list.js +++ b/erpnext/e_commerce/product_list.js @@ -12,6 +12,7 @@ erpnext.ProductList = class { this.products_section.addClass("hidden"); } + this.products_section.empty(); this.make(); } diff --git a/erpnext/e_commerce/product_query.py b/erpnext/e_commerce/product_query.py index 608e9d97fe..ed3c18b3fb 100644 --- a/erpnext/e_commerce/product_query.py +++ b/erpnext/e_commerce/product_query.py @@ -106,7 +106,7 @@ class ProductQuery: def query_items(self, conditions, or_conditions, substitutions, start=0, with_attributes=False): """Build a query to fetch Website Items based on field filters.""" - self.query_fields = (", ").join(self.fields) + self.query_fields = ", ".join(self.fields) attribute_table = ", `tabItem Variant Attribute` iva" if with_attributes else "" @@ -119,9 +119,9 @@ class ProductQuery: {conditions} {or_conditions} limit {self.page_length} offset {start} - """, - tuple(substitutions), - as_dict=1) + """, + tuple(substitutions), + as_dict=1) def query_items_with_attributes(self, attributes, start=0): """Build a query to fetch Website Items based on field & attribute filters.""" @@ -147,7 +147,7 @@ class ProductQuery: all_items.append(set(items_dict.keys())) - result = [items_dict.get(item) for item in list(set.intersection(*all_items))] + result = [items_dict.get(item) for item in set.intersection(*all_items)] return result def build_fields_filters(self, filters): @@ -192,11 +192,8 @@ class ProductQuery: # Join the meta fields and default fields set search_fields = default_fields.union(meta_fields) - try: - if frappe.db.count('Item', cache=True) > 50000: - search_fields.remove('description') - except KeyError: - pass + if frappe.db.count('Item', cache=True) > 50000: + search_fields.discard('description') # Build or filters for query search = '%{}%'.format(search_term) diff --git a/erpnext/e_commerce/product_view.js b/erpnext/e_commerce/product_view.js index 372e72281c..a64d55fa0e 100644 --- a/erpnext/e_commerce/product_view.js +++ b/erpnext/e_commerce/product_view.js @@ -6,8 +6,11 @@ erpnext.ProductView = class { */ constructor(options) { Object.assign(this, options); - this.preference = "List View"; + this.preference = this.view_type; + this.make(); + } + make() { this.products_section.empty(); this.prepare_view_toggler(); this.get_item_filter_data(); @@ -22,12 +25,12 @@ erpnext.ProductView = class { } get_item_filter_data() { - // Get and render all Items related components + // Get and render all Product related views let me = this; let args = this.get_query_filters(); - $('#list').prop('disabled', true); - $('#image-view').prop('disabled', true); + this.disable_view_toggler(true); + frappe.call({ method: 'erpnext.e_commerce.doctype.website_item.website_item.get_product_filter_data', args: args, @@ -55,14 +58,20 @@ erpnext.ProductView = class { me.render_no_products_section(); } - $('#list').prop('disabled', false); - $('#image-view').prop('disabled', false); + me.disable_view_toggler(false); } }); } + disable_view_toggler(disable=false) { + $('#list').prop('disabled', disable); + $('#image-view').prop('disabled', disable); + } + render_filters(filter_data) { this.get_discount_filter_html(filter_data.discount_filters); + this.bind_filters(); + this.restore_filters_state(); } render_grid_view(items, settings) { @@ -226,9 +235,11 @@ erpnext.ProductView = class { html += `