summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-08-25 15:13:46 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-08-25 15:13:46 +0700
commit52f4b12c0b211f958c2704346d7da24d1d4767c6 (patch)
tree772560ce2168a2c20de141ca88ad937d45505169 /indoteknik_api/controllers/api_v1
parenta9a3c3e8945dd11a0d81f64a5629876397a1e51d (diff)
Update API product category homepage
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/category.py3
-rw-r--r--indoteknik_api/controllers/api_v1/product.py22
2 files changed, 20 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..98e131da 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,20 @@ 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:
+ category['products'] = json.loads(category['products'])
+
+ return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')]) \ No newline at end of file