Skip to content

Basket templates

Template list

Path Description
SilversolutionsEshopBundle:Basket:show.html.twig Main basket template
SilversolutionsEshopBundle:Basket:messages.html.twig Renders a message when the basket is modified
SilversolutionsEshopBundle:Fieldtypes:StockField.html.twig Renders the stock Field representing product availability
SilversolutionsEshopBundle:parts:stock_legend.html.twig Renders the legend of symbols used to indicate product availability
ezcommerce-base-design/Resources/views/themes/standard/basket/widget.html.twig Renders the basket preview in the upper right corner of the shop screen
ezcommerce-base-design/Resources/views/themes/standard/basket/row.html.twig Renders one row of basket preview
SilversolutionsEshopBundle:Basket:stored_basket_preview_wish_list.html.twig Renders the wishlist row with a number of products in the "My Shop" menu
SilversolutionsEshopBundle:Basket:stored_basket_preview_comparison.html.twig Renders the comparison row with a number of products in the "My Shop" menu

Display the content of a basket

The BasketController provides the basket variable that contains the content of the current basket.

You can access all basket attributes from a template.

The count of basket lines:

1
{{ basket.lines.count }}

Access to basket lines:

1
2
3
4
{% for line in basket.lines %}
    {{ line.sku }} 
    {{ line.linePriceAmountGross }} 
{% endfor %}

You can access the basket total value (net or gross) using basket.totalsSum:

1
{{ basket.totalsSum.totalGross }}

To get the catalog element from the basket line, use line.catalogElement.

If a basket line does not provide product data (for example, the caching life time of a product has been exceeded), the product can be fetched with the ses_product function, by providing it with the product SKU obtained through line.sku.

1
2
3
4
5
{% if line.catalogElement|default is not empty %}
    {% set product = line.catalogElement %}
{% else %}
    {% set product = ses_product({'sku': line.sku, 'variantCode': line.variantCode }) %}
{% endif %}

Adding a product to the basket

To create a button that adds the current product to the basket, use the following form:

1
2
3
4
5
6
7
<form method="post" action="{{ path('silversolutions_add_to_basket') }}">
    <div class="js-add-to-basket-parent">
        <input type="text" name="ses_basket[0][quantity]" class="tooltip" data-placement="e">
        <input type="hidden" name="ses_basket[0][sku]" value="{{ catalogElement.sku }}" >
        <input type="submit" class="button js-add-to-basket float_right" value="{{ 'Add to basket'|trans }}">
    </div>
</form>

You can add more than one product to the basket (for example, in a product list) by using the index:

1
2
3
ses_basket[0]
ses_basket[1]
...

Note

If you want to add more products to the basket (for example, from the wishlist), you need one form around all the lines. The form adds all the lines to the basket at once. However, you might also need to add only one product from the list.

To add a single product to the basket, you need to define parent elements with the class .js-product-line.