diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-29 11:15:58 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-29 11:15:58 +0700 |
| commit | a1400f8ccdfb829a4193c5e8d3f910211e0d5830 (patch) | |
| tree | 4211e0c4acbffba80f56c2c8e15085c22bbfadbc /indoteknik_api/controllers | |
| parent | 203feb6018c55c108c31f4c0e03d38a8f39af52e (diff) | |
| parent | 6ed2316f6aa446bcd5bc7e6cd4d0c0a1136096dd (diff) | |
Merge branch 'change/feature/sync-solr' into production
Diffstat (limited to 'indoteknik_api/controllers')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/category.py | 3 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 25 |
2 files changed, 23 insertions, 5 deletions
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py index efbf52f2..3c5766e2 100644 --- a/indoteknik_api/controllers/api_v1/category.py +++ b/indoteknik_api/controllers/api_v1/category.py @@ -1,7 +1,7 @@ from .. import controller from odoo import http from odoo.http import request -import ast +import ast, json class Category(controller.Controller): @@ -58,6 +58,7 @@ class Category(controller.Controller): return self.response([x['id'] for x in categories]) + # TODO: Delete this function after unused by website @http.route(prefix + 'categories_homepage', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() def get_categories_homepage(self, **kw): diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index e08ec97b..e3b7701a 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -2,9 +2,7 @@ from .. import controller from odoo import http from odoo.http import request from datetime import datetime, timedelta -import ast -import logging -import math +import ast, logging, math, json _logger = logging.getLogger(__name__) @@ -348,4 +346,23 @@ class Product(controller.Controller): elif order == 'latest': orders.append('create_date desc') return ','.join(orders) -
\ No newline at end of file + + @http.route(prefix + 'product/category-homepage', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_product_category_homepage(self, **kw): + solr_model = request.env['apache.solr'] + + query = '*:*' + id = kw.get('id') + if id: + query = f'id:{id}' + + categories = solr_model.connect('product_category_homepage').search(query, sort='sequence_i asc').docs + categories = solr_model.clean_key_docs(categories) + for category in categories: + product_ids = category.get('product_ids', []) + category.pop('product_ids', None) + products = request.env['product.template'].browse(product_ids) + category['products'] = products.solr_results() + + return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')])
\ No newline at end of file |
