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

# GD- (Grouping discounts)

> Output discount groups from discount.dat in the template: list all tiers, highlight the tier reached, and query the granted discount for a single discount group.

Grouping discounts combine products into a discount group and grant a discount as soon as the basket reaches a quantity or goods value for that group. Which groups exist and how much discount applies from which threshold is defined in `discount.dat`. Which product belongs to which group is defined in the product data field "Discount group".

The `GD-` tags make these rules visible in the template. They are used in two ways: as a loop over all stored tiers to display a discount scale, or as a targeted query for a single discount group to output the currently granted discount on a product or in the basket.

Guide: Defining discounts · Reference: discount.dat

## Listing the discount scale

`GD-Data` has three faces. As a single tag, it outputs the number of tiers; as an area tag, it applies if there are any tiers at all; and as a loop, it runs over the tiers.

| Tag | Returns |
| - | - |
| `GD-Data` | the number of tiers, the existence check and the loop |
| `GD-Data_ID` | the ID of the discount group of the current iteration |
| `GD-Data_FromQuantity` | the minimum quantity from which the tier applies |
| `GD-Data_FromPrice` | the minimum goods value from which the tier applies |
| `GD-Data_Discount(<Stellen>)` | the discount rate of this tier |

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{GD-Data}
   <p>Unsere Rabattstaffel umfasst ~GD-Data~ Stufen.</p>

   <ul>
      {@GD-Data}
         <li>
            {GD-Data_FromQuantity}ab Menge ~GD-Data_FromQuantity~{/GD-Data_FromQuantity}
            {GD-Data_FromPrice}ab ~GD-Data_FromPrice~ Warenwert{/GD-Data_FromPrice}
            ~GD-Data_Discount~ % Rabatt in Gruppe ~GD-Data_ID~
         </li>
      {/@GD-Data}
   </ul>
{/GD-Data}
```

> [!NOTE]
>
> Each tier has either a quantity threshold or a value threshold, never both. That is why `GD-Data_FromQuantity` and `GD-Data_FromPrice` are also area tags: the area applies exactly for the type of threshold this tier uses and stays empty for the other. This way, you write both lines one below the other and always get the right one.

> [!NOTE]
>
> `GD-Data_Discount` outputs the discount rate without decimal places. For fractional rates, specify the desired number of places from 0 to 5 in the argument, for example `~GD-Data_Discount(2)~` for "7,50".

### Listing only one discount group

With an ID in the argument, the loop is restricted to the tiers of this one discount group. This is the usual case in the product view, where only the scale of the displayed product is of interest.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{GD-Data($PR-DiscountID$)}
   <ul>
      {@GD-Data($PR-DiscountID$)}
         <li>
            {GD-Data_FromQuantity}ab ~GD-Data_FromQuantity~ Stück{/GD-Data_FromQuantity}
            {GD-Data_FromPrice}ab ~GD-Data_FromPrice~{/GD-Data_FromPrice}
            ~GD-Data_Discount~ %
         </li>
      {/@GD-Data($PR-DiscountID$)}
   </ul>
{/GD-Data($PR-DiscountID$)}
```

> [!WARNING]
>
> Within a running `@GD-Data` loop, there must not be a second loop with a different ID. The shop system only maintains one loop counter, and a nested loop with a different ID is rejected as an invalid tag. Therefore, list several discount groups one after the other, not inside each other.

## Highlighting the tier reached

`GD-Data_DiscountGranted` applies for the tier that is actually granted based on the current basket. Use it to highlight in the scale where the visitor currently stands.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{GD-Data($PR-DiscountID$)}
   {@GD-Data($PR-DiscountID$)}
      <li class="{GD-Data_DiscountGranted}erreicht{/GD-Data_DiscountGranted}">
         {GD-Data_FromQuantity}ab ~GD-Data_FromQuantity~ Stück{/GD-Data_FromQuantity}
         {GD-Data_FromPrice}ab ~GD-Data_FromPrice~{/GD-Data_FromPrice}
         ~GD-Data_Discount~ %
      </li>
   {/@GD-Data($PR-DiscountID$)}
{/GD-Data($PR-DiscountID$)}
```

> [!WARNING]
>
> `GD-Data_DiscountGranted` only works if the loop was opened with a discount group ID in the argument. The shop system determines the granted rate when entering the loop, and it needs the ID for that. In a loop without an argument, the comparison value remains zero, and the area does not apply for any tier.

> [!NOTE]
>
> The assignment is made via the discount rate. If two tiers with the same rate are stored in a discount group, both are marked as reached. This is only noticeable with unusually structured scales.

## Querying the discount of a discount group

Outside the scale, you query a discount group directly via its ID. All tags in this section expect the ID as the first argument, usually as `$PR-DiscountID$` in the product view or as `$BASKET-PR-DiscountID$` on the basket page.

| Tag | Returns |
| - | - |
| `GD-DiscountForID_Available(<ID>)` | applies if any tiers are stored for this ID |
| `GD-DiscountForID_Granted(<ID>, <Stellen>)` | the discount rate granted based on the basket |
| `GD-DiscountForID_TimeDependent(<ID>)` | applies if at least one time-dependent tier is stored for this ID |

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{GD-DiscountForID_Available($PR-DiscountID$)}
   {GD-DiscountForID_Granted($PR-DiscountID$)}
      <p>Ihr Rabatt für dieses Produkt: ~GD-DiscountForID_Granted($PR-DiscountID$,2)~ %</p>
   {/GD-DiscountForID_Granted($PR-DiscountID$)}

   {!GD-DiscountForID_Granted($PR-DiscountID$)}
      <p>Für dieses Produkt gibt es einen Mengenrabatt.</p>
   {/!GD-DiscountForID_Granted($PR-DiscountID$)}
{/GD-DiscountForID_Available($PR-DiscountID$)}
```

