From a93b1cf582f5769623f057f3167278fc78ddccc4 Mon Sep 17 00:00:00 2001 From: MaxBuhe01 Date: Mon, 26 Jun 2023 17:41:00 +0200 Subject: [PATCH] [working state] add rel_2.x adjustments --- Application/Model/ManagerHandler.php | 53 ++++++++++++ Application/Model/ManagerTypes.php | 60 ++++++++++++++ Application/views/blocks/_gtm_js.tpl | 38 ++++----- Application/views/blocks/checkout_s1.tpl | 33 -------- Application/views/blocks/checkout_s5.tpl | 36 --------- Application/views/blocks/purchase.tpl | 49 ++++++++++++ Application/views/blocks/view_cart.tpl | 42 ++++++++++ Application/views/blocks/view_item.tpl | 7 +- Application/views/ga4/add_to_cart.tpl | 11 ++- Application/views/ga4/view_item_list.tpl | 10 ++- .../{search.tpl => view_search_result.tpl} | 8 +- IntelliSenseHelper.php | 5 ++ Modules/Application/Model/Basket.php | 23 ++++++ Modules/Application/Model/Category.php | 44 ++++++++++ Modules/Core/ViewConfig.php | 80 +++++++------------ README.md | 8 +- metadata.php | 24 +++--- 17 files changed, 364 insertions(+), 167 deletions(-) create mode 100644 Application/Model/ManagerHandler.php create mode 100644 Application/Model/ManagerTypes.php delete mode 100644 Application/views/blocks/checkout_s1.tpl delete mode 100644 Application/views/blocks/checkout_s5.tpl create mode 100644 Application/views/blocks/purchase.tpl create mode 100644 Application/views/blocks/view_cart.tpl rename Application/views/ga4/{search.tpl => view_search_result.tpl} (71%) mode change 100755 => 100644 create mode 100644 Modules/Application/Model/Basket.php create mode 100644 Modules/Application/Model/Category.php diff --git a/Application/Model/ManagerHandler.php b/Application/Model/ManagerHandler.php new file mode 100644 index 0000000..ef64abc --- /dev/null +++ b/Application/Model/ManagerHandler.php @@ -0,0 +1,53 @@ +getManagerList(); + + foreach ($aManagerList as $managerName){ + if ($oViewConfig->isModuleActive($managerName)){ + return $managerName; + } + } + + return $this->getExplicitManager(); + } + + /** + * @return string + */ + public function getModuleSettingExplicitManagerSelectValue() :string + { + return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_STD_MANAGER'); + } + + /** + * @return string + */ + public function getExplicitManager() :string + { + $sPotentialManagerName = $this->getModuleSettingExplicitManagerSelectValue(); + + /** @var ManagerTypes $oManagerTypes */ + $oManagerTypes = oxNew(ManagerTypes::class); + return $oManagerTypes->isManagerInList($sPotentialManagerName) + ? $sPotentialManagerName + : "NONE"; + } +} \ No newline at end of file diff --git a/Application/Model/ManagerTypes.php b/Application/Model/ManagerTypes.php new file mode 100644 index 0000000..7ebda76 --- /dev/null +++ b/Application/Model/ManagerTypes.php @@ -0,0 +1,60 @@ + self::EXTERNAL_SERVICE, + "agcookiecompliance" => self::AGCOOKIECOMPLIANCE, + "net_cookie_manager" => self::NET_COOKIE_MANAGER, + "oxps_usercentrics" => self::USERCENTRICS_MODULE, + "usercentrics" => self::USERCENTRICS_MANUALLY, + "consentmanager" => self::CONSENTMANAGER + ]; + } + + /** + * @param string $sManager + * @return bool + */ + public function isManagerInList(string $sManager) :bool + { + return in_array($sManager, $this->getManagerList(), true); + } +} \ No newline at end of file diff --git a/Application/views/blocks/_gtm_js.tpl b/Application/views/blocks/_gtm_js.tpl index d3d1075..de0cb3e 100755 --- a/Application/views/blocks/_gtm_js.tpl +++ b/Application/views/blocks/_gtm_js.tpl @@ -4,28 +4,22 @@ [{if $oViewConf->D3blShowGtmScript()}] - [{if $oViewConf->getGtmContainerId()}][{strip}] - - - - - [{if $oViewConf->getTopActionClassName() === "alist" }] - [{* include file="ga4_view_item_list.tpl" gtmCategory=$oView->getActiveCategory() gtmProducts=$oView->getArticleList() listtype=$oView->getListType() *}] - [{elseif $oViewConf->getTopActionClassName() === "details" }] - [{* include file="ga4_view_item.tpl" gtmProduct=$oView->getProduct() *}] - [{elseif $oViewConf->getTopActionClassName() === "search" }] - [{elseif $oViewConf->getTopActionClassName() === "basket" }] - [{/if}] - [{/strip}][{/if}] + [{if $oViewConf->getGtmContainerId()}] + [{strip}] + + + + [{/strip}] [{/if}] +[{/if}] [{$smarty.block.parent}] \ No newline at end of file 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/checkout_s5.tpl b/Application/views/blocks/checkout_s5.tpl deleted file mode 100644 index 0531e42..0000000 --- a/Application/views/blocks/checkout_s5.tpl +++ /dev/null @@ -1,36 +0,0 @@ -[{$smarty.block.parent}] - -[{strip}] - -[{/strip}] diff --git a/Application/views/blocks/purchase.tpl b/Application/views/blocks/purchase.tpl new file mode 100644 index 0000000..b97219e --- /dev/null +++ b/Application/views/blocks/purchase.tpl @@ -0,0 +1,49 @@ +[{$smarty.block.parent}] + +[{strip}] + +[{/strip}] diff --git a/Application/views/blocks/view_cart.tpl b/Application/views/blocks/view_cart.tpl new file mode 100644 index 0000000..79279c0 --- /dev/null +++ b/Application/views/blocks/view_cart.tpl @@ -0,0 +1,42 @@ +[{$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()}], + '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')}]', + '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()}]', + '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}] + ] + } + }); +[{/capture}][{/strip}] +[{oxscript add=$d3_ga4_view_cart}] \ No newline at end of file diff --git a/Application/views/blocks/view_item.tpl b/Application/views/blocks/view_item.tpl index 81e21b7..3e4b60a 100644 --- a/Application/views/blocks/view_item.tpl +++ b/Application/views/blocks/view_item.tpl @@ -5,6 +5,7 @@