diff --git a/Application/views/blocks/details_productmain_tobasket.tpl b/Application/views/blocks/details_productmain_tobasket.tpl new file mode 100644 index 0000000..6ccb0de --- /dev/null +++ b/Application/views/blocks/details_productmain_tobasket.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/blocks/page_list_listbody.tpl b/Application/views/blocks/page_list_listbody.tpl new file mode 100644 index 0000000..6ccb0de --- /dev/null +++ b/Application/views/blocks/page_list_listbody.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/blocks/purchase.tpl b/Application/views/blocks/purchase.tpl index 3419a43..dd15b60 100644 --- a/Application/views/blocks/purchase.tpl +++ b/Application/views/blocks/purchase.tpl @@ -1,56 +1,3 @@ [{$smarty.block.parent}] -[{block name="d3_ga4_purchase_block"}] - [{capture assign=d3_ga4_purchase}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - [{assign var="gtmOrder" value=$oView->getOrder()}] - [{assign var="gtmBasket" value=$oView->getBasket()}] - [{assign var="gtmArticles" value=$gtmOrder->getOrderArticles()}] - [{assign var="gtmOrderVouchers" value=$gtmOrder->getVoucherNrList()}] - - dataLayer.push({ - 'event': 'purchase', - 'eventLabel':'Checkout Step 5', - 'ecommerce': { - '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')}]', - 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', - 'paymentType': '[{$gtmBasket->getPaymentOnPaymentId()}]', - 'items': [ - [{foreach from=$gtmArticles item="gtmBasketItem" name="gtmArticles"}] - [{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}] - [{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}] - [{assign var="gtmPurchaseItemCategory" value=$gtmPurchaseItem->getCategory()}] - - { - 'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]', - 'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]', - 'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]', - 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', - 'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]', - [{if $gtmPurchaseItemCategory}] - 'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0)}]', - 'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1)}]', - 'item_category_3': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(2)}]', - 'item_category_4': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(3)}]', - 'item_list_name': '[{$gtmPurchaseItemCategory->getSplitCategoryArray()}]', - [{/if}] - 'price': [{$gtmPurchaseItemPriceObject->getPrice()}], - 'quantity': [{$gtmBasketItem->getFieldData("oxamount")}], - 'position': [{$smarty.foreach.gtmArticles.iteration}] - }[{if !$smarty.foreach.gtmArticles.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }) - [{/strip}] - [{/capture}] - [{oxscript add=$d3_ga4_purchase}] -[{/block}] \ No newline at end of file +[{include file="event/purchase.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/remove_from_cart.tpl b/Application/views/blocks/remove_from_cart.tpl new file mode 100644 index 0000000..3fd874a --- /dev/null +++ b/Application/views/blocks/remove_from_cart.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/remove_from_cart.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/start_welcome_text.tpl b/Application/views/blocks/start_welcome_text.tpl new file mode 100644 index 0000000..6ccb0de --- /dev/null +++ b/Application/views/blocks/start_welcome_text.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/blocks/view_cart.tpl b/Application/views/blocks/view_cart.tpl index 765bfe8..7f795e7 100644 --- a/Application/views/blocks/view_cart.tpl +++ b/Application/views/blocks/view_cart.tpl @@ -1,50 +1,3 @@ [{$smarty.block.parent}] -[{*$oxcmp_basket|get_class_methods|dumpvar*}] - -[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] -[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}] - -[{block name="d3_ga4_view_cart_block"}] - [{capture assign=d3_ga4_view_cart}] - [{strip}] - 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()}], - 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', - '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')}]', - [{if $gtmBasketItemCategory}] - 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3)}]', - 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', - [{/if}] - 'price': [{$d3oItemPrice->getPrice()}], - 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', - 'quantity': [{$basketitem->getAmount()}], - 'position': [{$smarty.foreach.gtmCartContents.index}] - }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}] - [{/foreach}] - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$d3_ga4_view_cart}] -[{/block}] \ No newline at end of file +[{include file="event/view_cart.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/view_item.tpl b/Application/views/blocks/view_item.tpl index e79852e..b4dbab0 100644 --- a/Application/views/blocks/view_item.tpl +++ b/Application/views/blocks/view_item.tpl @@ -1,40 +1,3 @@ [{$smarty.block.parent}] -[{assign var="gtmProduct" value=$oView->getProduct()}] -[{assign var="gtmCategory" value=$gtmProduct->getCategory()}] -[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] -[{block name="d3_ga4_view_item_block"}] - [{capture assign=d3_ga4_view_item}] - [{strip}] - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - - dataLayer.push({ - 'event': 'view_item', - 'eventLabel':'Product View', - 'ecommerce': { - 'currency': '[{$currency->name}]', - 'items': [ - { - 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', - 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', - 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', - 'item_variant': '[{if $gtmProduct->getFieldData("oxvarselect")}][{$gtmProduct->getFieldData("oxvarselect")}][{/if}]', - [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', - 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', - [{/if}] - [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] - 'price': [{$d3PriceObject->getPrice()}] - } - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - [{/strip}] - [{/capture}] - [{oxscript add=$d3_ga4_view_item}] -[{/block}] \ No newline at end of file +[{include file="event/view_item.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/view_item_list.tpl b/Application/views/blocks/view_item_list.tpl new file mode 100644 index 0000000..beba87d --- /dev/null +++ b/Application/views/blocks/view_item_list.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/view_item_list.tpl"}] \ No newline at end of file diff --git a/Application/views/blocks/view_search_result.tpl b/Application/views/blocks/view_search_result.tpl new file mode 100644 index 0000000..1684871 --- /dev/null +++ b/Application/views/blocks/view_search_result.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="event/view_search_result.tpl"}] \ No newline at end of file diff --git a/Application/views/event/add_to_cart.tpl b/Application/views/event/add_to_cart.tpl new file mode 100644 index 0000000..8d85631 --- /dev/null +++ b/Application/views/event/add_to_cart.tpl @@ -0,0 +1,61 @@ + +[{if $d3CmpBasket->getAddToBasketDecision() && $d3CmpBasket->d3GtmRequestedArticleLoadedByAnid() !== null}] + [{assign var="oGtmProduct" value=$d3CmpBasket->d3GtmRequestedArticleLoadedByAnid()}] + [{assign var="oGtmAmountArticlesAdded" value=$d3CmpBasket->getD3GtmAddToCartAmountArticles()}] + [{*$smarty.block.parent*}] + [{* variable $oGtmProduct is passed from parent tempalte *}] + [{assign var="d3PriceObject" value=$oGtmProduct->getPrice()}] + [{assign var="gtmCurrency" value=$oView->getActCurrency()}] + [{assign var="gtmManufacturer" value=$oGtmProduct->getManufacturer()}] + [{assign var="gtmCategory" value=$oGtmProduct->getCategory()}] + + [{block name="d3_ga4_add_to_cart_list_block"}] + [{capture name="d3_ga4_add_to_cart_listtpl"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + + [{*** Debug cases ***}] + [{*event.preventDefault();*}] + + let iArtQuantity = $("[{$htmlIdAmountOfArticles}]").val(); + let iArtQuantityAdded = [{$oGtmAmountArticlesAdded}]; + + if(!iArtQuantity && (iArtQuantityAdded === 1)){ + iArtQuantity = 1; + }else{ + iArtQuantity = iArtQuantityAdded; + } + + dataLayer.push({ + 'isAddToBasket': true, + 'event':'add_to_cart', + 'eventLabel': 'add_to_cart', + 'ecommerce': { + 'currency': "[{$currency->name}]", + 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], + 'items': [ + { + 'item_id': '[{$oGtmProduct->getFieldData('oxartnum')}]', + 'item_name': '[{$oGtmProduct->getFieldData('oxtitle')}]', + 'price': [{$d3PriceObject->getPrice()}], + 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', + 'item_variant': '[{if $oGtmProduct->getFieldData('oxvarselect')}][{$oGtmProduct->getFieldData('oxvarselect')}][{/if}]', + [{if $gtmCategory}] + 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', + 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', + [{/if}] + 'quantity': iArtQuantity + } + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_add_to_cart_listtpl}] + [{/block}] +[{/if}] \ No newline at end of file diff --git a/Application/views/event/purchase.tpl b/Application/views/event/purchase.tpl new file mode 100644 index 0000000..28f8444 --- /dev/null +++ b/Application/views/event/purchase.tpl @@ -0,0 +1,56 @@ +[{block name="d3_ga4_purchase_block"}] + [{capture name="d3_ga4_purchase"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + [{assign var="gtmOrder" value=$oView->getOrder()}] + [{assign var="gtmBasket" value=$oView->getBasket()}] + [{assign var="gtmArticles" value=$gtmOrder->getOrderArticles()}] + [{assign var="gtmOrderVouchers" value=$gtmOrder->getVoucherNrList()}] + + dataLayer.push({ + 'event': 'purchase', + 'eventLabel':'Checkout Step 5', + 'ecommerce': + { + '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')}]', + 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', + 'paymentType': '[{$gtmBasket->getPaymentOnPaymentId()}]', + 'items': + [ + [{foreach from=$gtmArticles item="gtmBasketItem" name="gtmArticles"}] + [{assign var="gtmPurchaseItemPriceObject" value=$gtmBasketItem->getPrice()}] + [{assign var="gtmPurchaseItem" value=$gtmBasketItem->getArticle()}] + [{assign var="gtmPurchaseItemCategory" value=$gtmPurchaseItem->getCategory()}] + + { + 'item_id': '[{$gtmBasketItem->getFieldData("oxartnum")}]', + 'item_name': '[{$gtmBasketItem->getFieldData("oxtitle")}]', + 'affiliation': '[{$gtmBasketItem->getFieldData("oxtitle")}]', + 'coupon': '[{foreach from=$gtmOrderVouchers item="gtmOrderVoucher" name="gtmOrderVoucherIteration"}][{$gtmOrderVoucher}][{if !$smarty.foreach.gtmOrderVoucherIteration.last}], [{/if}][{/foreach}]', + 'item_variant': '[{$gtmBasketItem->getFieldData("oxselvariant")}]', + [{if $gtmPurchaseItemCategory}] + 'item_category': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4': '[{$gtmPurchaseItemCategory->getSplitCategoryArray(3, true)}]', + 'item_list_name': '[{$gtmPurchaseItemCategory->getSplitCategoryArray()}]', + [{/if}] + 'price': [{$gtmPurchaseItemPriceObject->getPrice()}], + 'quantity': [{$gtmBasketItem->getFieldData("oxamount")}], + 'position': [{$smarty.foreach.gtmArticles.iteration}] + }[{if !$smarty.foreach.gtmArticles.last}],[{/if}] + [{/foreach}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }) + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_purchase}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/remove_from_cart.tpl b/Application/views/event/remove_from_cart.tpl similarity index 90% rename from Application/views/ga4/remove_from_cart.tpl rename to Application/views/event/remove_from_cart.tpl index 8c41746..ae3951b 100644 --- a/Application/views/ga4/remove_from_cart.tpl +++ b/Application/views/event/remove_from_cart.tpl @@ -1,9 +1,7 @@ -[{$smarty.block.parent}] - [{block name="d3_ga4_remove_from_cart_block"}] [{if $hasBeenReloaded}] [{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] - [{capture assign=d3_ga4_remove_from_cart}] + [{capture name="d3_ga4_remove_from_cart"}] [{strip}] dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ dataLayer.push({ @@ -24,10 +22,10 @@ 'item_name': '[{$rmItem->getFieldData('oxtitle')}]', 'item_variant': '[{$rmItem->getFieldData('oxvarselect')}]', [{if $gtmBasketItemCategory}] - 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0)}]', - 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1)}]', - 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2)}]', - 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3)}]', + 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', [{/if}] 'price': [{$d3oItemPrice->getPrice()}], @@ -43,6 +41,6 @@ }); [{/strip}] [{/capture}] - [{oxscript add=$d3_ga4_remove_from_cart}] + [{oxscript add=$smarty.capture.d3_ga4_remove_from_cart}] [{/if}] [{/block}] \ No newline at end of file diff --git a/Application/views/event/view_cart.tpl b/Application/views/event/view_cart.tpl new file mode 100644 index 0000000..d87d478 --- /dev/null +++ b/Application/views/event/view_cart.tpl @@ -0,0 +1,50 @@ +[{*$oxcmp_basket|get_class_methods|dumpvar*}] + +[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}] +[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}] + +[{block name="d3_ga4_view_cart_block"}] + [{capture name="d3_ga4_view_cart"}] + [{strip}] + 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()}], + 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', + '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')}]', + [{if $gtmBasketItemCategory}] + 'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]', + 'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]', + [{/if}] + 'price': [{$d3oItemPrice->getPrice()}], + 'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]', + 'quantity': [{$basketitem->getAmount()}], + 'position': [{$smarty.foreach.gtmCartContents.index}] + }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}] + [{/foreach}] + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_view_cart}] +[{/block}] \ No newline at end of file diff --git a/Application/views/event/view_item.tpl b/Application/views/event/view_item.tpl new file mode 100644 index 0000000..f6349b9 --- /dev/null +++ b/Application/views/event/view_item.tpl @@ -0,0 +1,41 @@ +[{assign var="gtmProduct" value=$oView->getProduct()}] +[{assign var="gtmCategory" value=$gtmProduct->getCategory()}] +[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] + +[{block name="d3_ga4_view_item_block"}] + [{capture name="d3_ga4_view_item"}] + [{strip}] + dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ + + dataLayer.push({ + 'event': 'view_item', + 'eventLabel':'Product View', + 'ecommerce': + { + 'currency': '[{$currency->name}]', + 'items': + [ + { + 'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]', + 'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]', + 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', + 'item_variant': '[{if $gtmProduct->getFieldData("oxvarselect")}][{$gtmProduct->getFieldData("oxvarselect")}][{/if}]', + [{if $gtmCategory}] + 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', + 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', + [{/if}] + [{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] + 'price': [{$d3PriceObject->getPrice()}] + } + ] + }[{if $oViewConf->isDebugModeOn()}], + 'debug_mode': 'true' + [{/if}] + }); + [{/strip}] + [{/capture}] + [{oxscript add=$smarty.capture.d3_ga4_view_item}] +[{/block}] \ No newline at end of file diff --git a/Application/views/ga4/view_item_list.tpl b/Application/views/event/view_item_list.tpl similarity index 89% rename from Application/views/ga4/view_item_list.tpl rename to Application/views/event/view_item_list.tpl index 78782e0..2dbc0c9 100644 --- a/Application/views/ga4/view_item_list.tpl +++ b/Application/views/event/view_item_list.tpl @@ -1,4 +1,3 @@ -[{$smarty.block.parent}] [{assign var="gtmProducts" value=$oView->getArticleList()}] [{assign var="gtmCategory" value=$oView->getActiveCategory()}] @@ -6,7 +5,7 @@ [{block name="d3_ga4_view_item_list_block"}] [{if $gtmProducts|@count}] - [{capture assign=d3_ga4_view_item_list}] + [{capture name="d3_ga4_view_item_list"}] [{strip}] dataLayer.push({ecommerce: null}); dataLayer.push({ @@ -26,10 +25,10 @@ 'price': [{$d3PriceObject->getPrice()}], 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', + 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', [{/if}] 'quantity': 1 }[{if !$smarty.foreach.gtmProducts.last}],[{/if}] @@ -41,6 +40,6 @@ }); [{/strip}] [{/capture}] - [{oxscript add=$d3_ga4_view_item_list}] + [{oxscript add=$smarty.capture.d3_ga4_view_item_list}] [{/if}] [{/block}] \ No newline at end of file diff --git a/Application/views/ga4/view_search_result.tpl b/Application/views/event/view_search_result.tpl similarity index 86% rename from Application/views/ga4/view_search_result.tpl rename to Application/views/event/view_search_result.tpl index f73643e..aad6232 100644 --- a/Application/views/ga4/view_search_result.tpl +++ b/Application/views/event/view_search_result.tpl @@ -1,10 +1,8 @@ -[{$smarty.block.parent}] - [{assign var="gtmProducts" value=$oView->getArticleList()}] [{block name="d3_ga4_view_search_result_block"}] [{if $gtmProducts}] - [{capture assign=d3_ga4_view_search_result}] + [{capture name="d3_ga4_view_search_result"}] [{strip}] dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ dataLayer.push({ @@ -23,10 +21,10 @@ 'price': [{$d3PriceObject->getPrice()}], 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', + 'item_category': '[{$gtmCategory->getSplitCategoryArray(0, true)}]', + 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1, true)}]', + 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2, true)}]', + 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3, true)}]', 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', [{/if}] 'quantity': 1 @@ -39,6 +37,8 @@ }); [{/strip}] [{/capture}] - [{oxscript add=$d3_ga4_view_search_result}] + [{oxscript add=$smarty.capture.d3_ga4_view_search_result}] [{/if}] -[{/block}] \ No newline at end of file +[{/block}] + +[{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] \ No newline at end of file diff --git a/Application/views/ga4/add_to_cart.tpl b/Application/views/ga4/add_to_cart.tpl deleted file mode 100644 index 8a2b68e..0000000 --- a/Application/views/ga4/add_to_cart.tpl +++ /dev/null @@ -1,52 +0,0 @@ -[{$smarty.block.parent}] - -[{* variable $gtmProduct is passed from parent tempalte *}] -[{assign var="d3PriceObject" value=$gtmProduct->getPrice()}] -[{assign var="gtmCurrency" value=$oView->getActCurrency()}] -[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}] -[{assign var="gtmCategory" value=$gtmProduct->getCategory()}] - -[{block name="d3_ga4_add_to_cart_block"}] - [{capture assign=d3_ga4_add_to_cart}] - [{strip}] - $("#toBasket").click(function(event) { - dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */ - - [{*** Debug cases ***}] - [{*event.preventDefault();*}] - - let iArtQuantity = $("#amountToBasket").val(); - - dataLayer.push({ - 'isAddToBasket': true, - 'event':'add_to_cart', - 'eventLabel': 'add_to_cart', - 'ecommerce': { - 'currency': "[{$currency->name}]", - 'value': iArtQuantity*[{$d3PriceObject->getPrice()}], - 'items': [ - { - 'item_id': '[{$gtmProduct->getFieldData('oxartnum')}]', - 'item_name': '[{$gtmProduct->getFieldData('oxtitle')}]', - 'price': [{$d3PriceObject->getPrice()}], - 'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]', - 'item_variant': '[{if $gtmProduct->getFieldData('oxvarselect')}][{$gtmProduct->getFieldData('oxvarselect')}][{/if}]', - [{if $gtmCategory}] - 'item_category': '[{$gtmCategory->getSplitCategoryArray(0)}]', - 'item_category_2':'[{$gtmCategory->getSplitCategoryArray(1)}]', - 'item_category_3':'[{$gtmCategory->getSplitCategoryArray(2)}]', - 'item_category_4':'[{$gtmCategory->getSplitCategoryArray(3)}]', - 'item_list_name':'[{$gtmCategory->getSplitCategoryArray()}]', - [{/if}] - 'quantity': iArtQuantity - } - ] - }[{if $oViewConf->isDebugModeOn()}], - 'debug_mode': 'true' - [{/if}] - }); - }); - [{/strip}] - [{/capture}] - [{oxscript add=$d3_ga4_add_to_cart}] -[{/block}] \ No newline at end of file diff --git a/Application/views/tpl/page/account/d3gtmnoticelist.tpl b/Application/views/tpl/page/account/d3gtmnoticelist.tpl new file mode 100644 index 0000000..1f7ee6c --- /dev/null +++ b/Application/views/tpl/page/account/d3gtmnoticelist.tpl @@ -0,0 +1,18 @@ +[{capture append="oxidBlock_content"}] + [{assign var="template_title" value="MY_WISH_LIST"|oxmultilangassign}] +
[{oxmultilang ident="WISH_LIST_EMPTY"}]
+ [{/if}] + + [{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] + + [{insert name="oxid_tracker" title=$template_title}] + [{/capture}] +[{capture append="oxidBlock_sidebar"}] + [{include file="page/account/inc/account_menu.tpl" active_link="noticelist"}] + [{/capture}] +[{include file="layout/page.tpl" sidebar="Left"}] \ No newline at end of file diff --git a/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl b/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl new file mode 100644 index 0000000..c5828da --- /dev/null +++ b/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl @@ -0,0 +1,32 @@ +[{capture append="oxidBlock_content"}] + [{assign var="template_title" value="LISTMANIA"|oxmultilangassign}] + [{assign var="_actvrecommlist" value=$oView->getActiveRecommList()}] + ++ [{oxmultilang ident="GIFT_REGISTRY_EMPTY"}] +
+ [{/if}] + + [{include file="event/add_to_cart.tpl" htmlIdAmountOfArticles='#amountToBasket'}] + + [{insert name="oxid_tracker" title=$template_title}] +[{/capture}] +[{capture append="oxidBlock_sidebar"}] + [{include file="page/account/inc/account_menu.tpl" active_link="wishlist"}] +[{/capture}] +[{include file="layout/page.tpl" sidebar="Left"}] \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cc63888..242c022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,6 +129,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.1...2.0) - 2023-01-20 ### Added - using of ContainerFactory in ViewConfig +## [1.15.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.14.0...1.15.0) - 2024-01-25 +### Fixed +- missing Component-ArticleDetails extension, missing ManufacturerListController extension + +## [1.14.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.13.0...1.14.0) - 2024-01-03 +### Added +- add_to_cart Event to several new shop-pages (landing-page, Account, category article-list, start) +- PHPStan code-cleanup +### Changed +- template structure +- code cleanup + ## [1.13.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.12.0...1.13.0) - 2023-09-13 ### Added - extended Docs diff --git a/Docs/README.md b/Docs/README.md index 8df6e03..8c5afaf 100644 --- a/Docs/README.md +++ b/Docs/README.md @@ -1,6 +1,6 @@ # Technische Doku ## GA4 Events / Customizing -Für alle implementierten GA4 Events existieren Templates unter `source/modules/d3/googleanalytics4/Application/views/ga4/`, dabei entspricht der Dateiname dem Eventnamen in GA4. +Für alle implementierten GA4 Events existieren Templates unter `source/modules/d3/googleanalytics4/Application/views/event/`, dabei entspricht der Dateiname dem Eventnamen in GA4. Die Einbindung dieser Event-Templates erfolgt über TPL-Blöcke unter `source/modules/d3/googleanalytics4/Application/views/blocks/`. *Hinweis: nicht alle templates sind bereits gefüllt. Wünschen Sie die Implementierung eines unausgefüllten templates? Kommen Sie auf uns zu unter https://www.d3data.de/ diff --git a/IntelliSenseHelper.php b/IntelliSenseHelper.php index 08ac114..4666e9e 100644 --- a/IntelliSenseHelper.php +++ b/IntelliSenseHelper.php @@ -20,9 +20,49 @@ namespace D3\GoogleAnalytics4\Modules\Core{ namespace D3\GoogleAnalytics4\Modules\Application\Model{ class Category_parent extends \OxidEsales\Eshop\Application\Model\Category {} class Basket_parent extends \OxidEsales\Eshop\Application\Model\Basket {} + class Manufacturer_parent extends \OxidEsales\Eshop\Application\Model\Manufacturer {} } namespace D3\GoogleAnalytics4\Modules\Application\Controller{ + + use OxidEsales\Eshop\Application\Controller\AccountNoticeListController; + use OxidEsales\Eshop\Application\Controller\AccountRecommlistController; + use OxidEsales\Eshop\Application\Controller\AccountWishlistController; + use OxidEsales\Eshop\Application\Controller\Admin\ManufacturerController; + use OxidEsales\Eshop\Application\Controller\ArticleListController; + use OxidEsales\Eshop\Application\Controller\SearchController; + use OxidEsales\Eshop\Application\Controller\StartController; + class BasketController_parent extends \OxidEsales\Eshop\Application\Controller\BasketController {} class ThankYouController_parent extends \OxidEsales\Eshop\Application\Controller\ThankYouController {} + + class ArticleListController_AddToCartHelpMethods_parent extends ArticleListController {} + + class ArticleDetailsController_parent extends \OxidEsales\Eshop\Application\Controller\ArticleDetailsController {} + + class d3GtmAccountNoticeListController_parent extends AccountNoticeListController {} + + class d3GtmAccountRecommlistController_parent extends AccountRecommlistController {} + + class d3GtmAccountWishlistController_parent extends AccountWishlistController {} + + class d3GtmStartController_parent extends StartController {} + + class d3GtmSearchController_parent extends SearchController {} + + class d3GtmManufacturerListController_parent extends ManufacturerController {} +} + +namespace D3\GoogleAnalytics4\Modules\Application\Component{ + + use OxidEsales\Eshop\Application\Component\BasketComponent; + + class d3GtmBasketComponentExtension_parent extends BasketComponent {} +} + +namespace D3\GoogleAnalytics4\Modules\Application\Component\Widget{ + + use OxidEsales\Eshop\Application\Component\Widget\ArticleDetails; + + class d3GtmWidgetArticleDetails_parent extends ArticleDetails {} } \ No newline at end of file diff --git a/Modules/Application/Component/Widget/d3GtmWidgetArticleDetails.php b/Modules/Application/Component/Widget/d3GtmWidgetArticleDetails.php new file mode 100644 index 0000000..9bb5c43 --- /dev/null +++ b/Modules/Application/Component/Widget/d3GtmWidgetArticleDetails.php @@ -0,0 +1,18 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Component/d3GtmBasketComponentExtension.php b/Modules/Application/Component/d3GtmBasketComponentExtension.php new file mode 100644 index 0000000..609044a --- /dev/null +++ b/Modules/Application/Component/d3GtmBasketComponentExtension.php @@ -0,0 +1,77 @@ +setVariable('d3GtmAddToBasketTrigger', true); + + $iAmountArticlesAddedToCart = (int) Registry::getRequest()->getRequestEscapedParameter('am'); + + if ($iAmountArticlesAddedToCart){ + Registry::getSession()->setVariable('d3GtmAddToCartAmountArticles', $iAmountArticlesAddedToCart); + }else{ + Registry::getSession()->setVariable('d3GtmAddToCartAmountArticles', 1); + } + + return $return; + } + + /** + * @return int + */ + public function getD3GtmAddToCartAmountArticles() :int + { + $iAmount = Registry::getSession()->getVariable('d3GtmAddToCartAmountArticles'); + + Registry::getSession()->deleteVariable('d3GtmAddToCartAmountArticles'); + + return (int) $iAmount; + } + + /** + * @return bool + */ + public function getAddToBasketDecision() :bool + { + $decision = Registry::getSession()->getVariable('d3GtmAddToBasketTrigger'); + + Registry::getSession()->setVariable('d3GtmAddToBasketTrigger', false); + + return (bool) $decision; + } + + /** + * @return Article|null + */ + public function d3GtmRequestedArticleLoadedByAnid() + { + $sAnid = Registry::getRequest()->getRequestEscapedParameter('anid'); + + $oArticle = null; + + if ($sAnid){ + /** @var Article $oArticle */ + $oArticle = oxNew(Article::class); + $oArticle->load($sAnid); + } + + return $oArticle; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/ArticleDetailsController.php b/Modules/Application/Controller/ArticleDetailsController.php new file mode 100644 index 0000000..a2aee20 --- /dev/null +++ b/Modules/Application/Controller/ArticleDetailsController.php @@ -0,0 +1,15 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/ArticleListController_AddToCartHelpMethods.php b/Modules/Application/Controller/ArticleListController_AddToCartHelpMethods.php new file mode 100644 index 0000000..49ea298 --- /dev/null +++ b/Modules/Application/Controller/ArticleListController_AddToCartHelpMethods.php @@ -0,0 +1,15 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $render; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/BasketController.php b/Modules/Application/Controller/BasketController.php index 8e0bdff..e3fecb8 100644 --- a/Modules/Application/Controller/BasketController.php +++ b/Modules/Application/Controller/BasketController.php @@ -11,7 +11,7 @@ use oxSystemComponentException; class BasketController extends BasketController_parent { /** - * @throws oxSystemComponentException + * @return string */ public function render() { @@ -33,22 +33,18 @@ class BasketController extends BasketController_parent $aProducts = Registry::getRequest()->getRequestEscapedParameter('aproducts'); // collecting specified item - $sProductId = $sProductId ?? Registry::getRequest()->getRequestEscapedParameter('aid'); + $sProductId = Registry::getRequest()->getRequestEscapedParameter('aid'); if ($sProductId) { // additionally fetching current product info - $dAmount = $dAmount ?? Registry::getRequest()->getRequestEscapedParameter('am'); + $dAmount = Registry::getRequest()->getRequestEscapedParameter('am'); // select lists - $aSel = $aSel ?? Registry::getRequest()->getRequestEscapedParameter('sel'); + $aSel = Registry::getRequest()->getRequestEscapedParameter('sel'); - // persistent parameters - if (empty($aPersParam)) { + /** @var BasketComponent $oBasketComponent */ + $oBasketComponent = $this->getComponent('oxcmp_basket'); - /** @var BasketComponent $oBasketComponent */ - $oBasketComponent = $this->getComponent('oxcmp_basket'); - - $aPersParam = $oBasketComponent->__call('getPersistedParameters', []); - } + $aPersParam = $oBasketComponent->__call('getPersistedParameters', []); $sBasketItemId = Registry::getRequest()->getRequestEscapedParameter('bindex'); diff --git a/Modules/Application/Controller/ThankYouController.php b/Modules/Application/Controller/ThankYouController.php index 215503a..dd90187 100644 --- a/Modules/Application/Controller/ThankYouController.php +++ b/Modules/Application/Controller/ThankYouController.php @@ -3,6 +3,7 @@ namespace D3\GoogleAnalytics4\Modules\Application\Controller; use OxidEsales\Eshop\Application\Model\Country; +use OxidEsales\Eshop\Application\Model\Order; class ThankYouController extends ThankYouController_parent { @@ -11,7 +12,9 @@ class ThankYouController extends ThankYouController_parent */ public function d3GAGetUserCountry() { - $sCountryId = $this->getOrder()->getFieldData('oxbillcountryid'); + /** @var Order $oOrder */ + $oOrder = $this->getOrder(); + $sCountryId = $oOrder->getFieldData('oxbillcountryid'); /** @var Country $oCountry */ $oCountry = oxNew(Country::class); diff --git a/Modules/Application/Controller/d3GtmAccountNoticeListController.php b/Modules/Application/Controller/d3GtmAccountNoticeListController.php new file mode 100644 index 0000000..8c62241 --- /dev/null +++ b/Modules/Application/Controller/d3GtmAccountNoticeListController.php @@ -0,0 +1,17 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/d3GtmAccountRecommlistController.php b/Modules/Application/Controller/d3GtmAccountRecommlistController.php new file mode 100644 index 0000000..6e9e825 --- /dev/null +++ b/Modules/Application/Controller/d3GtmAccountRecommlistController.php @@ -0,0 +1,17 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/d3GtmAccountWishlistController.php b/Modules/Application/Controller/d3GtmAccountWishlistController.php new file mode 100644 index 0000000..731d6d4 --- /dev/null +++ b/Modules/Application/Controller/d3GtmAccountWishlistController.php @@ -0,0 +1,17 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/d3GtmManufacturerListController.php b/Modules/Application/Controller/d3GtmManufacturerListController.php new file mode 100644 index 0000000..8064beb --- /dev/null +++ b/Modules/Application/Controller/d3GtmManufacturerListController.php @@ -0,0 +1,18 @@ +addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/d3GtmSearchController.php b/Modules/Application/Controller/d3GtmSearchController.php new file mode 100644 index 0000000..213937b --- /dev/null +++ b/Modules/Application/Controller/d3GtmSearchController.php @@ -0,0 +1,23 @@ +getComponents())){ + $this->addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + } + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Controller/d3GtmStartController.php b/Modules/Application/Controller/d3GtmStartController.php new file mode 100644 index 0000000..67816ce --- /dev/null +++ b/Modules/Application/Controller/d3GtmStartController.php @@ -0,0 +1,19 @@ +getComponents())){ + $this->addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket')); + } + + return $return; + } +} \ No newline at end of file diff --git a/Modules/Application/Model/Basket.php b/Modules/Application/Model/Basket.php index 9c7fa61..2cde7ef 100644 --- a/Modules/Application/Model/Basket.php +++ b/Modules/Application/Model/Basket.php @@ -7,7 +7,7 @@ use OxidEsales\Eshop\Application\Model\Payment; class Basket extends Basket_parent { /** - * @return void + * @return string */ public function getPaymentOnPaymentId() :string { diff --git a/Modules/Application/Model/Category.php b/Modules/Application/Model/Category.php index 1f27087..713e4a5 100644 --- a/Modules/Application/Model/Category.php +++ b/Modules/Application/Model/Category.php @@ -8,9 +8,9 @@ class Category extends Category_parent * @param int $indexOfArray * @return string */ - public function getSplitCategoryArray(int $indexOfArray = -1) :string + public function getSplitCategoryArray(int $indexOfArray = -1, bool $bShallTakeStd = false) :string { - if ($indexOfArray > -1){ + if ($bShallTakeStd){ $splitCatArray = array_values( array_filter( @@ -26,7 +26,7 @@ class Category extends Category_parent ) ); - if ($splitCatArray[$indexOfArray]){ + if (($indexOfArray >= 0) and (false === empty($splitCatArray[$indexOfArray]))){ return $splitCatArray[$indexOfArray]; }else{ return ""; diff --git a/Modules/Application/Model/Manufacturer.php b/Modules/Application/Model/Manufacturer.php index 8ecae9a..1d98dda 100644 --- a/Modules/Application/Model/Manufacturer.php +++ b/Modules/Application/Model/Manufacturer.php @@ -8,9 +8,9 @@ class Manufacturer extends Manufacturer_parent * @param int $indexOfArray * @return string */ - public function getSplitCategoryArray(int $indexOfArray = -1) :string + public function getSplitCategoryArray(int $indexOfArray = -1, bool $bShallTakeStd = false) :string { - if ($indexOfArray > -1){ + if ($bShallTakeStd){ $splitCatArray = array_values( array_filter( @@ -26,7 +26,7 @@ class Manufacturer extends Manufacturer_parent ) ); - if ($splitCatArray[$indexOfArray]){ + if (($indexOfArray >= 0) and (false === empty($splitCatArray[$indexOfArray]))){ return $splitCatArray[$indexOfArray]; }else{ return ""; diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index feeb95d..5fdce53 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -15,6 +15,7 @@ namespace D3\GoogleAnalytics4\Modules\Core; use D3\GoogleAnalytics4\Application\Model\ManagerHandler; use D3\GoogleAnalytics4\Application\Model\ManagerTypes; use OxidEsales\Eshop\Application\Controller\FrontendController; +use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Registry; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; @@ -180,7 +181,8 @@ class ViewConfig extends ViewConfig_parent $oConfig = Registry::getConfig(); $oView = $oConfig->getTopActiveView(); - /** @var FrontendController $oShop */ + + /** @var User|false|null $oUser */ $oUser = $oConfig->getUser(); $cl = $this->getTopActiveClassName(); @@ -203,8 +205,8 @@ class ViewConfig extends ViewConfig_parent 'title' => $oView->getTitle(), 'cl' => $cl, ], - 'userid' => ($oUser ? $oUser->getId() : false), - 'sessionid' => session_id() ?? false, + 'userid' => $oUser instanceof User ? $oUser->getId() : false, + 'sessionid' => session_id(), //'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown" ]; diff --git a/composer.json b/composer.json index 149fafa..bcf4f2d 100644 --- a/composer.json +++ b/composer.json @@ -46,8 +46,8 @@ "require": { "php": ">=7.1", "oxid-esales/oxideshop-ce": "^6.5", - "google/apiclient":" ^2.0" - }, + "google/apiclient":" ^2.0", + "phpstan/phpstan": "^1.8" }, "autoload": { "psr-4": { "D3\\GoogleAnalytics4\\": "../../../source/modules/d3/googleanalytics4" diff --git a/metadata.php b/metadata.php index 4e97a11..9ee32d3 100755 --- a/metadata.php +++ b/metadata.php @@ -2,12 +2,28 @@ use D3\GoogleAnalytics4\Modules\Application\Controller\BasketController; +use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmAccountNoticeListController; +use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmAccountRecommlistController; +use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmAccountWishlistController; +use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmManufacturerListController as d3GtmManufacturerListController; +use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmSearchController; +use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmStartController; use D3\GoogleAnalytics4\Modules\Application\Controller\ThankYouController; use D3\GoogleAnalytics4\Modules\Application\Model\Basket as Basket; use D3\GoogleAnalytics4\Modules\Application\Model\Category as Category; use D3\GoogleAnalytics4\Modules\Application\Model\Manufacturer as Manufacturer; use D3\GoogleAnalytics4\Modules\Core\ViewConfig; +use OxidEsales\Eshop\Application\Component\BasketComponent as OEBasketComponent; +use OxidEsales\Eshop\Application\Component\Widget\ArticleDetails as OEArticleDetails; +use OxidEsales\Eshop\Application\Controller\AccountNoticeListController as OEAccountNoticeListController; +use OxidEsales\Eshop\Application\Controller\AccountRecommlistController as OEAccountRecommlistController; +use OxidEsales\Eshop\Application\Controller\AccountWishlistController as OEAccountWishlistController; +use OxidEsales\Eshop\Application\Controller\ArticleDetailsController as OEArticleDetailsController; +use OxidEsales\Eshop\Application\Controller\ArticleListController as OEArticleListController; use OxidEsales\Eshop\Application\Controller\BasketController as OEBasketController; +use OxidEsales\Eshop\Application\Controller\ManufacturerListController as OEManufacturerListController; +use OxidEsales\Eshop\Application\Controller\SearchController as OESearchController; +use OxidEsales\Eshop\Application\Controller\StartController as OEStartController; use OxidEsales\Eshop\Application\Controller\ThankYouController as OEThankYouController; use OxidEsales\Eshop\Application\Model\Basket as OEBasket; use OxidEsales\Eshop\Application\Model\Category as OECategory; @@ -34,14 +50,46 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'extend' => [ - OEViewConfig::class => ViewConfig::class, - OECategory::class => Category::class, - OEBasket::class => Basket::class, - OEBasketController::class => BasketController::class, - OEManufacturer::class => Manufacturer::class, - OEThankYouController::class => ThankYouController::class + // Core + OEViewConfig::class => ViewConfig::class, + + // Model + OECategory::class => Category::class, + OEBasket::class => Basket::class, + OEManufacturer::class => Manufacturer::class, + + // Controller + OEBasketController::class => BasketController::class, + OEThankYouController::class => ThankYouController::class, + OEArticleListController::class => ArticleListController_AddToCartHelpMethods::class, + OEArticleDetailsController::class => ArticleDetailsController::class, + OEAccountNoticeListController::class => d3GtmAccountNoticeListController::class, + OEAccountRecommlistController::class => d3GtmAccountRecommlistController::class, + OEAccountWishlistController::class => d3GtmAccountWishlistController::class, + OEStartController::class => d3GtmStartController::class, + OESearchController::class => d3GtmSearchController::class, + OEManufacturerListController::class => d3GtmManufacturerListController::class, + + // Component + OEArticleDetails::class => d3GtmWidgetArticleDetails::class, + OEBasketComponent::class => d3GtmBasketComponentExtension::class, + ], + 'templates' => [ + // Event files that store the GA4 Event-Information + 'event/add_to_cart.tpl' => 'd3/googleanalytics4/Application/views/event/add_to_cart.tpl', + 'event/view_item.tpl' => 'd3/googleanalytics4/Application/views/event/view_item.tpl', + 'event/view_cart.tpl' => 'd3/googleanalytics4/Application/views/event/view_cart.tpl', + 'event/purchase.tpl' => 'd3/googleanalytics4/Application/views/event/purchase.tpl', + 'event/view_item_list.tpl' => 'd3/googleanalytics4/Application/views/event/view_item_list.tpl', + 'event/view_search_result.tpl' => 'd3/googleanalytics4/Application/views/event/view_search_result.tpl', + 'event/remove_from_cart.tpl' => 'd3/googleanalytics4/Application/views/event/remove_from_cart.tpl', + + // complete overwritten file of OXID-Originals + // the path of the template-name is the original path to the file in OXID-context from tpl/-> + 'page/account/d3gtmnoticelist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmnoticelist.tpl', + 'page/account/d3gtmrecommendationlist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl', + 'page/account/d3gtmwishlist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmwishlist.tpl', ], - 'templates' => [], 'blocks' => [ // tag manager js [ @@ -79,28 +127,40 @@ $aModule = [ [ 'template' => 'page/list/list.tpl', 'block' => 'page_list_productlist', - 'file' => '/Application/views/ga4/view_item_list.tpl', + 'file' => '/Application/views/blocks/view_item_list.tpl', 'position' => 150 ], // view_search_result [ 'template' => 'page/search/search.tpl', 'block' => 'search_results', - 'file' => '/Application/views/ga4/view_search_result.tpl', + 'file' => '/Application/views/blocks/view_search_result.tpl', 'position' => 150 ], // add_to_cart [ 'template' => 'page/details/inc/productmain.tpl', 'block' => 'details_productmain_tobasket', - 'file' => '/Application/views/ga4/add_to_cart.tpl', + 'file' => '/Application/views/blocks/details_productmain_tobasket.tpl', + 'position' => 150 + ], + [ + 'template' => 'page/list/list.tpl', + 'block' => 'page_list_listbody', + 'file' => '/Application/views/blocks/page_list_listbody.tpl', + 'position' => 150 + ], + [ + 'template' => 'page/shop/start.tpl', + 'block' => 'start_welcome_text', + 'file' => '/Application/views/blocks/start_welcome_text.tpl', 'position' => 150 ], // remove_from_cart [ 'template' => 'page/checkout/basket.tpl', 'block' => 'checkout_basket_main', - 'file' => '/Application/views/ga4/remove_from_cart.tpl', + 'file' => '/Application/views/blocks/remove_from_cart.tpl', 'position' => 150 ] ], diff --git a/phpstan.neon b/phpstan.neon index b6e0779..6ade348 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,16 @@ parameters: scanFiles: - IntelliSenseHelper.php - - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php - - ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php - level: 9 - phpVersion: 70100 - checkMissingIterableValueType: false + - ../../../../Shops/CE/6.1.x/616_/vendor/oxid-esales/oxideshop-ce/source/bootstrap.php + - ../../../../Shops/CE/6.1.x/616_/vendor/oxid-esales/oxideshop-ce/source/oxfunctions.php + - ../../../../Shops/CE/6.1.x/616_/vendor/oxid-esales/oxideshop-ce/source/overridablefunctions.php + scanDirectories: + - ../../../../Shops/CE/6.1.x/616_/vendor/oxid-esales ignoreErrors: - - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' + - '#.*is not subtype of Throwable.*#' + - '#\$sValue of method OxidEsales\\EshopCommunity\\Core\\Controller\\BaseController::addTplParam\(\) expects string,[ a-zA-Z\.]+#' + paths: + - ./ + level: 5 + phpVersion: 70200 + checkMissingIterableValueType: false