From c9a1174c98cc585ca1e1aa41ccee35c714eb3c82 Mon Sep 17 00:00:00 2001 From: MaxBUhe Date: Wed, 10 May 2023 15:01:56 +0200 Subject: [PATCH] genuine code cleanup; switch hard-getter to methods and use price-object # Conflicts: # Application/views/blocks/view_item.tpl # Application/views/ga4/add_to_cart.tpl --- Application/views/blocks/checkout_s1.tpl | 16 ++++++++-------- Application/views/blocks/checkout_s5.tpl | 23 ++++++++++++----------- Application/views/ga4/add_to_cart.tpl | 12 +++--------- Application/views/ga4/search.tpl | 3 ++- Application/views/ga4/view_item_list.tpl | 3 ++- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Application/views/blocks/checkout_s1.tpl b/Application/views/blocks/checkout_s1.tpl index 498b7dc..6b7fe88 100644 --- a/Application/views/blocks/checkout_s1.tpl +++ b/Application/views/blocks/checkout_s1.tpl @@ -2,10 +2,10 @@ [{*$oxcmp_basket|get_class_methods|dumpvar*}] +[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] + [{assign var='gtmCartArticles' value=$oView->getBasketArticles()}] [{strip}][{capture assign=d3_ga4_view_cart}] - let iPrice = "[{oxprice price=$oxcmp_basket->getPrice()}]"; - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ dataLayer.push({ 'event': 'view_cart', @@ -13,15 +13,15 @@ 'ecommerce': { 'actionField': "step: 1", 'currency': "[{$currency->name}]", - 'value': iPrice.replace("€", ""), + 'value': [{$d3BasketPrice->getPrice()}], 'items': [ [{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}] - [{assign var='_price' value=$basketitem->getUnitPrice()}] + [{assign var="d3oItemPrice" value=$basketitem->getPrice()}] { - 'item_id': '[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]', - 'item_name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]', - 'item_variant': '[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]', - 'price': [{$_price->getPrice()}], + 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', + 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', + 'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]', + 'price': [{$d3oItemPrice->getPrice()}], 'quantity':[{$basketitem->getAmount()}], 'position':[{$smarty.foreach.gtmCartContents.index}] }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}] diff --git a/Application/views/blocks/checkout_s5.tpl b/Application/views/blocks/checkout_s5.tpl index 64a8713..de97f30 100644 --- a/Application/views/blocks/checkout_s5.tpl +++ b/Application/views/blocks/checkout_s5.tpl @@ -10,21 +10,22 @@ 'event': 'purchase', 'eventLabel':'Checkout Step 5', 'ecommerce': { - 'transaction_id': '[{$_gtmOrder->oxorder__oxordernr->value}]', - 'affiliation': '[{$oxcmp_shop->oxshops__oxname->value}]', - 'value': '[{$_gtmOrder->oxorder__oxtotalordersum->value}]', - 'tax': '[{math equation="x+y" x=$_gtmOrder->oxorder__oxartvatprice1->value y=$_gtmOrder->oxorder__oxartvatprice2->value }]', - 'shipping': '[{$_gtmOrder->oxorder__oxdelcost->value}]', + 'transaction_id': '[{$_gtmOrder->getFieldData("oxordernr")}]', + 'affiliation': '[{$oxcmp_shop->getFieldData("oxname")}]', + 'value': '[{$_gtmOrder->getTotalOrderSum()}]', + 'tax': '[{math equation="x+y" x=$_gtmOrder->getFieldData("oxartvatprice1") y=$_gtmOrder->getFieldData("oxartvatprice2") }]', + 'shipping': '[{$_gtmOrder->getFieldData("oxdelcost")}]', 'currency': '[{$_gtmOrder->getFieldData('oxcurrency')}]', 'items': [ - [{foreach from=$_gtmArticles item="_gtmArticle" name="gtmArticles"}] + [{foreach from=$_gtmArticles item="d3BasketArticle" name="gtmArticles"}] + [{assign var="d3oArticlePrice" value=$d3BasketArticle->getPrice()}] { - 'id': '[{$_gtmArticle->oxorderarticles__oxartnum->value}]', - 'name': '[{$_gtmArticle->oxorderarticles__oxtitle->value}]', - 'variant': '[{$_gtmArticle->oxorderarticles__oxselvariant->value}]', - 'price': [{$_gtmArticle->oxorderarticles__oxprice->value}], - 'quantity': [{$_gtmArticle->oxorderarticles__oxamount->value}], + 'id': '[{$d3BasketArticle->getFieldData("oxartnum")}]', + 'name': '[{$d3BasketArticle->getFieldData("oxtitle")}]', + 'variant': '[{$d3BasketArticle->getFieldData("oxselvariant")}]', + 'price': [{$d3oArticlePrice->getPrice()}], + 'quantity': [{$d3BasketArticle->getFieldData("oxamount")}], 'position': [{$smarty.foreach.gtmArticles.iteration}] }[{if !$smarty.foreach.gtmArticles.last}],[{/if}] [{/foreach}] diff --git a/Application/views/ga4/add_to_cart.tpl b/Application/views/ga4/add_to_cart.tpl index 83062ec..9848918 100644 --- a/Application/views/ga4/add_to_cart.tpl +++ b/Application/views/ga4/add_to_cart.tpl @@ -1,6 +1,6 @@ [{$smarty.block.parent}] -[{*$gtmProduct|get_class_methods|dumpvar*}] +[{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] [{capture assign=d3_ga4_add_to_cart}] [{block name="d3_ga4_add_to_basket"}] @@ -15,24 +15,18 @@ 'eventLabel': 'add_to_cart', 'ecommerce': { 'currency': "[{$currency->name}]", - 'value': iArtQuantity*[{$gtmProduct->getFieldData('oxprice')}], + 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], 'items': [ { 'item_id': '[{$gtmProduct->getFieldData('oxartnum')}]', 'item_name': '[{$gtmProduct->getFieldData('oxtitle')}]', - 'price': '[{$gtmProduct->getFieldData('oxprice')}]', + 'price': '[{$d3PriceObject->getPrice()}]', 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', 'item_variant': '[{if $gtmProduct->getFieldData('oxvarselect')}][{$gtmProduct->getFieldData('oxvarselect')}][{/if}]', 'item_category': itemCategories[0] || 'no category', 'item_category_2':itemCategories[1] || '', 'item_category_3':itemCategories[2] || '', 'item_category_4':itemCategories[3] || '', - [{if false}] - [{* ??? what *}] - 'item_list_name': 'Search Results', // If associated with a list selection. - 'item_list_id': 'SR123', // If associated with a list selection. - 'index': 1, // If associated with a list selection. - [{/if}] 'quantity': iArtQuantity } ] diff --git a/Application/views/ga4/search.tpl b/Application/views/ga4/search.tpl index d71f6ea..50a300a 100755 --- a/Application/views/ga4/search.tpl +++ b/Application/views/ga4/search.tpl @@ -13,12 +13,13 @@ 'search_term': '[{$searchparamforhtml}]', 'items': [ [{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}] + [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] [{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] [{if !$gtmCategory}][{assign var="gtmCategory" value=$gtmProduct->getCategory()}][{/if}] { 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - 'price': [{$gtmProduct->oxarticles__oxprice->value|default:'0'}], + 'price': [{$d3PriceObject->getPrice()}], 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', 'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]', 'quantity': 1 diff --git a/Application/views/ga4/view_item_list.tpl b/Application/views/ga4/view_item_list.tpl index 2479eec..0f9a99f 100644 --- a/Application/views/ga4/view_item_list.tpl +++ b/Application/views/ga4/view_item_list.tpl @@ -1,4 +1,5 @@ [{assign var="gtmProducts" value=$products}] +[{assign var="d3PriceObject" value=$gtmProducts->getPrice()}] [{assign var="breadCrumb" value=''}] @@ -20,7 +21,7 @@ { 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - 'price': [{$gtmProduct->oxarticles__oxprice->value|default:'0'}], + 'price': [{$d3PriceObject->getPrice()}], 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', 'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]', 'quantity': 1