The default context provider does not provide a cart object. There’s only channelContext, currencyContext, localeContext and customerContext.
Is it possible to get cart in twig template using Sylius template events?
For example like this:
sylius_ui:
events:
sylius.shop.layout.header.content:
blocks:
search:
enabled: true
template: "@App/Layout/Header/_search.html.twig"
priority: 10
context:
cart: how_to_pass_cart? # <-- How to pass cart
And using it in a template, for example:
{# @App/Layout/Header/_search.html.twig #}
{{ cart.itemsTotal }}
Right now, in the standard template, to display the cart, a render of the order controller is used with template substitution.
<div class="right aligned column">
{{ render(url('sylius_shop_partial_cart_summary', {'template': '@SyliusShop/Cart/_widget.html.twig'})) }}
</div>
From my point of view this is not a very good solution.
Is there a way to get the cart via context parameter or ContextProvider in twig template?