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

Commit 1da1b57

Browse files
authored
Merge pull request #45 from 202ecommerce/feature/empty-cookie-version
Added possibility to have empty cookie version; refs #48039
2 parents 2168797 + 8518a5c commit 1da1b57

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

src/API/Response/Object/Configuration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
class Configuration extends AbstractObject
2727
{
2828
/**
29-
* @var string
29+
* @var string|null
3030
*/
3131
protected $id;
3232

3333
/**
34-
* @var string
34+
* @var string|null
3535
*/
3636
protected $language;
3737

@@ -48,8 +48,8 @@ class Configuration extends AbstractObject
4848
public function build($json)
4949
{
5050
if (empty($json)
51-
|| empty($json['identifier'])
52-
|| empty($json['language'])
51+
|| !array_key_exists('identifier', $json)
52+
|| !array_key_exists('language', $json)
5353
|| empty($json['name'])
5454
|| empty($json['title'])) {
5555
return null;
@@ -64,15 +64,15 @@ public function build($json)
6464
}
6565

6666
/**
67-
* @return string
67+
* @return string|null
6868
*/
6969
public function getId()
7070
{
7171
return $this->id;
7272
}
7373

7474
/**
75-
* @return string
75+
* @return string|null
7676
*/
7777
public function getLanguage()
7878
{

src/API/Response/Object/Project.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
exit;
2424
}
2525

26+
use AxeptiocookiesClasslib\Utils\Translate\TranslateTrait;
27+
2628
class Project extends AbstractObject
2729
{
30+
use TranslateTrait;
31+
2832
/**
2933
* @var int
3034
*/
@@ -42,6 +46,7 @@ public function build($json)
4246
}
4347

4448
$this->idProject = $json['projectId'];
49+
$this->configurations[] = $this->getDefaultConfiguration();
4550
if (!empty($json['cookies'])) {
4651
foreach ($json['cookies'] as $cookie) {
4752
$configuration = (new Configuration())->build($cookie);
@@ -55,6 +60,19 @@ public function build($json)
5560
return $this;
5661
}
5762

63+
protected function getDefaultConfiguration()
64+
{
65+
$defaultCookieName = $this->l('Automatic (Managed by Axeptio)', 'Project');
66+
67+
return (new Configuration())
68+
->build([
69+
'identifier' => null,
70+
'language' => null,
71+
'name' => \Tools::str2url($defaultCookieName),
72+
'title' => $defaultCookieName,
73+
]);
74+
}
75+
5876
/**
5977
* @return int
6078
*/

src/Entity/AxeptioConfiguration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public function __construct($id = null, $id_lang = null, $id_shop = null, $trans
136136
'fields' => [
137137
'id_configuration' => [
138138
'type' => self::TYPE_STRING,
139-
'required' => true,
139+
'required' => false,
140+
'allow_null' => true,
140141
],
141142
'id_project' => [
142143
'type' => self::TYPE_STRING,

src/Service/HookService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getIntegrationModelFromContext()
128128

129129
$integrationModel = new IntegrationModel();
130130
$integrationModel->setClientId($axeptioConfiguration->id_project);
131-
$integrationModel->setCookiesVersion($configuration->getName());
131+
$integrationModel->setCookiesVersion(empty($configuration->getId()) ? null : $configuration->getName());
132132
$integrationModel->setTriggerGtmEvents(TriggerGtmEventType::transformToValue((int) $axeptioConfiguration->trigger_gtm_events));
133133

134134
if (!empty($vendors)) {

src/Validator/ConfigurationValidator.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ public function validateCreateConfiguration(CreateConfigurationModel $configurat
5151
throw new ConfigurationValidatorException($this->l('Project ID is not valid', $this->getClassShortName()));
5252
}
5353

54-
if (empty($configurationModel->getIdConfiguration())) {
55-
throw new ConfigurationValidatorException($this->l('Configuration is not valid', $this->getClassShortName()));
56-
}
57-
5854
if (empty($configurationModel->getIdShops())) {
5955
throw new ConfigurationValidatorException($this->l('Shops are not selected', $this->getClassShortName()));
6056
}
@@ -87,10 +83,6 @@ public function validateEditConfiguration(EditConfigurationModel $configurationM
8783
throw new ConfigurationValidatorException($this->l('Project ID is not valid', $this->getClassShortName()));
8884
}
8985

90-
if (empty($configurationModel->getConfiguration()->getId())) {
91-
throw new ConfigurationValidatorException($this->l('Configuration is not valid', $this->getClassShortName()));
92-
}
93-
9486
if (empty($configurationModel->getShops())) {
9587
throw new ConfigurationValidatorException($this->l('Shops are not selected', $this->getClassShortName()));
9688
}

translations/fr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@
8989
$_MODULE['<{axeptiocookies}prestashop>adminaxeptiocookiesconfiguration_a1998652b01bdc9e7128734efb804780'] = 'Suppression';
9090
$_MODULE['<{axeptiocookies}prestashop>adminaxeptiocookiesconfiguration_290612199861c31d1036b185b4e69b75'] = 'Résumé';
9191
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_9e25aef4cd4c0065122c28fe492e9ddf'] = 'L\'ID de projet n\'est pas valide';
92-
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_fa158c18b001191d25193c3810388407'] = 'La configuration n\'est pas valide';
9392
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_75fbdb99c8b060fd62eafcc4d62a0956'] = 'Les boutiques ne sont pas sélectionnées';
9493
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_d0cf7383e1ee9f02c0fd303fa788dd5a'] = 'La langue n\'est pas sélectionnée';
9594
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_f8ea8e282b524773219c163388f9c40c'] = 'L\'association pour la boutique \"%s\" existe déjà';
9695
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_f52e14933a97749eda40b8b5054d9af6'] = 'L\'ID d\'objet n\'est pas valide';
9796
$_MODULE['<{axeptiocookies}prestashop>errorresponse_809c972c8bbb29c808e39ec6e69597c2'] = 'Erreur est survenue';
97+
$_MODULE['<{axeptiocookies}prestashop>project_ec069574b2c58e587d8d778df425ede5'] = 'Automatique (Géré par Axeptio)';

views/templates/front/hook/footer.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
//<![CDATA[
2222
clientId: "{$integration.clientId|escape:'htmlall':'UTF-8'}",
2323
triggerGtmEvents: "{$integration.triggerGtmEvents|escape:'htmlall':'UTF-8'}",
24-
cookiesVersion: "{$integration.cookiesVersion|escape:'htmlall':'UTF-8'}",
24+
{if !empty($integration.cookiesVersion)}
25+
cookiesVersion: "{$integration.cookiesVersion|escape:'htmlall':'UTF-8'}",
26+
{/if}
2527
platform: "{$integration.platform|escape:'htmlall':'UTF-8'}"
2628
//]]>
2729
};

0 commit comments

Comments
 (0)