Compare commits

...

2 Commits

Author SHA1 Message Date
MaxBUhe 22bec30621 add remove_from_cart 2023-08-03 14:57:26 +02:00
MaxBUhe 49bfd5be09 bump changelog && version to 2.10.0 2023-08-02 11:55:28 +02:00
5 changed files with 170 additions and 5 deletions

View File

@ -0,0 +1,44 @@
[{$smarty.block.parent}]
[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}]
[{if $hasBeenReloaded}]
[{strip}]
[{capture assign=d3_ga4_view_cart}]
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'remove_from_cart',
'eventLabel':'remove_from_cart',
'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=$toRemoveArticles->getArray() name=gtmRemovedItems item=rmItem key=rmItemindex}]
[{assign var="d3oItemPrice" value=$rmItem->getPrice()}]
[{assign var="gtmBasketItemCategory" value=$rmItem->getCategory()}]
{
'item_id': '[{$rmItem->getFieldData('oxartnum')}]',
'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_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': '[{$rmItem->getFieldData('d3AmountThatGotRemoved')}]',
'position': [{$smarty.foreach.gtmRemovedItems.index}]
}[{if !$smarty.foreach.gtmRemovedItems.last}],[{/if}]
[{/foreach}]
]
}
});
[{/capture}]
[{/strip}]
[{oxscript add=$d3_ga4_view_cart}]
[{/if}]

View File

@ -4,15 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.9.2](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.7.0...2.8.0) - 2023-06-29
## [2.10.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.9.2...2.10.0) - 2023-08-02
### Added
- new Event "remove_from_cart"
## [2.9.2](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.9.1...2.9.2) - 2023-06-29
### Fixed
- wrong variable for category-object check
## [2.9.1](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.7.0...2.8.0) - 2023-06-27
## [2.9.1](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.9.0...2.9.1) - 2023-06-27
### Fixed
- deny method call on no category
## [2.9.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.7.0...2.8.0) - 2023-06-27
## [2.9.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.8.0...2.9.0) - 2023-06-27
### Added
- Cookiefirst usability

View File

@ -20,4 +20,8 @@ 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 {}
}
namespace D3\GoogleAnalytics4\Modules\Application\Controller{
class BasketController_parent extends \OxidEsales\Eshop\Application\Controller\BasketController {}
}

View File

@ -0,0 +1,103 @@
<?php
namespace D3\GoogleAnalytics4\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Component\BasketComponent;
use OxidEsales\Eshop\Application\Model\Article;
use OxidEsales\Eshop\Application\Model\ArticleList;
use OxidEsales\Eshop\Core\Registry;
use oxSystemComponentException;
class BasketController extends BasketController_parent
{
/**
* @throws oxSystemComponentException
*/
public function render()
{
$return = parent::render();
$this->d3GA4getRemovedArticlesListObject();
return $return;
}
/**
* @return void
* @throws oxSystemComponentException
*/
public function d3GA4getRemovedArticlesListObject() :void
{
$this->addTplParam('hasBeenReloaded', false);
// collecting items to add
$aProducts = Registry::getRequest()->getRequestEscapedParameter('aproducts');
// collecting specified item
$sProductId = $sProductId ?? Registry::getRequest()->getRequestEscapedParameter('aid');
if ($sProductId) {
// additionally fetching current product info
$dAmount = $dAmount ?? Registry::getRequest()->getRequestEscapedParameter('am');
// select lists
$aSel = $aSel ?? Registry::getRequest()->getRequestEscapedParameter('sel');
// persistent parameters
if (empty($aPersParam)) {
/** @var BasketComponent $oBasketComponent */
$oBasketComponent = $this->getComponent('oxcmp_basket');
$aPersParam = $oBasketComponent->__call('getPersistedParameters', []);
}
$sBasketItemId = Registry::getRequest()->getRequestEscapedParameter('bindex');
$aProducts[$sProductId] = ['am' => $dAmount,
'sel' => $aSel,
'persparam' => $aPersParam,
'basketitemid' => $sBasketItemId
];
}
if (is_array($aProducts) && count($aProducts)) {
$toRemoveArticleIdList = [];
$artIdOnArtAmountList = [];
if (Registry::getRequest()->getRequestEscapedParameter('removeBtn') !== null
or Registry::getRequest()->getRequestParameter('updateBtn') !== null) {
//setting amount to 0 if removing article from basket
foreach ($aProducts as $sProductId => $aProduct) {
if ((isset($aProduct['remove']) && $aProduct['remove']) or intval($aProduct['am']) === 0) {
if (!in_array($aProduct, $toRemoveArticleIdList)) {
$toRemoveArticleIdList[] = $aProduct['aid'];
$artIdOnArtAmountList[$aProduct['aid']] = $aProduct['am'];
}
$aProducts[$sProductId]['am'] = 0;
#for GA4 Event
$this->addTplParam('hasBeenReloaded', true);
} else {
unset($aProducts[$sProductId]);
}
}
}
$oArtList = oxNew(ArticleList::class);
$oArtList->loadIds($toRemoveArticleIdList);
#dumpVar($this->getBasketArticles());
/** @var Article $item */
foreach ($oArtList->getArray() as $item){
foreach ($artIdOnArtAmountList as $artId => $artAmount){
if ($item->getId() === $artId){
$item->assign(['d3AmountThatGotRemoved' => $artAmount]);
}
}
}
$this->addTplParam('toRemoveArticles', $oArtList);
}
}
}

View File

@ -1,8 +1,10 @@
<?php
use D3\GoogleAnalytics4\Modules\Application\Controller\BasketController;
use D3\GoogleAnalytics4\Modules\Application\Model\Basket as Basket;
use D3\GoogleAnalytics4\Modules\Application\Model\Category as Category;
use D3\GoogleAnalytics4\Modules\Core\ViewConfig;
use OxidEsales\Eshop\Application\Controller\BasketController as OEBasketController;
use OxidEsales\Eshop\Application\Model\Basket as OEBasket;
use OxidEsales\Eshop\Application\Model\Category as OECategory;
use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig;
@ -22,14 +24,15 @@ $aModule = [
Die Entwicklung basiert auf einem Fork von Marat Bedoev - <a href='https://github.com/vanilla-thunder/oxid-module-gtm'>Github-Link</a>
",
'thumbnail' => 'thumbnail.png',
'version' => '2.9.2',
'version' => '2.10.0',
'author' => 'Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
'extend' => [
OEViewConfig::class => ViewConfig::class,
OECategory::class => Category::class,
OEBasket::class => Basket::class
OEBasket::class => Basket::class,
OEBasketController::class => BasketController::class
],
'templates' => [],
'blocks' => [
@ -85,6 +88,13 @@ $aModule = [
'block' => 'details_productmain_tobasket',
'file' => '/Application/views/ga4/add_to_cart.tpl',
'position' => 150
],
// remove_from_cart
[
'template' => 'page/checkout/basket.tpl',
'block' => 'checkout_basket_main',
'file' => '/Application/views/ga4/remove_from_cart.tpl',
'position' => 150
]
],
'settings' => [