Skip to main content
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, 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.
  • 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 is the primary switch, totalTaxDeduction and totalPreDeduction provide the amounts for a “minus VAT” line, and usedExemptionRule together with billingCountry/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 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
JSON output
Basket variables (top level)

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.

$wsBasket.total

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

$wsBasket.totalNet

Returns the net amount of the basket.

$wsBasket.totalGross

Returns the gross amount of the basket.

$wsBasket.totalTax

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

$wsBasket.totalCommission

Returns the total commission of the basket.

$wsBasket.totalWeight

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

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

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

Properties of $wsBasket.lastUpdatedItem

$wsBasket.items

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

Properties of an entry in $wsBasket.items

$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”.

$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”.

$wsBasket.totalPreDeduction

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

$wsBasket.billingCountry

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

$wsBasket.shippingCountry

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

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

Methods

No methods are available for $wsBasket.

Actions

Actions that change the basket (add product, change quantity, remove) are documented separately: Actions → 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.
Result
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.
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.
Result
The link leads to the basket page of the shop.

  • Actions → Basket – change the basket (add, modify, remove), because $wsBasket itself only reads.
  • $wsCheckout – provides supplementary values such as the shipping costs (sum.shippingCost) for the totals display.
  • $wsViews – generates the product and view URLs used in the examples.
  • Practical examples basket – 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, 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.
  • 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 is the primary switch, totalTaxDeduction and totalPreDeduction provide the amounts for a “minus VAT” line, and usedExemptionRule together with billingCountry/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 and lastUpdatedItem describe this last change. Useful, for example, to display feedback such as “Product X was added” directly after adding.
Basket variables (top level) 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.

$wsBasket.totalNet

Returns the net amount of the basket.

$wsBasket.totalGross

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

$wsBasket.totalCommission

Returns the total commission of the basket.

$wsBasket.totalWeight

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

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

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

Properties of $wsBasket.lastUpdatedItem

$wsBasket.items

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

Properties of an entry in $wsBasket.items

$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”.

$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”.

$wsBasket.totalPreDeduction

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

$wsBasket.billingCountry

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

$wsBasket.shippingCountry

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

$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.
Actions that change the basket (add product, change quantity, remove) are documented separately: Actions → Basket. First check whether any line items exist at all before displaying the basket, otherwise you would show an empty list.
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.
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.
Result
The link leads to the basket page of the shop.

  • Actions → Basket – change the basket (add, modify, remove), because $wsBasket itself only reads.
  • $wsCheckout – provides supplementary values such as the shipping costs (sum.shippingCost) for the totals display.
  • $wsViews – generates the product and view URLs used in the examples.
  • Practical examples basket – end-to-end practical examples for basket functions.