Skip to content

Add To Basket (Login)

Add multiple product variants to the user's basket after login. This endpoint is useful for syncing a guest basket with a user account after authentication.

Endpoint

PUT /v1/products/basket/auth/?currency_id={currency_id}

Authentication

Required (User role)

Query Parameters

Parameter Type Required Description
currency_id integer Yes Currency ID for price display

Request Body

Content-Type: multipart/form-data

Form Fields

Field Type Required Description
json_data string Yes JSON string containing array of basket items

JSON Data Format

The json_data field should be a JSON string containing an array of basket items:

[
  {
    "product_variant_id": 1,
    "quantity": 2
  },
  {
    "product_variant_id": 2,
    "quantity": 1
  }
]

Response

Success (200 OK)

Returns an array of basket items:

[
  {
    "id": 1,
    "product": {
      "id": 1,
      "product_id": 5,
      "product": {...},
      "name_az": "Məhsul Adı",
      "name_en": "Product Name",
      "sku": "SKU-001",
      "stock_quantity": 100,
      "price": 29.99,
      "discount_percent": 10.0,
      "discount_price": 26.99,
      "currency_name": "AZN",
      "attributes": [
        {
          "id": 1,
          "attribute_id": 1,
          "attribute_name": "Color",
          "attribute_name_az": "Rəng",
          "attribute_name_en": "Color",
          "attribute_name_es": "Color",
          "attribute_name_de": "Farbe",
          "attribute_type": "select",
          "value": "Red",
          "value_az": "Qırmızı",
          "value_en": "Red",
          "value_es": "Rojo",
          "value_de": "Rot",
          "is_filter": true,
          "is_view": true
        }
      ],
      "images": [...],
      "is_wish": false,
      "created": "2025-01-15T10:30:00Z"
    },
    "quantity": 2
  },
  {
    "id": 2,
    "product": {
      "id": 2,
      "product_id": 6,
      "product": {...},
      "name_az": "Məhsul Adı 2",
      "name_en": "Product Name 2",
      "sku": "SKU-002",
      "stock_quantity": 50,
      "price": 19.99,
      "discount_percent": 0.0,
      "discount_price": 19.99,
      "currency_name": "AZN",
      "attributes": [
        {
          "id": 1,
          "attribute_id": 1,
          "attribute_name": "Color",
          "attribute_name_az": "Rəng",
          "attribute_name_en": "Color",
          "attribute_name_es": "Color",
          "attribute_name_de": "Farbe",
          "attribute_type": "select",
          "value": "Red",
          "value_az": "Qırmızı",
          "value_en": "Red",
          "value_es": "Rojo",
          "value_de": "Rot",
          "is_filter": true,
          "is_view": true
        }
      ],
      "images": [...],
      "is_wish": false,
      "created": "2025-01-15T10:30:00Z"
    },
    "quantity": 1
  }
]

Error Responses

Product Not Found (404)

{
  "error": "Product Not Found"
}

Insufficient Stock (400)

{
  "error": "Not enough stock available for this product"
}

Example Request

curl -X PUT "https://api.luxmart.site/v1/products/basket/auth/?currency_id=1" \
  -H "Authorization: Token your_access_token" \
  -F 'json_data=[{"product_variant_id":1,"quantity":2},{"product_variant_id":2,"quantity":1}]'

Notes

  • If a product variant already exists in the basket, its quantity is updated
  • If a product variant doesn't exist, it's added to the basket
  • Stock quantity is validated for each item
  • Price is converted to specified currency if currency_id is provided
  • discount_percent is the discount percentage (0 if no discount)
  • discount_price is the final price after discount (calculated from converted price if currency_id is provided)
  • Useful for syncing guest basket data after user login