> [!WARNING]
>
> `GD-DiscountForID_Available` only says that rules exist for this ID, not that a discount is currently being granted. Whether anything is actually granted is answered by `GD-DiscountForID_Granted` as an area tag. If you only check `Available` and then output the rate, you write a zero on the page when the threshold has not yet been reached.

> [!NOTE]
>
> Time-dependent tiers only apply within a stored period. `GD-DiscountForID_TimeDependent` detects that a discount group contains such tiers and allows you to show a corresponding notice such as "Promotional discount".

### Outputting the reference value

Two further tags output what the granted discount is based on. Use them to show the visitor how much they already have in the basket in this discount group.

| Tag | Returns |
| - | - |
| `GD-DiscountForID_Base(<ID>, <Stellen>)` | the goods value accumulated for this discount group |
| `GD-DiscountForID_BaseQuantity(<ID>, <Stellen>)` | the quantity accumulated for this discount group |

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{GD-DiscountForID_Available($PR-DiscountID$)}
   <p>
      In dieser Rabattgruppe haben Sie ~GD-DiscountForID_BaseQuantity($PR-DiscountID$)~ Stück
      im Warenkorb, Warenwert ~GD-DiscountForID_Base($PR-DiscountID$,2)~.
   </p>
{/GD-DiscountForID_Available($PR-DiscountID$)}
```

> [!NOTE]
>
> These two tags are not described in the previous documentation. They behave like `GD-DiscountForID_Granted` and take the same arguments, but output the reference value or reference quantity instead of the discount rate.

### Showing the next higher tier

With two further arguments, the tags calculate as if a certain additional value or quantity were in the basket. This lets you answer the question "What do I get if I add one more?".

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<p>
   Mit einem Stück mehr erhalten Sie
   ~GD-DiscountForID_Granted($PR-DiscountID$,0,$PR-Price$,1)~ % Rabatt.
</p>
```

The arguments are, in order: discount group ID, decimal places, additional price, additional quantity.

> [!WARNING]
>
> The third and fourth parameters only work together. The shop system only evaluates them when all four arguments are specified. A call with only three arguments calculates with the unchanged basket, without this being noticeable. Therefore, specify the decimal places even if you want zero places.

## The tags at a glance

| Tag | Single tag | Area tag | Negative area tag | Loop tag |
| - | - | - | - | - |
| `GD-Data(<ID>)` | yes | yes | yes | yes |
| `GD-Data_ID` | yes | yes | yes | – |
| `GD-Data_FromQuantity` | yes | yes | yes | – |
| `GD-Data_FromPrice` | yes | yes | yes | – |
| `GD-Data_Discount(<Stellen>)` | yes | yes | yes | – |
| `GD-Data_DiscountGranted` | – | yes | yes | – |
| `GD-DiscountForID_Granted(<ID>, …)` | yes | yes | yes | – |
| `GD-DiscountForID_Base(<ID>, …)` | yes | yes | yes | – |
| `GD-DiscountForID_BaseQuantity(<ID>, …)` | yes | yes | yes | – |
| `GD-DiscountForID_Available(<ID>)` | – | yes | yes | – |
| `GD-DiscountForID_TimeDependent(<ID>)` | – | yes | yes | – |

The tags of the `GD-Data_` family only apply within the `@GD-Data` loop. The remaining tags are permitted on all templates.

> [!NOTE]
>
> The area tags `GD-Data_ID`, `GD-Data_FromQuantity` and `GD-Data_FromPrice` compare with the argument if one is specified. `{GD-Data_ID(VIP)}` therefore only applies when iterating the discount group VIP. Without an argument, they apply if any value is present.

> [!WARNING]
>
> With `GD-Data_Discount`, the argument specifies the decimal places. As an area tag with an argument, the shop system nevertheless compares the number of places with the formatted discount rate, which practically never matches. Use `GD-Data_Discount` with an argument only as a single tag.

## Related topics

* Guide: Defining discounts
* Reference: discount.dat
* Reference: BD- (volume discounts)
* Reference: PR- (product data)


## Related topics

- [Configuration discount.dat](https://dokumentation.websale.de/en/v8s/referenz/konfigurationen/konfiguration-discount-dat.md)
- [Displaying grouping products](https://dokumentation.websale.de/en/v8s/produkte/gruppierungsprodukte-anzeigen.md)
- [Excluding buyers with a customer discount from a voucher](https://dokumentation.websale.de/en/v8s/gutscheine-anbieten/gutschein-fuer-kaeufer-mit-kundenrabatt-ausschliessen.md)
- [API reference vouchers](https://dokumentation.websale.de/en/schnittstellen/admin-interface-api/api-referenz-gutscheine.md)
- [Order data overview](https://dokumentation.websale.de/en/v8s/materialien/uebersicht-bestelldaten.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.