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

Commit

Permalink
Merge pull request #45 from 202ecommerce/feature/empty-cookie-version
Browse files Browse the repository at this point in the history
Added possibility to have empty cookie version; refs #48039
  • Loading branch information
denys202 authored Oct 10, 2024
2 parents 2168797 + 8518a5c commit 1da1b57
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/API/Response/Object/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
class Configuration extends AbstractObject
{
/**
* @var string
* @var string|null
*/
protected $id;

/**
* @var string
* @var string|null
*/
protected $language;

Expand All @@ -48,8 +48,8 @@ class Configuration extends AbstractObject
public function build($json)
{
if (empty($json)
|| empty($json['identifier'])
|| empty($json['language'])
|| !array_key_exists('identifier', $json)
|| !array_key_exists('language', $json)
|| empty($json['name'])
|| empty($json['title'])) {
return null;
Expand All @@ -64,15 +64,15 @@ public function build($json)
}

/**
* @return string
* @return string|null
*/
public function getId()
{
return $this->id;
}

/**
* @return string
* @return string|null
*/
public function getLanguage()
{
Expand Down
18 changes: 18 additions & 0 deletions src/API/Response/Object/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
exit;
}

use AxeptiocookiesClasslib\Utils\Translate\TranslateTrait;

class Project extends AbstractObject
{
use TranslateTrait;

/**
* @var int
*/
Expand All @@ -42,6 +46,7 @@ public function build($json)
}

$this->idProject = $json['projectId'];
$this->configurations[] = $this->getDefaultConfiguration();
if (!empty($json['cookies'])) {
foreach ($json['cookies'] as $cookie) {
$configuration = (new Configuration())->build($cookie);
Expand All @@ -55,6 +60,19 @@ public function build($json)
return $this;
}

protected function getDefaultConfiguration()
{
$defaultCookieName = $this->l('Automatic (Managed by Axeptio)', 'Project');

return (new Configuration())
->build([
'identifier' => null,
'language' => null,
'name' => \Tools::str2url($defaultCookieName),
'title' => $defaultCookieName,
]);
}

/**
* @return int
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/AxeptioConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public function __construct($id = null, $id_lang = null, $id_shop = null, $trans
'fields' => [
'id_configuration' => [
'type' => self::TYPE_STRING,
'required' => true,
'required' => false,
'allow_null' => true,
],
'id_project' => [
'type' => self::TYPE_STRING,
Expand Down
2 changes: 1 addition & 1 deletion src/Service/HookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getIntegrationModelFromContext()

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

if (!empty($vendors)) {
Expand Down
8 changes: 0 additions & 8 deletions src/Validator/ConfigurationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public function validateCreateConfiguration(CreateConfigurationModel $configurat
throw new ConfigurationValidatorException($this->l('Project ID is not valid', $this->getClassShortName()));
}

if (empty($configurationModel->getIdConfiguration())) {
throw new ConfigurationValidatorException($this->l('Configuration is not valid', $this->getClassShortName()));
}

if (empty($configurationModel->getIdShops())) {
throw new ConfigurationValidatorException($this->l('Shops are not selected', $this->getClassShortName()));
}
Expand Down Expand Up @@ -87,10 +83,6 @@ public function validateEditConfiguration(EditConfigurationModel $configurationM
throw new ConfigurationValidatorException($this->l('Project ID is not valid', $this->getClassShortName()));
}

if (empty($configurationModel->getConfiguration()->getId())) {
throw new ConfigurationValidatorException($this->l('Configuration is not valid', $this->getClassShortName()));
}

if (empty($configurationModel->getShops())) {
throw new ConfigurationValidatorException($this->l('Shops are not selected', $this->getClassShortName()));
}
Expand Down
2 changes: 1 addition & 1 deletion translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
$_MODULE['<{axeptiocookies}prestashop>adminaxeptiocookiesconfiguration_a1998652b01bdc9e7128734efb804780'] = 'Suppression';
$_MODULE['<{axeptiocookies}prestashop>adminaxeptiocookiesconfiguration_290612199861c31d1036b185b4e69b75'] = 'Résumé';
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_9e25aef4cd4c0065122c28fe492e9ddf'] = 'L\'ID de projet n\'est pas valide';
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_fa158c18b001191d25193c3810388407'] = 'La configuration n\'est pas valide';
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_75fbdb99c8b060fd62eafcc4d62a0956'] = 'Les boutiques ne sont pas sélectionnées';
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_d0cf7383e1ee9f02c0fd303fa788dd5a'] = 'La langue n\'est pas sélectionnée';
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_f8ea8e282b524773219c163388f9c40c'] = 'L\'association pour la boutique \"%s\" existe déjà';
$_MODULE['<{axeptiocookies}prestashop>configurationvalidator_f52e14933a97749eda40b8b5054d9af6'] = 'L\'ID d\'objet n\'est pas valide';
$_MODULE['<{axeptiocookies}prestashop>errorresponse_809c972c8bbb29c808e39ec6e69597c2'] = 'Erreur est survenue';
$_MODULE['<{axeptiocookies}prestashop>project_ec069574b2c58e587d8d778df425ede5'] = 'Automatique (Géré par Axeptio)';
4 changes: 3 additions & 1 deletion views/templates/front/hook/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
//<![CDATA[
clientId: "{$integration.clientId|escape:'htmlall':'UTF-8'}",
triggerGtmEvents: "{$integration.triggerGtmEvents|escape:'htmlall':'UTF-8'}",
cookiesVersion: "{$integration.cookiesVersion|escape:'htmlall':'UTF-8'}",
{if !empty($integration.cookiesVersion)}
cookiesVersion: "{$integration.cookiesVersion|escape:'htmlall':'UTF-8'}",
{/if}
platform: "{$integration.platform|escape:'htmlall':'UTF-8'}"
//]]>
};
Expand Down

0 comments on commit 1da1b57

Please sign in to comment.