Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit bd4e3a3

Browse files
authored
Changed display widget hook strategy; refs #45733 (#34)
1 parent dcf2412 commit bd4e3a3

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/Hook/CommonHook.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@
2525

2626
use AxeptiocookiesAddon\Service\HookService;
2727
use AxeptiocookiesAddon\Smarty\CookiesCompletePrefilter;
28+
use AxeptiocookiesAddon\Smarty\WidgetPrefilter;
2829
use AxeptiocookiesAddon\Utils\ServiceContainer;
2930
use AxeptiocookiesClasslib\Hook\AbstractHook;
3031

3132
class CommonHook extends AbstractHook
3233
{
3334
const AVAILABLE_HOOKS = [
34-
'displayFooter',
3535
'actionDispatcherBefore',
36+
'displayAxeptioWidget',
3637
];
3738

38-
public function displayFooter($params)
39+
public function displayAxeptioWidget($params)
3940
{
41+
if (\Tools::getValue('ajax') !== false) {
42+
return;
43+
}
44+
4045
/** @var HookService $hookService */
4146
$hookService = ServiceContainer::getInstance()->get(HookService::class);
4247

@@ -67,6 +72,14 @@ public function actionDispatcherBefore($params)
6772
],
6873
'handleCookiesComplete'
6974
);
75+
\Context::getContext()->smarty->registerFilter(
76+
'pre',
77+
[
78+
WidgetPrefilter::class,
79+
'addAxeptioWidget',
80+
],
81+
'addAxeptioWidget'
82+
);
7083
}
7184

7285
if ($params['controller_type'] != \Dispatcher::FC_FRONT) {

src/Smarty/WidgetPrefilter.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright since 2022 Axeptio
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License (AFL 3.0)
8+
* that is bundled with this package in the file LICENSE.md.
9+
* It is also available through the world-wide-web at this URL:
10+
* https://opensource.org/licenses/AFL-3.0
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to tech@202-ecommerce.com so we can send you a copy immediately.
14+
*
15+
* @author 202 ecommerce <tech@202-ecommerce.com>
16+
* @copyright 2022 Axeptio
17+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License (AFL 3.0)
18+
*/
19+
20+
namespace AxeptiocookiesAddon\Smarty;
21+
22+
if (!defined('_PS_VERSION_')) {
23+
exit;
24+
}
25+
26+
class WidgetPrefilter
27+
{
28+
public static function addAxeptioWidget($source)
29+
{
30+
$stringToSearch = '/<\/body>/ims';
31+
preg_match($stringToSearch, $source, $matches, PREG_OFFSET_CAPTURE, 0);
32+
if (empty($matches)) {
33+
return $source;
34+
}
35+
36+
$replace = "{hook h='displayAxeptioWidget'}\r" . '</body>';
37+
38+
return preg_replace($stringToSearch, $replace, $source);
39+
}
40+
}

upgrade/upgrade-2.0.8.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
function upgrade_module_2_0_8($module)
2929
{
3030
try {
31+
$installer = new \AxeptiocookiesClasslib\Install\ModuleInstaller($module);
32+
$installer->registerHooks();
3133
$cache = new \AxeptiocookiesAddon\Cache\ProjectCache();
3234
$cache->cleanCacheDirectory();
3335
\Tools::clearCache();

0 commit comments

Comments
 (0)