chore: Re-organise files,remove T&C modal in cart

- Moved product query and filters engine to `product_data_engine` folder
- Moved product grid, list, search, view to `product_ui` folder
- Renamed `website_item_indexing.py` to `redisearch.py`
- Render Terms and Conditions server side along with the rest of the Shopping cart. Don’t make another db call
- Style changes to terms and conditions
- Deleted unused `cart_terms.html`
- Removed print statements
This commit is contained in:
marination 2021-08-12 19:01:10 +05:30
parent 78ee51c6ca
commit 335a237383
19 changed files with 61 additions and 81 deletions

View File

@ -5,8 +5,8 @@
import frappe import frappe
from frappe.utils import cint from frappe.utils import cint
from erpnext.e_commerce.product_query import ProductQuery from erpnext.e_commerce.product_data_engine.query import ProductQuery
from erpnext.e_commerce.filters import ProductFiltersBuilder from erpnext.e_commerce.product_data_engine.filters import ProductFiltersBuilder
from erpnext.setup.doctype.item_group.item_group import get_child_groups from erpnext.setup.doctype.item_group.item_group import get_child_groups
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)

View File

@ -7,7 +7,7 @@ from frappe.utils import cint, comma_and
from frappe import _, msgprint from frappe import _, msgprint
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import unique from frappe.utils import unique
from erpnext.e_commerce.website_item_indexing import create_website_items_index, ALLOWED_INDEXABLE_FIELDS_SET, is_search_module_loaded from erpnext.e_commerce.redisearch import create_website_items_index, ALLOWED_INDEXABLE_FIELDS_SET, is_search_module_loaded
class ShoppingCartSetupError(frappe.ValidationError): pass class ShoppingCartSetupError(frappe.ValidationError): pass

View File

