diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-26 15:07:27 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-26 15:07:27 +0700 |
| commit | c86979fd504ee06dc19c69797159a13295b0c809 (patch) | |
| tree | f271661fbc2947073d48cc67c3eb4901692d1643 /indoteknik_api/controllers/api_v1/cart.py | |
| parent | 01f308991afffaff5eda1b758dbb98d0f3ba8396 (diff) | |
| parent | d324fdd8ea3b14c966510bde610a96c8f5c3e3c5 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_api/controllers/api_v1/cart.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/cart.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 3b15e778..cb0f5a99 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -31,7 +31,7 @@ class Cart(controller.Controller): return self.response(carts) @http.route(PREFIX_USER + 'cart/create-or-update', auth='public', methods=['POST', 'OPTIONS'], csrf=False) - @controller.Controller.must_authorized() + @controller.Controller.must_authorized(private=True, private_key='user_id') def create_or_update_cart(self, user_id, **kw): # Convert input values to appropriate types user_id = int(user_id) @@ -54,19 +54,29 @@ class Cart(controller.Controller): user_query = ('user_id', '=', user_id) website_user_cart.search([user_query, ('source', '=', 'buy')]).unlink() - # Prepare query to find existing cart entry for the product - query = [user_query, ('product_id', '=', product_id), ('source', '=', 'add_to_cart')] + # Prepare query to find existing cart entry + query = [user_query, ('source', '=', 'add_to_cart')] + if product_id: + query.append(('product_id', '=', product_id)) + elif program_line_id: + query.append(('program_line_id', '=', program_line_id)) + cart = website_user_cart.search(query, limit=1) - result = {} + data_to_update = { 'qty': qty, 'is_selected': is_selected, - 'program_line_id': program_line_id + 'program_line_id': program_line_id, + 'product_id': product_id } + if program_line_id: + data_to_update['product_id'] = False + if source: data_to_update['source'] = source + result = {} if cart and source in (None, 'add_to_cart'): # Update existing cart entry cart.write(data_to_update) @@ -75,7 +85,6 @@ class Cart(controller.Controller): # Create a new cart entry if it doesn't exist create = website_user_cart.create({ 'user_id': user_id, - 'product_id': product_id, **data_to_update }) result['id'] = create.id |
