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

Commit dcf2412

Browse files
authored
Removed lang context from front; refs #45569 (#33)
* Removed lang context from front; refs #45569 * Fixed test; refs #45569
1 parent cd028da commit dcf2412

File tree

9 files changed

+105
-156
lines changed

9 files changed

+105
-156
lines changed

202/test/AxeptiocookiesAddon/Hook/CommonHookTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public function testActionDispatcherBeforeFrontReplace()
4343
return false;
4444
});
4545
global $_COOKIE;
46-
$_COOKIE[HookService::DEFAULT_COOKIE_NAME] = json_encode([
46+
$_COOKIE[HookService::DEFAULT_COOKIE_NAME . '_fr'] = json_encode([
47+
HookService::PS_MODULE_PREFIX . 'ps_emailsubscription' => true,
48+
]);
49+
$_COOKIE[HookService::DEFAULT_COOKIE_NAME . '_en'] = json_encode([
4750
HookService::PS_MODULE_PREFIX . 'ps_emailsubscription' => true,
4851
]);
4952

@@ -66,22 +69,4 @@ public function testActionDispatcherBeforeAdminEmpty()
6669
);
6770
$this->assertEmpty($result);
6871
}
69-
70-
public function testDisplayFooter()
71-
{
72-
self::truncateTables();
73-
ServiceContainer::getInstance()->get(ProjectCache::class)->cleanCacheDirectory();
74-
$result = $this->hookDispatcher->dispatch('displayFooter');
75-
$this->assertEmpty($result);
76-
}
77-
78-
public function testDisplayFooterFixtures()
79-
{
80-
$currentIsoCode = \Context::getContext()->language->iso_code;
81-
\Context::getContext()->language->iso_code = 'en';
82-
$this->createConfigurationFixtures();
83-
$result = $this->hookDispatcher->dispatch('displayFooter');
84-
\Context::getContext()->language->iso_code = $currentIsoCode;
85-
$this->assertNotEmpty($result);
86-
}
8772
}

202/test/AxeptiocookiesAddon/Service/CookieServiceTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ public function testGetModifiedHookExecListEmpty()
7272

7373
public function testGetModifiedHookExecListDependency()
7474
{
75+
$oldShop = \Context::getContext()->shop;
76+
$oldLanguage = \Context::getContext()->language;
77+
\Context::getContext()->language = new \Language(1);
78+
\Context::getContext()->shop = new \Shop(1);
7579
$this->truncateTables();
7680
$this->hookService->purgeCache();
7781
$data = $this->createConfigurationFixtures();
7882

7983
$result = $this->cookieService->getModifiedHookExecList($data['hooks']);
80-
84+
\Context::getContext()->language = $oldLanguage;
85+
\Context::getContext()->shop = new $oldShop;
8186
$this->assertEmpty($result);
8287
}
8388

@@ -88,7 +93,7 @@ public function testGetModifiedHookExecListDependencyTrue()
8893
$data = $this->createConfigurationFixtures();
8994

9095
global $_COOKIE;
91-
$_COOKIE[HookService::DEFAULT_COOKIE_NAME . '_' . \Language::getIsoById(1)] = json_encode([
96+
$_COOKIE[HookService::DEFAULT_COOKIE_NAME] = json_encode([
9297
HookService::PS_MODULE_PREFIX . 'ps_emailsubscription' => true,
9398
]);
9499
$this->cookieService->clearContextRequestCache();

src/Hook/CommonHook.php

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,53 +73,10 @@ public function actionDispatcherBefore($params)
7373
return;
7474
}
7575

76-
if (empty($_COOKIE[HookService::DEFAULT_COOKIE_NAME])) {
77-
return;
78-
}
79-
80-
$idShop = \Context::getContext()->shop->id;
81-
$languages = \Language::getLanguages(true, $idShop);
82-
83-
foreach ($languages as $language) {
84-
if (isset($_COOKIE[HookService::DEFAULT_COOKIE_NAME])) {
85-
setcookie(
86-
HookService::DEFAULT_COOKIE_NAME . '_' . $language['iso_code'],
87-
$_COOKIE[HookService::DEFAULT_COOKIE_NAME],
88-
strtotime('+1 year'),
89-
'/',
90-
'',
91-
true
92-
);
93-
}
94-
if (isset($_COOKIE[HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS])) {
95-
setcookie(
96-
HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS . '_' . $language['iso_code'],
97-
$_COOKIE[HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS],
98-
strtotime('+1 year'),
99-
'/',
100-
'',
101-
true
102-
);
103-
}
104-
if (isset($_COOKIE[HookService::DEFAULT_COOKIE_ALL_VENDORS])) {
105-
setcookie(
106-
HookService::DEFAULT_COOKIE_ALL_VENDORS . '_' . $language['iso_code'],
107-
$_COOKIE[HookService::DEFAULT_COOKIE_ALL_VENDORS],
108-
strtotime('+1 year'),
109-
'/',
110-
'',
111-
true
112-
);
113-
}
114-
}
115-
116-
unset($_COOKIE[HookService::DEFAULT_COOKIE_NAME]);
117-
setcookie(HookService::DEFAULT_COOKIE_NAME, '', time() - 3600, '/', '', true);
118-
119-
unset($_COOKIE[HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS]);
120-
setcookie(HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS, '', time() - 3600, '/', '', true);
121-
122-
unset($_COOKIE[HookService::DEFAULT_COOKIE_ALL_VENDORS]);
123-
setcookie(HookService::DEFAULT_COOKIE_ALL_VENDORS, '', time() - 3600, '/', '', true);
76+
/** @var \AxeptiocookiesAddon\Update\UpdateHandler $updateHandler */
77+
$updateHandler = \AxeptiocookiesAddon\Utils\ServiceContainer::getInstance()->get(
78+
\AxeptiocookiesAddon\Update\UpdateHandler::class
79+
);
80+
$updateHandler->setDefaultCookieFromLangCookies();
12481
}
12582
}

