[FIX] website_sale_aplicoop: Complete infinite scroll and search filter integration
Major fixes: - Fix JSON body parsing in load_products_ajax with type='http' route * Parse JSON from request.httprequest.get_data() instead of post params * Correctly read page, search, category from JSON request body - Fix search and category filter combination * Use intersection (&) instead of replacement to preserve both filters * Now respects search AND category simultaneously - Integrate realtime_search.js with infinite_scroll.js * Add resetWithFilters() method to reset scroll to page 1 with new filters * When search/category changes, reload products from server * Clear grid and load fresh results - Fix pagination reset logic * Set currentPage = 0 in resetWithFilters() so loadNextPage() increments to 1 * Prevents loading empty page 2 when resetting filters Results: ✅ Infinite scroll loads all pages correctly (1, 2, 3...) ✅ Search filters work across all products (not just loaded) ✅ Category filters work correctly ✅ Search AND category filters work together ✅ Page resets to 1 when filters change
This commit is contained in:
parent
5eb039ffe0
commit
40ce973bd6
4 changed files with 463 additions and 239 deletions
|
|
@ -1380,7 +1380,7 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
|
||||
@http.route(
|
||||
["/eskaera/<int:order_id>/load-products-ajax"],
|
||||
type="json",
|
||||
type="http",
|
||||
auth="user",
|
||||
website=True,
|
||||
methods=["POST"],
|
||||
|
|
@ -1407,17 +1407,27 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
)
|
||||
)
|
||||
|
||||
# Get page from POST
|
||||
# Parse JSON body for parameters (type="http" doesn't auto-parse JSON)
|
||||
params = {}
|
||||
try:
|
||||
page = int(post.get("page", 1))
|
||||
if request.httprequest.content_length:
|
||||
data = request.httprequest.get_data(as_text=True)
|
||||
if data:
|
||||
params = json.loads(data)
|
||||
except (ValueError, json.JSONDecodeError, AttributeError):
|
||||
params = {}
|
||||
|
||||
# Get page from POST/JSON
|
||||
try:
|
||||
page = int(params.get("page", post.get("page", 1)))
|
||||
if page < 1:
|
||||
page = 1
|
||||
except (ValueError, TypeError):
|
||||
page = 1
|
||||
|
||||
# Get filters
|
||||
search_query = post.get("search", "").strip()
|
||||
category_filter = str(post.get("category", "0"))
|
||||
search_query = params.get("search", post.get("search", "")).strip()
|
||||
category_filter = str(params.get("category", post.get("category", "0")))
|
||||
|
||||
_logger.info(
|
||||
"load_products_ajax: order_id=%d, page=%d, search=%s, category=%s",
|
||||
|
|
@ -1477,7 +1487,8 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
lambda p: p.categ_id.id in order_cat_ids
|
||||
)
|
||||
|
||||
filtered_products = cat_filtered
|
||||
# Preserve search filter by using intersection
|
||||
filtered_products = filtered_products & cat_filtered
|
||||
except (ValueError, TypeError) as e:
|
||||
_logger.warning(
|
||||
"load_products_ajax: Invalid category filter: %s", str(e)
|
||||
|
|
@ -1556,7 +1567,7 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
}
|
||||
|
||||
# Render HTML
|
||||
html = request.env["ir.ui.view"]._render(
|
||||
html = request.env["ir.ui.view"]._render_template(
|
||||
"website_sale_aplicoop.eskaera_shop_products",
|
||||
{
|
||||
"group_order": group_order,
|
||||
|
|
@ -1571,13 +1582,18 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
},
|
||||
)
|
||||
|
||||
return {
|
||||
"html": html,
|
||||
"has_next": has_next,
|
||||
"next_page": page + 1,
|
||||
"total": total_products,
|
||||
"page": page,
|
||||
}
|
||||
return request.make_response(
|
||||
json.dumps(
|
||||
{
|
||||
"html": html,
|
||||
"has_next": has_next,
|
||||
"next_page": page + 1,
|
||||
"total": total_products,
|
||||
"page": page,
|
||||
}
|
||||
),
|
||||
[("Content-Type", "application/json")],
|
||||
)
|
||||
|
||||
@http.route(
|
||||
["/eskaera/add-to-cart"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue