> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# Basket

> Reference for WEBSALE basket actions used to add, update and remove products as well as redeem and remove vouchers in the shopping cart.

This section describes the available actions in the basket area. With these actions, products can be added, updated, and removed, and vouchers can be managed.

***

## Actions overview

| **Action**         | **Description**                                  |
| ------------------ | ------------------------------------------------ |
| `BasketItemAdd`    | Adds a product to the basket.                    |
| `BasketItemUpdate` | Updates the quantity of a product in the basket. |
| `BasketItemDelete` | Removes a product from the basket.               |
| `VoucherAdd`       | Redeems a voucher code in the basket.            |
| `VoucherDelete`    | Removes a redeemed voucher from the basket.      |

***

## Actions

### BasketItemAdd

This action adds a product to the basket.

**Usage example**\
Can be used on product detail, category, or watchlist pages where products can be added directly to the basket.

**Parameters**

| **Name**                 | **Description**                                                                 |
| ------------------------ | ------------------------------------------------------------------------------- |
| `productId`              | The ID of the product to be added to the basket.                                |
| `quantity`               | The desired quantity of the product.                                            |
| `freeFieldscategoryPath` | Optional free field for passing the category path, e.g., for tracking purposes. |

**Error codes**

| **Error code**     | **Description**                                 |
| ------------------ | ----------------------------------------------- |
| `missingProductId` | Parameter `productId` is missing.               |
| `invalidProductId` | The product does not exist or is not available. |

**Related modules, variables & methods**

* [\$wsBasket](/en/frontend/referenz/module/wsbasket)
* [\$wsBasket.items](/en/frontend/referenz/module/wsbasket#\$wsbasket-items)
* [\$wsBasket.lastBasketAction](/en/frontend/referenz/module/wsbasket#\$wsbasket-lastbasketaction)
* [\$wsBasket.lastUpdatedItem](/en/frontend/referenz/module/wsbasket#\$wsbasket-lastupdateditem)

**Example** showing how a product with quantity selection is added to the basket and a confirmation message appears after successful execution.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsActions.current.success and $wsActions.current.name == "BasketItemAdd" }}
    <div class="alert alert-success">Product added to basket.</div>
{{ /if }}

{{ var $myActionBasketItemAdd = $wsActions.create("BasketItemAdd") }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionBasketItemAdd.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionBasketItemAdd.id }}">
    <input type="hidden" name="productId" value="{{= $cProduct.id }}">
    <input type="text" name="quantity" value="1">
    <button type="submit">Add to basket.</button>
</form>
```

***

### BasketItemUpdate

This action updates the quantity of a product already in the basket.

**Usage example**\
Can be used on the basket page or in the basket offcanvas when customers want to adjust the quantity of a product that has already been added.

**Parameters**

| **Name**       | **Description**                                             |
| -------------- | ----------------------------------------------------------- |
| `basketItemId` | The ID of the basket entry whose quantity is to be updated. |
| `quantity`     | The new quantity of the product.                            |

**Error codes**

| **Error code**        | **Description**                                                    |
| --------------------- | ------------------------------------------------------------------ |
| `missingBasketItemId` | Parameter `basketItemId` is missing.                               |
| `invalidBasketItemId` | The basket entry does not exist or does not belong to this basket. |
| `missingQuantity`     | Parameter `quantity` is missing.                                   |

**Related modules, variables & methods**

* [\$wsBasket](/en/frontend/referenz/module/wsbasket)
* [\$wsBasket.items](/en/frontend/referenz/module/wsbasket#\$wsbasket-items)
* [\$wsBasket.lastBasketAction](/en/frontend/referenz/module/wsbasket#\$wsbasket-lastbasketaction)
* [\$wsBasket.lastUpdatedItem](/en/frontend/referenz/module/wsbasket#\$wsbasket-lastupdateditem)

**Example** showing how the quantity of a basket entry is updated via a form.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionBasketItemUpdate = $wsActions.create("BasketItemUpdate", tag = $myProduct.id) }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionBasketItemUpdate.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionBasketItemUpdate.id }}">
    <input type="hidden" name="basketItemId" value="{{= $myProduct.id }}">
    <input type="text" name="quantity" value="{{= $myProduct.quantity | preparedFormat('amount') }}">
    <button type="submit">Update quantity.</button>
</form>
```

***

### BasketItemDelete

This action removes a product from the basket.

**Usage example**\
Can be used on the basket page or in the basket offcanvas when customers want to remove a product completely from the basket.

**Parameters**

| **Name**       | **Description**                           |
| -------------- | ----------------------------------------- |
| `basketItemId` | The ID of the basket entry to be removed. |
| `productId`    | The ID of the product to be removed.      |
| `quantity`     | The current quantity of the product.      |

**Error codes**

| **Error code**        | **Description**                                                    |
| --------------------- | ------------------------------------------------------------------ |
| `missingBasketItemId` | Parameter `basketItemId` is missing.                               |
| `invalidBasketItemId` | The basket entry does not exist or does not belong to this basket. |

**Related modules, variables & methods**

* [\$wsBasket](/en/frontend/referenz/module/wsbasket)
* [\$wsBasket.items](/en/frontend/referenz/module/wsbasket#\$wsbasket-items)
* [\$wsBasket.lastBasketAction](/en/frontend/referenz/module/wsbasket#\$wsbasket-lastbasketaction)
* [\$wsBasket.lastUpdatedItem](/en/frontend/referenz/module/wsbasket#\$wsbasket-lastupdateditem)

**Example** showing how a product is removed from the basket via a button.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionBasketItemDelete = $wsActions.create("BasketItemDelete", tag = $myProduct.id) }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionBasketItemDelete.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionBasketItemDelete.id }}">
    <input type="hidden" name="basketItemId" value="{{= $myProduct.id }}">
    <input type="hidden" name="productId" value="{{= $myProduct.product.id }}">
    <input type="hidden" name="quantity" value="{{= $myProduct.quantity | preparedFormat('amount') }}">
    <button type="submit">Remove product.</button>
</form>
```
