Skip to main content
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

ActionDescription
BasketItemAddAdds a product to the basket.
BasketItemUpdateUpdates the quantity of a product in the basket.
BasketItemDeleteRemoves a product from the basket.
VoucherAddRedeems a voucher code in the basket.
VoucherDeleteRemoves 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
NameDescription
productIdThe ID of the product to be added to the basket.
quantityThe desired quantity of the product.
freeFieldscategoryPathOptional free field for passing the category path, e.g., for tracking purposes.
Error codes
Error codeDescription
missingProductIdParameter productId is missing.
invalidProductIdThe product does not exist or is not available.
Related modules, variables & methods Example showing how a product with quantity selection is added to the basket and a confirmation message appears after successful execution.
{{ 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
NameDescription
basketItemIdThe ID of the basket entry whose quantity is to be updated.
quantityThe new quantity of the product.
Error codes
Error codeDescription
missingBasketItemIdParameter basketItemId is missing.
invalidBasketItemIdThe basket entry does not exist or does not belong to this basket.
missingQuantityParameter quantity is missing.
Related modules, variables & methods Example showing how the quantity of a basket entry is updated via a form.
{{ 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
NameDescription
basketItemIdThe ID of the basket entry to be removed.
productIdThe ID of the product to be removed.
quantityThe current quantity of the product.
Error codes
Error codeDescription
missingBasketItemIdParameter basketItemId is missing.
invalidBasketItemIdThe basket entry does not exist or does not belong to this basket.
Related modules, variables & methods Example showing how a product is removed from the basket via a button.
{{ 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>