diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-16 11:19:07 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-16 11:19:07 +0700 |
| commit | 34baf6dc9d7031fdfa196446ef4274fff03d0abc (patch) | |
| tree | f8e4fc3bf65e280df9c0b8e80982f0f9828c162c | |
| parent | eefe129e31b112d80038fc3aecf2aee4c4e10108 (diff) | |
Fix cart API
| -rw-r--r-- | indoteknik_api/controllers/api_v1/cart.py | 7 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/category.py | 2 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 8 |
4 files changed, 12 insertions, 7 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 88fa9f88..8ef2c1c1 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -14,8 +14,9 @@ class Cart(controller.Controller): user_id = int(user_id) limit = int(kw.get('limit', 0)) offset = int(kw.get('offset', 0)) - query = [('user_id', '=', user_id), ('source', '=', 'add_to_cart')] + query = [('user_id', '=', user_id)] carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc') + carts.write({'source': 'add_to_cart'}) data = { 'product_total': user_cart.search_count(query), 'products': carts.with_context(price_for="web").get_products() @@ -26,7 +27,7 @@ class Cart(controller.Controller): @controller.Controller.must_authorized() def get_cart_count_by_user_id(self, user_id, **kw): user_id = int(user_id) - query = [('user_id', '=', user_id), ('source', '=', 'add_to_cart')] + query = [('user_id', '=', user_id)] carts = request.env['website.user.cart'].search_count(query) return self.response(carts) @@ -77,7 +78,7 @@ class Cart(controller.Controller): data_to_update['source'] = source result = {} - if cart and source in (None, 'add_to_cart'): + if cart: # Update existing cart entry cart.write(data_to_update) result['id'] = cart.id diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py index efa6b033..44a60bc9 100644 --- a/indoteknik_api/controllers/api_v1/category.py +++ b/indoteknik_api/controllers/api_v1/category.py @@ -135,4 +135,4 @@ class Category(controller.Controller): category = category.parent_frontend_id categories.reverse() - return self.response(categories)
\ No newline at end of file + return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')])
\ No newline at end of file diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 0c8a286b..1b698f26 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -32,7 +32,7 @@ class Product(controller.Controller): category = category.parent_frontend_id categories.reverse() - return self.response(categories) + return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')]) @http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 47a695fe..2721d66f 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -55,11 +55,15 @@ class WebsiteUserCart(models.Model): def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) - source = source if source else 'add_to_cart' + + if source == 'buy': + source = ['buy'] + else: + source = ['add_to_cart', 'buy'] parameters = [ ('user_id', '=', user_id), - ('source', '=', source) + ('source', 'in', source) ] if selected: |