@ -17,7 +17,7 @@ from erpnext.e_commerce.shopping_cart.cart import _set_price_list
from erpnext.utilities.product import get_price from erpnext.utilities.product import get_price
# SEARCH # SEARCH
from erpnext.e_commerce.website_item_indexing import ( from erpnext.e_commerce.redisearch import (
insert_item_to_index, insert_item_to_index,
update_index_for_item, update_index_for_item,
delete_item_from_index delete_item_from_index

View File

@ -6,6 +6,7 @@ from whoosh.fields import ID, KEYWORD, TEXT, Schema
from whoosh.qparser import FieldsPlugin, MultifieldParser, WildcardPlugin from whoosh.qparser import FieldsPlugin, MultifieldParser, WildcardPlugin
from whoosh.query import Prefix from whoosh.query import Prefix
# TODO: Make obsolete
INDEX_NAME = "products" INDEX_NAME = "products"
class ProductSearch(FullTextSearch): class ProductSearch(FullTextSearch):

View File

@ -4,7 +4,7 @@ import frappe
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import frappe, unittest import frappe, unittest
from frappe.utils import get_html_for_route from frappe.utils import get_html_for_route
from erpnext.e_commerce.product_query import ProductQuery from erpnext.e_commerce.product_data_engine.query import ProductQuery
from erpnext.e_commerce.doctype.website_item.website_item import make_website_item from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
test_dependencies = ["Item"] test_dependencies = ["Item"]

View File

@ -1,6 +1,5 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
import frappe import frappe
from frappe import _dict from frappe import _dict
from frappe.utils import floor from frappe.utils import floor

View File

@ -1,4 +1,4 @@
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
import frappe import frappe

View File

@ -49,7 +49,7 @@ erpnext.ProductSearch = class {
// Fetch and populate product results // Fetch and populate product results
frappe.call({ frappe.call({
method: "erpnext.templates.pages.product_search.search", method: "erpnext.templates.pages.e_commerce.product_search.search",
args: { args: {
query: query query: query
}, },
@ -61,7 +61,7 @@ erpnext.ProductSearch = class {
// Populate categories // Populate categories
if (me.category_container) { if (me.category_container) {
frappe.call({ frappe.call({
method: "erpnext.templates.pages.product_search.get_category_suggestions", method: "erpnext.templates.pages.e_commerce.product_search.get_category_suggestions",
args: { args: {
query: query query: query
}, },

View File

@ -68,9 +68,9 @@
"public/js/hierarchy_chart/hierarchy_chart_mobile.js" "public/js/hierarchy_chart/hierarchy_chart_mobile.js"
], ],
"js/e-commerce.min.js": [ "js/e-commerce.min.js": [
"e_commerce/product_view.js", "e_commerce/product_ui/views.js",
"e_commerce/product_grid.js", "e_commerce/product_ui/grid.js",
"e_commerce/product_list.js", "e_commerce/product_ui/list.js",
"e_commerce/product_search.js" "e_commerce/product_ui/search.js"
] ]
} }

View File

@ -844,6 +844,14 @@ body.product-page {
} }
} }
} }
.t-and-c-container {
padding: 1.5rem;
}
.t-and-c-terms {
font-size: 14px;
}
} }
.cart-empty.frappe-card { .cart-empty.frappe-card {

View File

@ -10,11 +10,7 @@ from frappe.utils.nestedset import NestedSet
from frappe.website.utils import clear_cache from frappe.website.utils import clear_cache
from frappe.website.website_generator import WebsiteGenerator from frappe.website.website_generator import WebsiteGenerator
from six.moves.urllib.parse import quote from six.moves.urllib.parse import quote
from erpnext.e_commerce.product_data_engine.filters import ProductFiltersBuilder
from erpnext.e_commerce.filters import ProductFiltersBuilder
from erpnext.e_commerce.product_query import ProductQuery
from erpnext.utilities.product import get_qty_in_stock
class ItemGroup(NestedSet, WebsiteGenerator): class ItemGroup(NestedSet, WebsiteGenerator):
nsm_parent_field = 'parent_item_group' nsm_parent_field = 'parent_item_group'

View File

@ -21,8 +21,9 @@
{% if doc.items %} {% if doc.items %}
<div class="cart-container"> <div class="cart-container">
<div class="row m-0"> <div class="row m-0">
<div class="col-md-8 frappe-card p-5 mb-4"> <!-- Left section -->
<div> <div class="col-md-8">
<div class="frappe-card p-5 mb-4">
<div id="cart-error" class="alert alert-danger" style="display: none;"></div> <div id="cart-error" class="alert alert-danger" style="display: none;"></div>
<div class="cart-items-header"> <div class="cart-items-header">
{{ _('Items') }} {{ _('Items') }}
@ -56,7 +57,6 @@
</tfoot> </tfoot>
{% endif %} {% endif %}
</table> </table>
</div>
<div class="row mt-2"> <div class="row mt-2">
<div class="col-3"> <div class="col-3">
@ -80,37 +80,21 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div>
<!-- Terms and Conditions -->
{% if doc.items %} {% if doc.items %}
{% if doc.tc_name %} {% if doc.terms %}
<div class="terms-and-conditions-link"> <div class="t-and-c-container mt-4 frappe-card">
<a href class="link-terms-and-conditions" data-terms-name="{{ doc.tc_name }}"> <h5>{{ _("Terms and Conditions") }}</h5>
{{ _("Terms and Conditions") }} <div class="t-and-c-terms mt-2">
</a> {{ doc.terms }}
<script> </div>
frappe.ready(() => {
$('.link-terms-and-conditions').click((e) => {
e.preventDefault();
const $link = $(e.target);
const terms_name = $link.attr('data-terms-name');
show_terms_and_conditions(terms_name);
})
});
function show_terms_and_conditions(terms_name) {
frappe.call('erpnext.e_commerce.shopping_cart.cart.get_terms_and_conditions', { terms_name })
.then(r => {
frappe.msgprint({
title: terms_name,
message: r.message
});
});
}
</script>
</div> </div>
{% endif %} {% endif %}
</div> </div>
<!-- Right section -->
<div class="col-md-4"> <div class="col-md-4">
<div class="cart-payment-addresses"> <div class="cart-payment-addresses">
<!-- Apply Coupon Code --> <!-- Apply Coupon Code -->

View File

@ -1,2 +0,0 @@
<div>{{doc.terms}}</div>

View File

@ -8,7 +8,7 @@ from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_htm
from erpnext.e_commerce.shopping_cart.product_info import set_product_info_for_website from erpnext.e_commerce.shopping_cart.product_info import set_product_info_for_website
from redisearch import AutoCompleter, Client, Query from redisearch import AutoCompleter, Client, Query
from erpnext.e_commerce.website_item_indexing import ( from erpnext.e_commerce.redisearch import (
is_search_module_loaded, is_search_module_loaded,
WEBSITE_ITEM_INDEX, WEBSITE_ITEM_INDEX,
WEBSITE_ITEM_NAME_AUTOCOMPLETE, WEBSITE_ITEM_NAME_AUTOCOMPLETE,
@ -18,7 +18,6 @@ from erpnext.e_commerce.website_item_indexing import (
no_cache = 1 no_cache = 1
def get_context(context): def get_context(context):
context.show_search = True context.show_search = True
@ -35,13 +34,13 @@ def get_product_data(search=None, start=0, limit=12):
# limit = 12 because we show 12 items in the grid view # limit = 12 because we show 12 items in the grid view
# base query # base query
query = """ query = """
Select SELECT
web_item_name, item_name, item_code, brand, route, web_item_name, item_name, item_code, brand, route,
website_image, thumbnail, item_group, website_image, thumbnail, item_group,
description, web_long_description as website_description, description, web_long_description as website_description,
website_warehouse, ranking website_warehouse, ranking
from `tabWebsite Item` FROM `tabWebsite Item`
where published = 1 WHERE published = 1
""" """
# search term condition # search term condition
@ -53,7 +52,7 @@ def get_product_data(search=None, start=0, limit=12):
search = "%" + cstr(search) + "%" search = "%" + cstr(search) + "%"
# order by # order by
query += """ order by ranking asc, modified desc limit %s, %s""" % (cint(start), cint(limit)) query += """ ORDER BY ranking asc, modified desc limit %s, %s""" % (cint(start), cint(limit))
return frappe.db.sql(query, { return frappe.db.sql(query, {
"search": search "search": search
@ -91,14 +90,9 @@ def search(query, limit=10, fuzzy_search=True):
q = Query(query_string) q = Query(query_string)
print(f"Executing query: {q.query_string()}")
results = client.search(q) results = client.search(q)
search_results['results'] = list(map(convert_to_dict, results.docs)) search_results['results'] = list(map(convert_to_dict, results.docs))
# FOR DEBUGGING
print("SEARCH RESULTS ------------------\n ", search_results)
return search_results return search_results
def clean_up_query(query): def clean_up_query(query):

View File

@ -1,6 +1,6 @@
import frappe import frappe
from frappe.utils import cint from frappe.utils import cint
from erpnext.e_commerce.filters import ProductFiltersBuilder from erpnext.e_commerce.product_data_engine.filters import ProductFiltersBuilder
sitemap = 1 sitemap = 1