diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-07-30 10:11:20 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-07-30 10:11:20 +0000 |
| commit | a6d5a8245721463bc8bb14b7e8921f0c544ffd39 (patch) | |
| tree | 9f0f6f1cb87f0d49ec957a14d7be790982119316 /indoteknik_api/controllers/api_v1 | |
| parent | fb45665e9598297dfd77054c1c3ff7c2ca9bc67d (diff) | |
| parent | 5ead14749a6be3453c71b0b053cc508facb5ab9d (diff) | |
Merged in feature/iman-categories-homepage (pull request #188)
Feature/iman categories homepage
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/category_management_lob.py | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/category_management_lob.py b/indoteknik_api/controllers/api_v1/category_management_lob.py index e453e402..0018edce 100644 --- a/indoteknik_api/controllers/api_v1/category_management_lob.py +++ b/indoteknik_api/controllers/api_v1/category_management_lob.py @@ -8,7 +8,7 @@ class BrandHomepage(controller.Controller): @http.route(prefix + 'lob_homepage', auth='public', methods=['GET', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() - def get_brand_homepage(self, **kw): + def get_lob_homepage(self, **kw): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') query = [('status', '=', 'tayang')] @@ -19,15 +19,76 @@ class BrandHomepage(controller.Controller): category_ids = [ { 'id': cat.id, - 'name': cat.name + 'name': cat.name, + 'image': base_url + 'api/image/product.public.category/image/' + str(cat.id) if cat.image else '', } for cat in category.category_ids ] data.append({ 'id': category.id, 'sequence': category.sequence, 'industries': category.category_id.name if category.category_id else '', - 'image': base_url + '/api/image/website.categories.lob/image/' + str(category.id) if category.image else '', + 'image': base_url + 'api/image/website.categories.lob/image/' + str(category.id) if category.image else '', 'category_ids': category_ids }) - return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')])
\ No newline at end of file + return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) + + @http.route(prefix + 'lob_homepage/<id>/category_id', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() + def get_lob_homepage_id(self, id, **kw): + base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') + + # Query for lob records + query = [('status', '=', 'tayang')] + if id: + query.append(('id', '=', id)) + + lob_records = request.env['website.categories.lob'].search(query) + + data = [] + for category in lob_records: + category_ids = [] + child_ids = set() # Use a set to avoid duplicate IDs + + for cat in category.category_ids: + # Add category information to the list + category_ids.append({ + 'id': cat.id, + 'name': cat.name, + 'image': base_url + 'web/image?model=x_banner.banner&id=' + str(cat.x_studio_field_7bVEO.id)+'&field=x_banner_image' if cat.image else '', + 'child_id': [] + }) + + # Find level 1 child categories with non-empty product_tmpl_ids + level_1_children = request.env['product.public.category'].search([ + ('parent_frontend_id', '=', cat.id), + ('product_tmpl_ids', '!=', False) + ]) + for child in level_1_children: + child_ids.add(child.id) + + # Find level 2 child categories with non-empty product_tmpl_ids + level_2_children = request.env['product.public.category'].search([ + ('parent_frontend_id', '=', child.id), + ('product_tmpl_ids', '!=', False) + ]) + for sub_child in level_2_children: + child_ids.add(sub_child.id) + + # Convert child_ids set to list and include the current category id + all_child_ids = list(child_ids) + for cat in category_ids: + cat['child_id'] = [cat['id']] + all_child_ids + + # Add lob record information + data.append({ + 'id': category.id, + 'sequence': category.sequence, + 'industries': category.category_id.name if category.category_id else '', + 'image': base_url + 'web/image?model=website.categories.lob' + str( + category.id) + '&field=image' if category.image else '', + 'category_ids': category_ids + }) + + # Response with formatted JSON + return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) |
