reworking view_cart to add necessary parameters
This commit is contained in:
parent
95de52600d
commit
c83e908da1
@ -1,20 +1,24 @@
|
|||||||
[{strip}]
|
[{$smarty.block.parent}]
|
||||||
[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}]
|
|
||||||
<script>
|
[{$oxcmp_basket|get_class_methods|dumpvar}]
|
||||||
|
|
||||||
|
[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}]
|
||||||
|
[{strip}][{capture assign=d3_ga4_view_cart}]
|
||||||
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
|
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
|
||||||
dataLayer.push({
|
dataLayer.push({
|
||||||
'event': 'view_cart',
|
'event': 'view_cart',
|
||||||
'eventLabel':'Checkout Step 1',
|
'eventLabel':'Checkout Step 1',
|
||||||
'ecommerce': {
|
'ecommerce': {
|
||||||
'checkout': {
|
'actionField': "step: 1",
|
||||||
'actionField': {'step': 1},
|
'currency': "[{$currency->name}]",
|
||||||
'products': [
|
'value': [{$oxcmp_basket->getBruttoSum()}],
|
||||||
|
'items': [
|
||||||
[{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}]
|
[{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}]
|
||||||
[{assign var='_price' value=$basketitem->getUnitPrice()}]
|
[{assign var='_price' value=$basketitem->getUnitPrice()}]
|
||||||
{
|
{
|
||||||
'id': '[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]',
|
'item_id': '[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]',
|
||||||
'name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]',
|
'item_name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]',
|
||||||
'variant': '[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]',
|
'item_variant': '[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]',
|
||||||
'price': [{$_price->getPrice()}],
|
'price': [{$_price->getPrice()}],
|
||||||
'quantity':[{$basketitem->getAmount()}],
|
'quantity':[{$basketitem->getAmount()}],
|
||||||
'position':[{$smarty.foreach.gtmCartContents.index}]
|
'position':[{$smarty.foreach.gtmCartContents.index}]
|
||||||
@ -22,36 +26,6 @@
|
|||||||
[{/foreach}]
|
[{/foreach}]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
[{*
|
[{/capture}][{/strip}]
|
||||||
var gtmCartContents = {[{foreach key=basketindex from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents}]
|
[{oxscript add=$d3_ga4_view_cart}]
|
||||||
'[{$basketindex}]':{ 'id':'[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]' }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}][{/foreach}]
|
|
||||||
};
|
|
||||||
|
|
||||||
[{capture name='removeFromBasket'}]
|
|
||||||
$('#basketRemove').on('click', function() {
|
|
||||||
var _checked = [],
|
|
||||||
_products = [];
|
|
||||||
|
|
||||||
$('input:checkbox:checked[name^="aproducts"][name*="remove"]').each(function() { _checked.push($(this).attr('name').replace('aproducts[','').replace('][remove]','')); });
|
|
||||||
if(_checked.length == 0) return;
|
|
||||||
_checked.forEach(function(_oxid) { _products.push({ 'id':gtmCartContents[_oxid].id}) });
|
|
||||||
|
|
||||||
dataLayer.push({
|
|
||||||
'event':'ee.removeFromCart',
|
|
||||||
'ecommerce': {
|
|
||||||
'currencyCode': '[{$currency->name}]',
|
|
||||||
'remove': {
|
|
||||||
'products': _products
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
[{/capture }]
|
|
||||||
[{oxscript add=$smarty.capture.removeFromBasket}]
|
|
||||||
*}]
|
|
||||||
</script>
|
|
||||||
[{/strip}]
|
|
||||||
[{$smarty.block.parent}]
|
|
Loading…
Reference in New Issue
Block a user