adjust view_cart; extend Model\Category
add categories to ecommerce-DataLayer; add method to immediately get the requested Category-Steps
This commit is contained in:
bovenliggende
7b82476e8b
commit
5dd7b51fb5
@ -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}]
|
39
Application/views/blocks/view_cart.tpl
Normal file
39
Application/views/blocks/view_cart.tpl
Normal file
@ -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}]
|
@ -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 {}
|
||||
}
|
44
Modules/Application/Model/Category.php
Normal file
44
Modules/Application/Model/Category.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace D3\GoogleAnalytics4\Modules\Application\Model;
|
||||
|
||||
class Category extends Category_parent
|
||||
{
|
||||
/**
|
||||
* @param int $indexOfArray
|
||||
* @return string
|
||||
*/
|
||||
public function getSplitCategoryArray(int $indexOfArray = -1) :string
|
||||
{
|
||||
if ($indexOfArray > -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use D3\GoogleAnalytics4\Modules\Application\Model\Category as Category;
|
||||
use D3\GoogleAnalytics4\Modules\Core\ViewConfig;
|
||||
use OxidEsales\Eshop\Application\Model\Category as OECategory;
|
||||
use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig;
|
||||
|
||||
$sMetadataVersion = '2.1';
|
||||
@ -22,7 +25,8 @@ $aModule = [
|
||||
'email' => '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',
|
||||
|
Laden…
Verwijs in nieuw issue
Block a user