From 5dd7b51fb55d178c23c29bb7e37cff7b9ea3985e Mon Sep 17 00:00:00 2001 From: MaxBUhe Date: Wed, 21 Jun 2023 15:23:50 +0200 Subject: [PATCH] adjust view_cart; extend Model\Category add categories to ecommerce-DataLayer; add method to immediately get the requested Category-Steps --- Application/views/blocks/checkout_s1.tpl | 33 ------------------ Application/views/blocks/view_cart.tpl | 39 +++++++++++++++++++++ IntelliSenseHelper.php | 4 +++ Modules/Application/Model/Category.php | 44 ++++++++++++++++++++++++ metadata.php | 8 +++-- 5 files changed, 93 insertions(+), 35 deletions(-) delete mode 100644 Application/views/blocks/checkout_s1.tpl create mode 100644 Application/views/blocks/view_cart.tpl create mode 100644 Modules/Application/Model/Category.php diff --git a/Application/views/blocks/checkout_s1.tpl b/Application/views/blocks/checkout_s1.tpl deleted file mode 100644 index 6b7fe88..0000000 --- a/Application/views/blocks/checkout_s1.tpl +++ /dev/null @@ -1,33 +0,0 @@ -[{$smarty.block.parent}] - -[{*$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}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - dataLayer.push({ - 'event': 'view_cart', - 'eventLabel':'Checkout Step 1', - 'ecommerce': { - 'actionField': "step: 1", - 'currency': "[{$currency->name}]", - 'value': [{$d3BasketPrice->getPrice()}], - 'items': [ - [{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}] - [{assign var="d3oItemPrice" value=$basketitem->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}] - [{/foreach}] - ] - } - }); -[{/capture}][{/strip}] -[{oxscript add=$d3_ga4_view_cart}] \ No newline at end of file diff --git a/Application/views/blocks/view_cart.tpl b/Application/views/blocks/view_cart.tpl new file mode 100644 index 0000000..50ecccf --- /dev/null +++ b/Application/views/blocks/view_cart.tpl @@ -0,0 +1,39 @@ +[{$smarty.block.parent}] + +[{*$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}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + dataLayer.push({ + 'event': 'view_cart', + 'eventLabel':'Checkout Step 1', + 'ecommerce': { + 'actionField': "step: 1", + 'currency': "[{$currency->name}]", + 'value': [{$d3BasketPrice->getPrice()}], + 'items': [ + [{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}] + [{assign var="d3oItemPrice" value=$basketitem->getPrice()}] + [{assign var="gtmBasketItem" value=$basketitem->getArticle()}] + [{assign var="gtmBasketItemCategory" value=$gtmBasketItem->getCategory()}] + { + 'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]', + 'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]', + 'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]', + 'item_category':'[{$gtmBasketItemCategory->getSplitCategoryArray(0)}]', + 'item_category_2':'[{$gtmBasketItemCategory->getSplitCategoryArray(1)}]', + 'item_category_3':'[{$gtmBasketItemCategory->getSplitCategoryArray(2)}]', + 'item_category_4':'[{$gtmBasketItemCategory->getSplitCategoryArray(3)}]', + 'price': [{$d3oItemPrice->getPrice()}], + 'quantity':[{$basketitem->getAmount()}], + 'position':[{$smarty.foreach.gtmCartContents.index}] + }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}] + [{/foreach}] + ] + } + }); +[{/capture}][{/strip}] +[{oxscript add=$d3_ga4_view_cart}] \ No newline at end of file diff --git a/IntelliSenseHelper.php b/IntelliSenseHelper.php index 90f5882..2f818cd 100644 --- a/IntelliSenseHelper.php +++ b/IntelliSenseHelper.php @@ -15,4 +15,8 @@ namespace D3\GoogleAnalytics4\Modules\Core{ class ViewConfig_parent extends \OxidEsales\Eshop\Core\ViewConfig{} +} + +namespace D3\GoogleAnalytics4\Modules\Application\Model{ + class Category_parent extends \OxidEsales\Eshop\Application\Model\Category {} } \ No newline at end of file diff --git a/Modules/Application/Model/Category.php b/Modules/Application/Model/Category.php new file mode 100644 index 0000000..1f27087 --- /dev/null +++ b/Modules/Application/Model/Category.php @@ -0,0 +1,44 @@ + -1){ + $splitCatArray = + array_values( + array_filter( + explode( + '/', + trim( + parse_url( + $this->getLink(), + 5 + ) + ) + ) + ) + ); + + if ($splitCatArray[$indexOfArray]){ + return $splitCatArray[$indexOfArray]; + }else{ + return ""; + } + } + + return + trim( + parse_url( + $this->getLink(), + 5 + ) + ); + } +} \ No newline at end of file diff --git a/metadata.php b/metadata.php index 5a0b4f7..a02a7d2 100755 --- a/metadata.php +++ b/metadata.php @@ -1,5 +1,8 @@ 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'extend' => [ - OEViewConfig::class => ViewConfig::class + OEViewConfig::class => ViewConfig::class, + OECategory::class => Category::class ], 'templates' => [ // GA4 events @@ -55,7 +59,7 @@ $aModule = [ [ 'template' => 'page/checkout/basket.tpl', 'block' => 'checkout_basket_main', - 'file' => '/Application/views/blocks/checkout_s1.tpl' + 'file' => '/Application/views/blocks/view_cart.tpl' ], [ 'template' => 'page/checkout/thankyou.tpl',