[Added] add_to_cart to page/list/list.tpl, BasketComponent methods for trigger-behaviour add_to_cart
This commit is contained in:
parent
81aab10c4e
commit
a88fa570a8
@ -2,16 +2,76 @@
|
|||||||
|
|
||||||
namespace D3\GoogleAnalytics4\Modules\Application\Component;
|
namespace D3\GoogleAnalytics4\Modules\Application\Component;
|
||||||
|
|
||||||
|
use OxidEsales\Eshop\Application\Model\Article;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
|
||||||
class d3GtmBasketComponentExtension extends d3GtmBasketComponentExtension_parent
|
class d3GtmBasketComponentExtension extends d3GtmBasketComponentExtension_parent
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param $sProductId
|
||||||
|
* @param $dAmount
|
||||||
|
* @param $aSel
|
||||||
|
* @param $aPersParam
|
||||||
|
* @param $blOverride
|
||||||
|
* @return mixed|string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function toBasket($sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false)
|
public function toBasket($sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false)
|
||||||
{
|
{
|
||||||
$return = parent::toBasket($sProductId, $dAmount, $aSel, $aPersParam, $blOverride);
|
$return = parent::toBasket($sProductId, $dAmount, $aSel, $aPersParam, $blOverride);
|
||||||
|
|
||||||
Registry::getSession()->setVariable('d3GtmAddToBasketTrigger', true);
|
Registry::getSession()->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 $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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,38 +2,14 @@
|
|||||||
|
|
||||||
namespace D3\GoogleAnalytics4\Modules\Application\Controller;
|
namespace D3\GoogleAnalytics4\Modules\Application\Controller;
|
||||||
|
|
||||||
use OxidEsales\Eshop\Application\Model\Article;
|
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
|
||||||
|
|
||||||
class ArticleListController_AddToCartHelpMethods extends ArticleListController_AddToCartHelpMethods_parent
|
class ArticleListController_AddToCartHelpMethods extends ArticleListController_AddToCartHelpMethods_parent
|
||||||
{
|
{
|
||||||
/**
|
public function render()
|
||||||
* @return mixed|null
|
|
||||||
*/
|
|
||||||
public function getAddToBasketDecision() :bool
|
|
||||||
{
|
{
|
||||||
$decision = Registry::getSession()->getVariable('d3GtmAddToBasketTrigger');
|
$render = parent::render();
|
||||||
|
|
||||||
Registry::getSession()->setVariable('d3GtmAddToBasketTrigger', false);
|
$this->addTplParam('d3CmpBasket', $this->getComponent('oxcmp_basket'));
|
||||||
|
|
||||||
return (bool) $decision;
|
return $render;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user