> ## 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.

# $wsBasket - Basket

> Read basket data in the frontend: line items, quantities, amounts, discounts, tax information, and insert codes for mini-cart, summary, and checkout.

The `$wsBasket` module lets you read the data of the current basket in the frontend. This includes the contained products (line items), their quantities and prices, as well as the calculated totals and tax information.

This page is about reading the basket data. Everything that changes the basket (add product, change quantity, remove) is described under [Actions → Basket](/en/frontend/referenz/aktionen/basket), because the triggering actions and their parameters are documented there.

***

## Basic concept

The basket stores the products selected by the customer and automatically calculates quantities, prices, and taxes. Through this module you can read these values and display them.

### Structure

The basket data is nested in three levels:

* **Basket** (`$wsBasket`) - the totals across all line items, e.g. `total` or [`totalQuantity`](#wsbasket-totalquantity).
* **Line items** (`$wsBasket.items`) - a list of basket entries. Each entry represents a product in the basket and has its own values such as quantity and item total.
* **Product** (`item.product`) - within each line item there is also the associated product with its master data (name, image, ID).

So you read totals from the basket, item-related values from the respective line item, and product details from the product of the line item.

### Tax exemption

Several variables together represent the tax exemption and belong together in terms of content: [`isTaxExempt`](#wsbasket-istaxexempt) is the primary switch, [`totalTaxDeduction`](#wsbasket-totaltaxdeduction) and [`totalPreDeduction`](#wsbasket-totalprededuction) provide the amounts for a "minus VAT" line, and [`usedExemptionRule`](#wsbasket-usedexemptionrule) together with [`billingCountry`](#wsbasket-billingcountry)/[`shippingCountry`](#wsbasket-shippingcountry) shows which addresses are used for the check. For tax notices, always check `isTaxExempt` first.

### Insert code

When [insert codes](/en/frontend/funktionsubersicht/werbemittelkennzeichnung) are enabled in the shop, each line item also carries the captured insert code. There are two fields for this: [`insert`](#wsbasket-items) returns the plain code, [`itemNumberWithInsert`](#wsbasket-items) returns the fully composed display of product number and code in the configured order and with the configured separator. If no code is set, `itemNumberWithInsert` simply contains the plain product number.

As a rule, it is enough to output `itemNumberWithInsert` as the item number – position and separator are already taken into account. Additional output around the insert code (for example, a separate code label) belongs inside `{{ if $wsConfig.inserts.enabled }} … {{ /if }}`, so nothing appears when the feature is disabled. The settings are provided by [\$wsConfig.inserts](/en/frontend/referenz/module/wsconfig#wsconfig-inserts).

### Timing and last updated item

The template code runs when the page is built. Therefore, `$wsBasket` contains the basket state after the last executed action. [`lastBasketAction`](#wsbasket-lastbasketaction) and `lastUpdatedItem` describe this last change. Useful, for example, to display feedback such as "Product X was added" directly after adding.

***

## Module overview

**Example / excerpt of** `$wsBasket`

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{= $wsBasket | json }}
```

**JSON output**

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "billingCountry": "...",
  "isTaxExempt": true,
  "items": [
    {
      "discountPrice": 0.0,
      "freeFields": { },
      "id": "...",
      "insert": "...",
      "itemNumberWithInsert": "...",
      "oneTimeFee": 0.0,
      "orgPrice": 0.0,
      "price": 0.0,
      "product": { },
      "quantity": 0.0,
      "total": 0.0,
      "totalGross": 0.0,
      "totalNet": 0.0,
      "totalTax": 0.0,
      "voucherIds": [...]
    }
  ],
  "lastBasketAction": "...",
  "lastUpdatedItem": {
    "categories": [...],
    "freeFields": { },
    "id": "...",
    "parentCategories": [...],
    "price": 0.0,
    "productNumber": "...",
    "quantity": 0.0,
    "taxId": "...",
    "voucherIds": [...]
  },
  "shippingCountry": "...",
  "total": 0.0,
  "totalCommission": 0.0,
  "totalGross": 0.0,
  "totalNet": 0.0,
  "totalQuantity": 0.0,
  "totalTax": 0.0,
  "totalTaxDeduction": 0.0,
  "totalPreDeduction": 0.0,
  "totalWeight": 0.0,
  "usedExemptionRule": "..."
}
```

**Basket variables (top level)**

| **Variable**        | **Return type** | **Description**                                                     |
| ------------------- | --------------- | ------------------------------------------------------------------- |
| `totalQuantity`     | float           | Total quantity of all products in the basket.                       |
| `total`             | float           | Total amount of the basket.                                         |
| `totalNet`          | float           | Net amount of the basket.                                           |
| `totalGross`        | float           | Gross amount of the basket.                                         |
| `totalTax`          | float           | VAT of the basket.                                                  |
| `totalCommission`   | float           | Total commission.                                                   |
| `totalWeight`       | float           | Total weight of all products in the basket.                         |
| `lastBasketAction`  | string          | Last action on the basket (e.g. `"add"`, `"remove"`, `"update"`).   |
| `lastUpdatedItem`   | map             | Most recently changed item (structure see below).                   |
| `items`             | array           | List of all basket entries (structure see below).                   |
| `isTaxExempt`       | bool            | Whether the current basket is tax-exempt.                           |
| `totalTaxDeduction` | float           | Amount of deducted tax; only > 0 when a tax exemption is active.    |
| `totalPreDeduction` | float           | Total amount before the tax deduction.                              |
| `billingCountry`    | string          | Country code of the billing address (e.g. `"DE"`).                  |
| `shippingCountry`   | string          | Country code of the shipping address (e.g. `"DE"`).                 |
| `usedExemptionRule` | string          | Active tax check rule (`"shippingOnly"` or `"shippingAndBilling"`). |

***

## Templates

The basket data can be displayed on every page of the shop. Common presentations are:

* **Offcanvas basket:** in a sidebar, as a flyout, or as an off-canvas element, for a quick overview.
* **Basket page:** a detailed overview with adjustment options.
* **Checkout and order confirmation:** display during the purchase process and in confirmation emails.

***

## Variables

### \$wsBasket.totalQuantity

Returns the total quantity of all products in the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Items in the basket: {{= $wsBasket.totalQuantity }}
```

### \$wsBasket.total

Returns the total amount of the basket. Use it for the final total in basket and checkout.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Total amount: {{= $wsBasket.total | currency }}
```

### \$wsBasket.totalNet

Returns the net amount of the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Net amount: {{= $wsBasket.totalNet | currency }}
```

### \$wsBasket.totalGross

Returns the gross amount of the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Gross amount: {{= $wsBasket.totalGross | currency }}
```

### \$wsBasket.totalTax

Returns the VAT of the basket. Use it for a separate tax line in the totals overview.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
VAT: {{= $wsBasket.totalTax | currency }}
```

### \$wsBasket.totalCommission

Returns the total commission of the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Commission: {{= $wsBasket.totalCommission | currency }}
```

### \$wsBasket.totalWeight

Returns the total weight of all products in the basket. Useful, for example, to display a shipping cost or weight notice.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Total weight: {{= $wsBasket.totalWeight }}
```

### \$wsBasket.lastBasketAction

Returns the action most recently performed on the basket (e.g. `"add"`, `"remove"`, `"update"`). Evaluate it to display appropriate feedback after a change.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Last action: {{= $wsBasket.lastBasketAction }}
```

### \$wsBasket.lastUpdatedItem

Returns the most recently added or changed item. Use it together with `lastBasketAction` to display, for example, "Product X was added" directly after adding, without having to search through the entire basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Most recently changed: {{= $wsBasket.lastUpdatedItem.id }}
Quantity: {{= int($wsBasket.lastUpdatedItem.quantity) }}
```

#### Properties of `$wsBasket.lastUpdatedItem`

| **Property**       | **Return type** | **Description**                            |
| ------------------ | --------------- | ------------------------------------------ |
| `id`               | string          | Product ID of the item.                    |
| `productNumber`    | string          | Item number of the item.                   |
| `price`            | float           | Price of the item.                         |
| `quantity`         | float           | Quantity of the item.                      |
| `taxId`            | string          | Tax rate ID of the item.                   |
| `categories`       | array           | Category IDs in which the item is located. |
| `parentCategories` | array           | Parent category IDs of the item.           |
| `freeFields`       | map             | Free fields of the item.                   |
| `voucherIds`       | array           | Applied voucher IDs for the item.          |

### \$wsBasket.items

Returns the list of all basket entries (line items). Iterate over this list to display each line item individually.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ foreach $item in $wsBasket.items }}
  Item: {{= $item.product.name }} – Quantity: {{= int($item.quantity) }}
{{ /foreach }}
```

#### Properties of an entry in `$wsBasket.items`

| **Property**           | **Return type** | **Description**                                                                                                                                                  |
| ---------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                   | string          | Basket ID of the entry.                                                                                                                                          |
| `product`              | map             | The associated product of the entry (master data such as name, image, ID).                                                                                       |
| `insert`               | string          | The [insert code](/en/frontend/funktionsubersicht/werbemittelkennzeichnung) of the entry. Empty when no code is set.                                             |
| `itemNumberWithInsert` | string          | Fully composed display of product number and insert code in the configured order with separator. If no code is set, the field contains the plain product number. |
| `quantity`             | float           | Quantity of the entry.                                                                                                                                           |
| `price`                | float           | Unit price of the entry.                                                                                                                                         |
| `orgPrice`             | float           | Original price before discounts.                                                                                                                                 |
| `discountPrice`        | float           | Discounted price (if a discount is active).                                                                                                                      |
| `oneTimeFee`           | float           | One-time fee (e.g. setup costs).                                                                                                                                 |
| `total`                | float           | Total amount of the entry (item total).                                                                                                                          |
| `totalNet`             | float           | Net amount of the entry.                                                                                                                                         |
| `totalGross`           | float           | Gross amount of the entry.                                                                                                                                       |
| `totalTax`             | float           | VAT of the entry.                                                                                                                                                |
| `freeFields`           | map             | Free fields (e.g. labels, comments).                                                                                                                             |
| `voucherIds`           | array           | Applied voucher IDs for this entry.                                                                                                                              |

### \$wsBasket.isTaxExempt

Returns whether the current basket is tax-exempt. This is the primary indicator for a tax exemption – use it, for example, to show a notice "Tax-exempt delivery".

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.isTaxExempt }}
  This basket is tax-exempt.
{{ /if }}
```

### \$wsBasket.totalTaxDeduction

Returns the amount of deducted tax. The value is only greater than 0 when a tax exemption is active. In gross shops, you can use it, for example, to display a line "minus VAT".

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.totalTaxDeduction > 0 }}
  Tax deduction: {{= $wsBasket.totalTaxDeduction | currency }}
{{ /if }}
```

### \$wsBasket.totalPreDeduction

Returns the total amount before the tax deduction. Together with `totalTaxDeduction`, you can show the amount before and after the deduction.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Amount before tax deduction: {{= $wsBasket.totalPreDeduction | currency }}
```

### \$wsBasket.billingCountry

Returns the country code of the billing address (e.g. `"DE"` for Germany).

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Billing country: {{= $wsBasket.billingCountry }}
```

### \$wsBasket.shippingCountry

Returns the country code of the shipping address (e.g. `"DE"` for Germany).

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Shipping country: {{= $wsBasket.shippingCountry }}
```

### \$wsBasket.usedExemptionRule

Returns the active tax check rule. Possible values: `"shippingOnly"` (only the shipping address is checked) or `"shippingAndBilling"` (shipping and billing addresses are checked). This shows you which addresses determine the tax exemption.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.usedExemptionRule }}
  Active check rule: {{= $wsBasket.usedExemptionRule }}
{{ /if }}
```

***

## Methods

No methods are available for `$wsBasket`.

***

## Actions

Actions that change the basket (add product, change quantity, remove) are documented separately: [Actions → Basket](/en/frontend/referenz/aktionen/basket).

***

## Examples for data access

### Check whether products are in the basket

First check whether any line items exist at all before displaying the basket, otherwise you would show an empty list.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.items }}
  <p>The basket contains {{= $wsBasket.items | len }} line items.</p>
{{ else }}
  <p>You have no products in the basket yet.</p>
{{ /if }}
```

**Result** <br />If the basket is filled, the number of line items appears, otherwise a notice about the empty basket.

### Display products in the basket

If line items are present, iterate over `items` and show product name, quantity, and prices for each line item. The totals are placed outside the loop because they would otherwise be output again for each line item.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.items }}
  {{ foreach $item in $wsBasket.items }}
    <a href="{{= $wsViews.url('Product', {productId: $item.product.id}) }}">
      <img src="{{= $item.product.custom.image.normal }}" alt="{{= $item.product.name }}">
    </a>
    <p>Product name: {{= $item.product.name }}</p>
    <p>Item no.: {{= $item.itemNumberWithInsert }}</p>
    <p>Quantity: {{= int($item.quantity) }}</p>
    <p>Unit price: {{= $item.price | currency }}</p>
    <p>Item total: {{= $item.total | currency }}</p>
  {{ /foreach }}

  <p>Shipping costs: {{= $wsCheckout.sum.shippingCost | currency }}</p>
  <p>Grand total: {{= $wsBasket.total | currency }}</p>
{{ else }}
  <p>You have no products in the basket!</p>
{{ /if }}
```