src/Model/Integration/IntegrationModel.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ class IntegrationModel implements \JsonSerializable
2929

3030
protected $cookiesVersion;
3131

32-
protected $jsonCookieName;
33-
34-
protected $allVendorsCookieName;
35-
36-
protected $authorizedVendorsCookieName;
37-
3832
/**
3933
* @var StepModel
4034
*/
@@ -90,66 +84,6 @@ public function setCookiesVersion($cookiesVersion)
9084
return $this;
9185
}
9286

93-
/**
94-
* @return mixed
95-
*/
96-
public function getJsonCookieName()
97-
{
98-
return $this->jsonCookieName;
99-
}
100-
101-
/**
102-
* @param mixed $jsonCookieName
103-
*
104-
* @return IntegrationModel
105-
*/
106-
public function setJsonCookieName($jsonCookieName)
107-
{
108-
$this->jsonCookieName = $jsonCookieName;
109-
110-
return $this;
111-
}
112-
113-
/**
114-
* @return mixed
115-
*/
116-
public function getAllVendorsCookieName()
117-
{
118-
return $this->allVendorsCookieName;
119-
}
120-
121-
/**
122-
* @param mixed $allVendorsCookieName
123-
*
124-
* @return IntegrationModel
125-
*/
126-
public function setAllVendorsCookieName($allVendorsCookieName)
127-
{
128-
$this->allVendorsCookieName = $allVendorsCookieName;
129-
130-
return $this;
131-
}
132-
133-
/**
134-
* @return mixed
135-
*/
136-
public function getAuthorizedVendorsCookieName()
137-
{
138-
return $this->authorizedVendorsCookieName;
139-
}
140-
141-
/**
142-
* @param mixed $authorizedVendorsCookieName
143-
*
144-
* @return IntegrationModel
145-
*/
146-
public function setAuthorizedVendorsCookieName($authorizedVendorsCookieName)
147-
{
148-
$this->authorizedVendorsCookieName = $authorizedVendorsCookieName;
149-
150-
return $this;
151-
}
152-
15387
/**
15488
* @return StepModel
15589
*/
@@ -220,9 +154,6 @@ public static function __set_state($array)
220154
$obj = new IntegrationModel();
221155
$obj->setClientId($array['clientId']);
222156
$obj->setCookiesVersion($array['cookiesVersion']);
223-
$obj->setJsonCookieName($array['jsonCookieName']);
224-
$obj->setAllVendorsCookieName($array['allVendorsCookieName']);
225-
$obj->setAuthorizedVendorsCookieName($array['authorizedVendorsCookieName']);
226157
$obj->setModuleStep($array['moduleStep']);
227158
$obj->setPlatform(empty($array['platform']) ? '' : $array['platform']);
228159
$obj->setConsent(empty($array['consent']) ? null : $array['consent']);
@@ -235,9 +166,6 @@ public function toArray()
235166
return [
236167
'clientId' => $this->getClientId(),
237168
'cookiesVersion' => $this->getCookiesVersion(),
238-
'jsonCookieName' => $this->getJsonCookieName(),
239-
'allVendorsCookieName' => $this->getAllVendorsCookieName(),
240-
'authorizedVendorsCookieName' => $this->getAuthorizedVendorsCookieName(),
241169
'moduleStep' => empty($this->getModuleStep()) ? [] : $this->getModuleStep()->toArray(),
242170
'platform' => $this->getPlatform(),
243171
'consent' => empty($this->getConsent()) ? null : $this->getConsent()->toArray(),

src/Service/CookieService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function __construct(HookService $hookService)
4444

4545
public function getModulesFromContext()
4646
{
47-
$language = \Context::getContext()->language;
48-
49-
$cookieName = HookService::DEFAULT_COOKIE_NAME . '_' . $language->iso_code;
47+
$cookieName = HookService::DEFAULT_COOKIE_NAME;
5048

5149
if (!empty(static::$contextModules[$cookieName])) {
5250
return static::$contextModules[$cookieName];

src/Service/HookService.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,6 @@ public function getIntegrationModelFromContext()
120120
$integrationModel = new IntegrationModel();
121121
$integrationModel->setClientId($axeptioConfiguration->id_project);
122122
$integrationModel->setCookiesVersion($configuration->getName());
123-
$integrationModel->setJsonCookieName(
124-
self::DEFAULT_COOKIE_NAME . '_' . \Language::getIsoById($cacheParams->getIdLang())
125-
);
126-
$integrationModel->setAllVendorsCookieName(
127-
self::DEFAULT_COOKIE_ALL_VENDORS . '_' . \Language::getIsoById($cacheParams->getIdLang())
128-
);
129-
$integrationModel->setAuthorizedVendorsCookieName(
130-
self::DEFAULT_COOKIE_AUTHORIZED_VENDORS . '_' . \Language::getIsoById($cacheParams->getIdLang())
131-
);
132123

133124
if (!empty($vendors)) {
134125
$stepModel = new StepModel();

src/Update/UpdateHandler.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use AxeptiocookiesAddon\API\Response\Object\Configuration;
2727
use AxeptiocookiesAddon\Model\CreateConfigurationModel;
2828
use AxeptiocookiesAddon\Service\ConfigurationService;
29+
use AxeptiocookiesAddon\Service\HookService;
2930
use AxeptiocookiesAddon\Service\ProjectService;
3031

3132
class UpdateHandler
@@ -91,4 +92,52 @@ public function createLangShopConfigurationFromParams($projectId, $versionId, $i
9192

9293
return $this->configurationService->createConfiguration($createConfiguration);
9394
}
95+
96+
public function setDefaultCookieFromLangCookies()
97+
{
98+
$isoCurrentLang = \Context::getContext()->language->iso_code;
99+
if (isset($_COOKIE[HookService::DEFAULT_COOKIE_NAME . '_' . $isoCurrentLang])) {
100+
setcookie(
101+
HookService::DEFAULT_COOKIE_NAME,
102+
$_COOKIE[HookService::DEFAULT_COOKIE_NAME . '_' . $isoCurrentLang],
103+
strtotime('+1 year'),
104+
'/',
105+
'',
106+
true
107+
);
108+
}
109+
if (isset($_COOKIE[HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS . '_' . $isoCurrentLang])) {
110+
setcookie(
111+
HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS,
112+
$_COOKIE[HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS . '_' . $isoCurrentLang],
113+
strtotime('+1 year'),
114+
'/',
115+
'',
116+
true
117+
);
118+
}
119+
if (isset($_COOKIE[HookService::DEFAULT_COOKIE_ALL_VENDORS . '_' . $isoCurrentLang])) {
120+
setcookie(
121+
HookService::DEFAULT_COOKIE_ALL_VENDORS,
122+
$_COOKIE[HookService::DEFAULT_COOKIE_ALL_VENDORS . '_' . $isoCurrentLang],
123+
strtotime('+1 year'),
124+
'/',
125+
'',
126+
true
127+
);
128+
}
129+
130+
$idShop = \Context::getContext()->shop->id;
131+
$languages = \Language::getLanguages(true, $idShop);
132+
foreach ($languages as $language) {
133+
unset($_COOKIE[HookService::DEFAULT_COOKIE_NAME . '_' . $language['iso_code']]);
134+
setcookie(HookService::DEFAULT_COOKIE_NAME . '_' . $language['iso_code'], '', time() - 3600, '/', '', true);
135+
136+
unset($_COOKIE[HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS . '_' . $language['iso_code']]);
137+
setcookie(HookService::DEFAULT_COOKIE_AUTHORIZED_VENDORS . '_' . $language['iso_code'], '', time() - 3600, '/', '', true);
138+
139+
unset($_COOKIE[HookService::DEFAULT_COOKIE_ALL_VENDORS . '_' . $language['iso_code']]);
140+
setcookie(HookService::DEFAULT_COOKIE_ALL_VENDORS . '_' . $language['iso_code'], '', time() - 3600, '/', '', true);
141+
}
142+
}
94143
}

upgrade/upgrade-2.0.8.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
if (!defined('_PS_VERSION_')) {
20+
exit;
21+
}
22+
23+
/**
24+
* @param Axeptiocookies $module
25+
*
26+
* @return bool
27+
*/
28+
function upgrade_module_2_0_8($module)
29+
{
30+
try {
31+
$cache = new \AxeptiocookiesAddon\Cache\ProjectCache();
32+
$cache->cleanCacheDirectory();
33+
\Tools::clearCache();
34+
} catch (Exception $e) {
35+
return false;
36+
}
37+
38+
return true;
39+
}

views/templates/front/hook/footer.tpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
//<![CDATA[
2222
clientId: "{$integration.clientId|escape:'htmlall':'UTF-8'}",
2323
cookiesVersion: "{$integration.cookiesVersion|escape:'htmlall':'UTF-8'}",
24-
jsonCookieName: "{$integration.jsonCookieName|escape:'htmlall':'UTF-8'}",
25-
allVendorsCookieName: "{$integration.allVendorsCookieName|escape:'htmlall':'UTF-8'}",
26-
authorizedVendorsCookieName: "{$integration.authorizedVendorsCookieName|escape:'htmlall':'UTF-8'}",
2724
platform: "{$integration.platform|escape:'htmlall':'UTF-8'}"
2825
//]]>
2926
};

0 commit comments

Comments
 (0)