-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathbasket_event.html.twig
More file actions
39 lines (31 loc) · 1.18 KB
/
basket_event.html.twig
File metadata and controls
39 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# templates/cart/add_confirmation.html.twig #}
{% extends 'base.html.twig' %}
{% block content %}
<div class="cart-notification">
<p>Product "{{ product.name }}" has been added to your cart!</p>
<p>Quantity: {{ addedQuantity }}</p>
</div>
{# Build basket content string: "SKU:quantity;SKU:quantity" #}
{% set basketContent = [] %}
{% for item in basket.items %}
{% set basketContent = basketContent|merge([item.product.code ~ ':' ~ item.quantity]) %}
{% endfor %}
{# Track basket addition #}
{% set basketContext = {
'basketContent': basketContent|join(';'),
'basketId': basket.id,
'quantity': addedQuantity
} %}
{{ ibexa_tracking_track_event('basket', product, basketContext) }}
<a href="{{ path('cart_view') }}">View Cart</a>
{% endblock %}
```
Simplified example with Twig filter:
``` html+twig
{# If you have a custom Twig filter to format basket content #}
{% set basketContext = {
'basketContent': basket|format_basket_content, {# Returns "SKU-1:2;SKU-2:1;SKU-3:5" #}
'basketId': basket.id,
'quantity': addedQuantity
} %}
{{ ibexa_tracking_track_event('basket', product, basketContext) }}