**Result** <br />Each line item is listed with image, name, item number (including the insert code, if captured), quantity, and prices. Below, the shipping costs and grand total appear once.

### Output the insert code separately

If the plain code should also appear as its own field alongside the item number, first check via [`$wsConfig.inserts.enabled`](/en/frontend/referenz/module/wsconfig#wsconfig-inserts) whether the feature is active, so nothing appears when it is disabled.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsConfig.inserts.enabled }}
  {{ foreach $item in $wsBasket.items }}
    {{ if $item.insert }}
      <p>Insert code: {{= $item.insert }}</p>
    {{ /if }}
  {{ /foreach }}
{{ /if }}
```

**Result** <br />The insert code only appears when the feature is active and only for line items that carry a code.

### Link to the basket page

Creates a link to the basket page, which is implemented via the view template `basket.htm`.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<a href="{{= $wsViews.viewUrl('basket.htm') }}">View basket</a>
```

**Result** <br />The link leads to the basket page of the shop.

***

## Further links

* [Insert code](/en/frontend/funktionsubersicht/werbemittelkennzeichnung) – conceptual overview of insert codes: capture paths, resolution logic, and setup.
* [Actions → Basket](/en/frontend/referenz/aktionen/basket) – change the basket (add, modify, remove), because `$wsBasket` itself only reads.
* [\$wsCheckout](/en/frontend/referenz/module/wscheckout) – provides supplementary values such as the shipping costs (`sum.shippingCost`) for the totals display.
* [\$wsViews](/en/frontend/referenz/module/wsviews) – generates the product and view URLs used in the examples.
* [Practical examples basket](/en/frontend/praxisbeispiele/warenkorb-funktionen) – end-to-end practical examples for basket functions.

The `$wsBasket` module lets you read the data of the current basket in the frontend. This includes the contained products (line items), their quantities and prices, as well as the calculated totals and tax information.

This page is about reading the basket data. Everything that changes the basket (add product, change quantity, remove) is described under [Actions → Basket](/en/frontend/referenz/aktionen/basket), because the triggering actions and their parameters are documented there.

***

## Basic concept

The basket stores the products selected by the customer and automatically calculates quantities, prices, and taxes. Through this module you can read these values and display them.

### Structure

The basket data is nested in three levels:

* **Basket** (`$wsBasket`) - the totals across all line items, e.g. `total` or [`totalQuantity`](#wsbasket-totalquantity).
* **Line items** (`$wsBasket.items`) - a list of basket entries. Each entry represents a product in the basket and has its own values such as quantity and item total.
* **Product** (`item.product`) - within each line item there is also the associated product with its master data (name, image, ID).

So you read totals from the basket, item-related values from the respective line item, and product details from the product of the line item.

### Tax exemption

Several variables together represent the tax exemption and belong together in terms of content: [`isTaxExempt`](#wsbasket-istaxexempt) is the primary switch, [`totalTaxDeduction`](#wsbasket-totaltaxdeduction) and [`totalPreDeduction`](#wsbasket-totalprededuction) provide the amounts for a "minus VAT" line, and [`usedExemptionRule`](#wsbasket-usedexemptionrule) together with [`billingCountry`](#wsbasket-billingcountry)/[`shippingCountry`](#wsbasket-shippingcountry) shows which addresses are used for the check. For tax notices, always check `isTaxExempt` first.

### Timing and last updated item

The template code runs when the page is built. Therefore, `$wsBasket` contains the basket state after the last executed action. [`lastBasketAction`](#wsbasket-lastbasketaction) and `lastUpdatedItem` describe this last change. Useful, for example, to display feedback such as "Product X was added" directly after adding.

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "billingCountry": "...",
  "isTaxExempt": true,
  "items": [
    {
      "discountPrice": 0.0,
      "freeFields": { },
      "id": "...",
      "oneTimeFee": 0.0,
      "orgPrice": 0.0,
      "price": 0.0,
      "product": { },
      "quantity": 0.0,
      "total": 0.0,
      "totalGross": 0.0,
      "totalNet": 0.0,
      "totalTax": 0.0,
      "voucherIds": [...]
    }
  ],
  "lastBasketAction": "...",
  "lastUpdatedItem": {
    "categories": [...],
    "freeFields": { },
    "id": "...",
    "parentCategories": [...],
    "price": 0.0,
    "productNumber": "...",
    "quantity": 0.0,
    "taxId": "...",
    "voucherIds": [...]
  },
  "shippingCountry": "...",
  "total": 0.0,
  "totalCommission": 0.0,
  "totalGross": 0.0,
  "totalNet": 0.0,
  "totalQuantity": 0.0,
  "totalTax": 0.0,
  "totalTaxDeduction": 0.0,
  "totalPreDeduction": 0.0,
  "totalWeight": 0.0,
  "usedExemptionRule": "..."
}
```

**Basket variables (top level)**

| **Variable**        | **Return type** | **Description**                                                     |
| ------------------- | --------------- | ------------------------------------------------------------------- |
| `totalQuantity`     | float           | Total quantity of all products in the basket.                       |
| `total`             | float           | Total amount of the basket.                                         |
| `totalNet`          | float           | Net amount of the basket.                                           |
| `totalGross`        | float           | Gross amount of the basket.                                         |
| `totalTax`          | float           | VAT of the basket.                                                  |
| `totalCommission`   | float           | Total commission.                                                   |
| `totalWeight`       | float           | Total weight of all products in the basket.                         |
| `lastBasketAction`  | string          | Last action on the basket (e.g. `"add"`, `"remove"`, `"update"`).   |
| `lastUpdatedItem`   | map             | Most recently changed item (structure see below).                   |
| `items`             | array           | List of all basket entries (structure see below).                   |
| `isTaxExempt`       | bool            | Whether the current basket is tax-exempt.                           |
| `totalTaxDeduction` | float           | Amount of deducted tax; only > 0 when a tax exemption is active.    |
| `totalPreDeduction` | float           | Total amount before the tax deduction.                              |
| `billingCountry`    | string          | Country code of the billing address (e.g. `"DE"`).                  |
| `shippingCountry`   | string          | Country code of the shipping address (e.g. `"DE"`).                 |
| `usedExemptionRule` | string          | Active tax check rule (`"shippingOnly"` or `"shippingAndBilling"`). |

The basket data can be displayed on every page of the shop. Common presentations are:

* **Offcanvas basket:** in a sidebar, as a flyout, or as an off-canvas element, for a quick overview.
* **Basket page:** a detailed overview with adjustment options.
* **Checkout and order confirmation:** display during the purchase process and in confirmation emails.

### \$wsBasket.total

Returns the total amount of the basket. Use it for the final total in basket and checkout.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Total amount: {{= $wsBasket.total | currency }}
```

### \$wsBasket.totalNet

Returns the net amount of the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Net amount: {{= $wsBasket.totalNet | currency }}
```

### \$wsBasket.totalGross

Returns the gross amount of the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Gross amount: {{= $wsBasket.totalGross | currency }}
```

Returns the VAT of the basket. Use it for a separate tax line in the totals overview.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
VAT: {{= $wsBasket.totalTax | currency }}
```

### \$wsBasket.totalCommission

Returns the total commission of the basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Commission: {{= $wsBasket.totalCommission | currency }}
```

### \$wsBasket.totalWeight

Returns the total weight of all products in the basket. Useful, for example, to display a shipping cost or weight notice.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Total weight: {{= $wsBasket.totalWeight }}
```

### \$wsBasket.lastBasketAction

Returns the action most recently performed on the basket (e.g. `"add"`, `"remove"`, `"update"`). Evaluate it to display appropriate feedback after a change.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Last action: {{= $wsBasket.lastBasketAction }}
```

### \$wsBasket.lastUpdatedItem

Returns the most recently added or changed item. Use it together with `lastBasketAction` to display, for example, "Product X was added" directly after adding, without having to search through the entire basket.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Most recently changed: {{= $wsBasket.lastUpdatedItem.id }}
Quantity: {{= int($wsBasket.lastUpdatedItem.quantity) }}
```

#### Properties of `$wsBasket.lastUpdatedItem`

| **Property**       | **Return type** | **Description**                            |
| ------------------ | --------------- | ------------------------------------------ |
| `id`               | string          | Product ID of the item.                    |
| `productNumber`    | string          | Item number of the item.                   |
| `price`            | float           | Price of the item.                         |
| `quantity`         | float           | Quantity of the item.                      |
| `taxId`            | string          | Tax rate ID of the item.                   |
| `categories`       | array           | Category IDs in which the item is located. |
| `parentCategories` | array           | Parent category IDs of the item.           |
| `freeFields`       | map             | Free fields of the item.                   |
| `voucherIds`       | array           | Applied voucher IDs for the item.          |

### \$wsBasket.items

Returns the list of all basket entries (line items). Iterate over this list to display each line item individually.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ foreach $item in $wsBasket.items }}
  Item: {{= $item.product.name }} – Quantity: {{= int($item.quantity) }}
{{ /foreach }}
```

#### Properties of an entry in `$wsBasket.items`

| **Property**    | **Return type** | **Description**                                                            |
| --------------- | --------------- | -------------------------------------------------------------------------- |
| `id`            | string          | Basket ID of the entry.                                                    |
| `product`       | map             | The associated product of the entry (master data such as name, image, ID). |
| `quantity`      | float           | Quantity of the entry.                                                     |
| `price`         | float           | Unit price of the entry.                                                   |
| `orgPrice`      | float           | Original price before discounts.                                           |
| `discountPrice` | float           | Discounted price (if a discount is active).                                |
| `oneTimeFee`    | float           | One-time fee (e.g. setup costs).                                           |
| `total`         | float           | Total amount of the entry (item total).                                    |
| `totalNet`      | float           | Net amount of the entry.                                                   |
| `totalGross`    | float           | Gross amount of the entry.                                                 |
| `totalTax`      | float           | VAT of the entry.                                                          |
| `freeFields`    | map             | Free fields (e.g. labels, comments).                                       |
| `voucherIds`    | array           | Applied voucher IDs for this entry.                                        |

### \$wsBasket.isTaxExempt

Returns whether the current basket is tax-exempt. This is the primary indicator for a tax exemption – use it, for example, to show a notice "Tax-exempt delivery".

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.isTaxExempt }}
  This basket is tax-exempt.
{{ /if }}
```

### \$wsBasket.totalTaxDeduction

Returns the amount of deducted tax. The value is only greater than 0 when a tax exemption is active. In gross shops, you can use it, for example, to display a line "minus VAT".

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.totalTaxDeduction > 0 }}
  Tax deduction: {{= $wsBasket.totalTaxDeduction | currency }}
{{ /if }}
```

### \$wsBasket.totalPreDeduction

Returns the total amount before the tax deduction. Together with `totalTaxDeduction`, you can show the amount before and after the deduction.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Amount before tax deduction: {{= $wsBasket.totalPreDeduction | currency }}
```

### \$wsBasket.billingCountry

Returns the country code of the billing address (e.g. `"DE"` for Germany).

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Billing country: {{= $wsBasket.billingCountry }}
```

### \$wsBasket.shippingCountry

Returns the country code of the shipping address (e.g. `"DE"` for Germany).

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Shipping country: {{= $wsBasket.shippingCountry }}
```

### \$wsBasket.usedExemptionRule

Returns the active tax check rule. Possible values: `"shippingOnly"` (only the shipping address is checked) or `"shippingAndBilling"` (shipping and billing addresses are checked). This shows you which addresses determine the tax exemption.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.usedExemptionRule }}
  Active check rule: {{= $wsBasket.usedExemptionRule }}
{{ /if }}
```

Actions that change the basket (add product, change quantity, remove) are documented separately: [Actions → Basket](/en/frontend/referenz/aktionen/basket).

First check whether any line items exist at all before displaying the basket, otherwise you would show an empty list.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.items }}
  <p>The basket contains {{= $wsBasket.items | len }} line items.</p>
{{ else }}
  <p>You have no products in the basket yet.</p>
{{ /if }}
```

**Result** \
If the basket is filled, the number of line items appears, otherwise a notice about the empty basket.

If line items are present, iterate over `items` and show product name, quantity, and prices for each line item. The totals are placed outside the loop because they would otherwise be output again for each line item.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $wsBasket.items }}
  {{ foreach $item in $wsBasket.items }}
    <a href="{{= $wsViews.url('Product', {productId: $item.product.id}) }}">
      <img src="{{= $item.product.custom.image.normal }}" alt="{{= $item.product.name }}">
    </a>
    <p>Product name: {{= $item.product.name }}</p>
    <p>Quantity: {{= int($item.quantity) }}</p>
    <p>Unit price: {{= $item.price | currency }}</p>
    <p>Item total: {{= $item.total | currency }}</p>
  {{ /foreach }}

  <p>Shipping costs: {{= $wsCheckout.sum.shippingCost | currency }}</p>
  <p>Grand total: {{= $wsBasket.total | currency }}</p>
{{ else }}
  <p>You have no products in the basket!</p>
{{ /if }}
```

**Result** \
Each line item is listed with image, name, quantity, and prices. Below, the shipping costs and grand total appear once.

Creates a link to the basket page, which is implemented via the view template `basket.htm`.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<a href="{{= $wsViews.viewUrl('basket.htm') }}">View basket</a>
```

**Result** \
The link leads to the basket page of the shop.

***

## Further links

* [Actions → Basket](/en/frontend/referenz/aktionen/basket) – change the basket (add, modify, remove), because `$wsBasket` itself only reads.
* [\$wsCheckout](/en/frontend/referenz/module/wscheckout) – provides supplementary values such as the shipping costs (`sum.shippingCost`) for the totals display.
* [\$wsViews](/en/frontend/referenz/module/wsviews) – generates the product and view URLs used in the examples.
* [Practical examples basket](/en/frontend/praxisbeispiele/warenkorb-funktionen) – end-to-end practical examples for basket functions.
