Skip to content

Cart API

This API allows users to manage their cart, including fetching cart details and deleting multiple items from the cart.


Endpoints Overview

Method Endpoint Description
GET /api/v1/cart/list/ Retrieve the user's cart details.
DELETE /api/v1/cart/list/ Delete multiple items from the user's cart.

Cart API Documentation

1. Retrieve Cart Details

Endpoint

  • URL: /api/v1/cart/list/
  • Method: GET
  • Permission Required: IsAuthenticated

Description

Retrieves the details of the authenticated user's cart, including items, subtotal, discounts, and totals.

Response Fields

  • subtotal: The total price of all items in the cart (before discounts).
  • total_discount: The total discount applied to the cart items.
  • final_total: The final price after applying discounts.
  • total_items: The total number of items in the cart.
  • items: A list of items in the cart, each containing details such as product, quantity, price, and discount.

Example Request

This is the endpoint

GET /api/v1/cart/list/


Success

{
    "id": 3,
    "user_id": 21,
    "items": [
        {
            "id": 44,
            "product": {
                "id": 34,
                "name": "New Product",
                "price": 222.0,
                "discount_percent": 22.0,
                "description": "xcvxc",
                "images": [
                    {
                        "id": 19,
                        "image": "http://127.0.0.1:8000/media/product/image/gg_pt1x1sS.png"
                    },
                    {
                        "id": 20,
                        "image": "http://127.0.0.1:8000/media/product/image/1_ss_gTsD8uy.png"
                    }
                ],
                "primary_image": "http://127.0.0.1:8000/media/product/image/gg_pt1x1sS.png"
            },
            "variant": {
                "id": 76,
                "variant_price": 222.0,
                "discounted_price": 173.16,
                "stock_quantity": 32,
                "is_available": true,
                "is_active": true,
                "variant_images": [
                    {
                        "id": 19,
                        "image": "http://127.0.0.1:8000/media/product/image/gg_pt1x1sS.png",
                        "is_primary": false
                    },
                    {
                        "id": 20,
                        "image": "http://127.0.0.1:8000/media/product/image/1_ss_gTsD8uy.png",
                        "is_primary": false
                    }
                ],
                "size": {
                    "id": 2,
                    "size": "Small",
                    "value": "S"
                }
            },
            "quantity": 1,
            "total_price": 222.0,
            "discount_amount": 48.84,
            "final_price": 173.16,
            "is_direct_purchase": false,
            "has_purchased": false,
            "created_at": "12-17-2024 10:46:07",
            "updated_at": "12-17-2024 10:46:07"
        }
    ],
    "subtotal": 222.0,
    "total_discount": 48.84,
    "final_total": 173.16,
    "total_items": 1,
    "created_at": "11-29-2024 04:34:07",
    "updated_at": "11-29-2024 04:34:07"
}


2. Delete Multiple Cart Items

Endpoint

  • URL: /api/v1/cart/list/
  • Method: DELETE
  • Permission Required: IsAuthenticated

Description

Deletes multiple items from the authenticated user's cart. The client must provide the IDs of the items to be removed.

Path Parameters

  • item_ids (Required): A list of IDs of the cart items to delete.

Example Request

This is the endpoint

DELETE /api/v1/cart/list/


Request Body

This is the request body

{
  "item_ids":[1, 2, 3]
}


Success

{
    "message": "Cart items successfully deleted"
}
Error (404 Not Found)
{
  "error": "No matching cart items found"
}

Error (404 Not Found)

{
  "error": "Cart not found"
}

Error (400 Bad Request)

{
  "error": "No item IDs provided"
}