Skip to main content

Cart Operations

This documentation covers the endpoints for managing products in the customer's cart, including adding new items and removing existing ones.

Add to Cart

Add a product (course, ebook, bundle, or course videos) to the customer's cart.

Endpoint

POST /v1/customer/cart

Request Parameters

ParameterTypeRequiredDescription
product_idstringYesThe ID of the product to add to cart
product_typestringYesType of product. Must be one of: course, ebook, bundle, course_videos
gift_idstringNoID of an existing gift if this is a gift purchase
refstringNoAffiliate reference code for tracking affiliate-driven purchases
promo_codestringNoPromotion code for tracking promotional campaign statistics

Response

Success Response

{
"success": true,
"message": "تمت إضافة المنتج للسلة بنجاح",
"data": {
"cart_count": 3
},
"status_code": 200
}

Error Responses

{
"success": false,
"message": "هذا المنتج موجود في السلة مسبقًا",
"errors": "هذا المنتج موجود في السلة مسبقًا",
"data": null,
"status_code": 422
}

Special Features

Affiliate Tracking

When ref parameter is provided:

  • Validates if the affiliate exists and is active
  • Checks if the affiliate is allowed for the product category
  • Associates the cart item with the affiliate for commission tracking
  • Prevents self-referral (affiliate cannot use their own code)

Promotion Codes

When promo_code parameter is provided:

  • Validates if the promotion code exists and is active
  • Tracks promotion usage statistics
  • Used for analyzing promotional campaign effectiveness

Gift Purchases

When gift_id parameter is provided:

  • Validates if the gift exists
  • Associates the cart item with the gift
  • Bypasses subscription and free product checks

Notes

  • A product cannot be added to cart if:
    • It's already in the customer's cart
    • The customer is already subscribed to it
    • It's free or has a reduced price and the customer qualifies for the reduction
    • The customer has already sent a product request for it
  • For course videos, if the customer has an active subscription, only unwatched videos can be added to cart
  • The endpoint supports both UUID and special_id for product identification

Remove from Cart

Remove a product from the customer's cart.

Endpoint

DELETE /v1/customer/cart/delete-product/{id}

Path Parameters

ParameterTypeDescription
idstringThe ID of the cart item to remove. Supports both UUID and special_id

Response

Success Response

{
"success": true,
"message": "تم حذف البيانات بنجاح.",
"data": null,
"status_code": 200
}

Special Features

Course Videos Handling

When removing a course video from cart:

  • All related videos from the same course are automatically removed
  • This ensures consistency in course video purchases

Gift Cleanup

When removing a gift purchase from cart:

  • Associated gift records are automatically cleaned up
  • Prevents orphaned gift records in the system

Notes

  • The endpoint supports both UUID and special_id for cart item identification
  • Automatically handles cleanup of related records (gifts, course videos)