Skip to content

Move to Cart API

MoveToCartView

Overview The MoveToCartView is an API view for moving products from the user's wishlist to their shopping cart. It checks stock availability, ensures variants are available, and creates cart items for valid products.

Action post(self, request) Endpoint: api/v1/wishlist/move-to-cart/
Method: GET
Permissions: IsAuthenticated - POST: This action moves the selected wishlist items to the user's cart. - Request Body: A list of product IDs to be moved.

{
    "product_ids": [1, 2]
}
- Permissions: Only authenticated users can access this endpoint. - Logic: - The products in the wishlist are validated and checked for stock availability. - If the product's variant is available, a new cart item is created for the user. - The product is then removed from the wishlist.

Response: - Returns a message with the results of the operation. - Indicates which products were successfully moved to the cart, which were already in the cart, and which had stock issues.

{
    "message": "Items moved to cart",
    "moved_items": [1, 2],
    "already_in_cart": [3],
    "stock_unavailable": [4]
}

Example Usage

{
"product_ids": [1, 2]
}