Skip to content

Commit 414e505

Browse files
authored
Merge pull request #148 from Hlavtox/fix-trans
Remove old code, fix translation domains, bump compatibility
2 parents b435c26 + 87df4d3 commit 414e505

35 files changed

Lines changed: 355 additions & 1287 deletions

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
runs-on: ubuntu-latest
5959
strategy:
6060
matrix:
61-
presta-versions: ['1.6.1.18', '1.7.1.2', '1.7.2.5', '1.7.3.4', '1.7.4.4', '1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest']
61+
presta-versions: ['1.7.6', '1.7.7', '1.7.8', 'latest']
6262
steps:
6363
- name: Setup PHP
6464
uses: shivammathur/setup-php@v2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Enhanced Ecommerce must be enabled in Google Analytics settings for full functio
2121

2222
PrestaShop modules are open-source extensions to the PrestaShop e-commerce solution. Everyone is welcome and even encouraged to contribute with their own improvements.
2323

24-
Google Analytics is compatible with all versions of PrestaShop 8, 1.7 and 1.6.
24+
Google Analytics is compatible with PrestaShop 1.7.6 and newer.
2525

2626
### Requirements
2727

classes/Database/Install.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public function registerHooks()
101101
return $this->module->registerHook('displayHeader') &&
102102
$this->module->registerHook('displayAdminOrder') &&
103103
$this->module->registerHook('displayBeforeBodyClosingTag') &&
104-
$this->module->registerHook('displayFooter') &&
105104
$this->module->registerHook('displayFooterProduct') &&
106105
$this->module->registerHook('displayOrderConfirmation') &&
107106
$this->module->registerHook('actionProductCancel') &&

classes/Form/ConfigurationForm.php

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use HelperForm;
2727
use OrderState;
2828
use Ps_Googleanalytics;
29-
use Shop;
3029
use Tools;
3130

3231
class ConfigurationForm
@@ -45,9 +44,6 @@ public function __construct(Ps_Googleanalytics $module)
4544
*/
4645
public function generate()
4746
{
48-
// Check if multistore is active
49-
$is_multistore_active = Shop::isFeatureActive();
50-
5147
// Get default language
5248
$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
5349

@@ -70,107 +66,89 @@ public function generate()
7066
$helper->submit_action = 'submit' . $this->module->name;
7167
$helper->toolbar_btn = [
7268
'save' => [
73-
'desc' => $this->module->trans('Save', [], 'Modules.GAnalytics.Admin'),
69+
'desc' => $this->module->getTranslator()->trans('Save', [], 'Modules.Googleanalytics.Admin'),
7470
'href' => AdminController::$currentIndex . '&configure=' . $this->module->name . '&save=' . $this->module->name .
7571
'&token=' . $helper->token,
7672
],
7773
'back' => [
7874
'href' => AdminController::$currentIndex . '&token=' . $helper->token,
79-
'desc' => $this->module->trans('Back to list', [], 'Modules.GAnalytics.Admin'),
75+
'desc' => $this->module->getTranslator()->trans('Back to list', [], 'Modules.Googleanalytics.Admin'),
8076
],
8177
];
8278

8379
$fields_form = [];
8480
// Init Fields form array
8581
$fields_form[0]['form'] = [
8682
'legend' => [
87-
'title' => $this->module->trans('Settings', [], 'Modules.GAnalytics.Admin'),
83+
'title' => $this->module->getTranslator()->trans('Settings', [], 'Modules.Googleanalytics.Admin'),
8884
],
8985
'input' => [
90-
[
91-
'type' => 'switch',
92-
'label' => $this->module->trans('Enable Google Analytics 4', [], 'Modules.GAnalytics.Admin'),
93-
'name' => 'GA_V4_ENABLED',
94-
'values' => [
95-
[
96-
'id' => 'GA_V4_ENABLED',
97-
'value' => 1,
98-
'label' => $this->module->trans('Yes', [], 'Modules.GAnalytics.Admin'),
99-
],
100-
[
101-
'id' => 'GA_V4_ENABLED',
102-
'value' => 0,
103-
'label' => $this->module->trans('No', [], 'Modules.GAnalytics.Admin'),
104-
],
105-
],
106-
'desc' => $this->module->trans('Universal analytics will stop processing data on July 1, 2023. We recommend switching to Google Analytics 4 as soon as possible.', [], 'Modules.GAnalytics.Admin'),
107-
],
10886
[
10987
'type' => 'text',
110-
'label' => $this->module->trans('Google Analytics Tracking ID', [], 'Modules.GAnalytics.Admin'),
88+
'label' => $this->module->getTranslator()->trans('Google Analytics Tracking ID', [], 'Modules.Googleanalytics.Admin'),
11189
'name' => 'GA_ACCOUNT_ID',
11290
'size' => 20,
11391
'required' => true,
114-
'desc' => $this->module->trans('This information is available in your Google Analytics account. GA4 tracking ID starts with "G-", Universal Analytics with "UA-".', [], 'Modules.GAnalytics.Admin'),
92+
'desc' => $this->module->getTranslator()->trans('This information is available in your Google Analytics account. Google Analytics 4 tracking ID starts with "G-".', [], 'Modules.Googleanalytics.Admin'),
11593
],
11694
[
11795
'type' => 'switch',
118-
'label' => $this->module->trans('Enable User ID tracking', [], 'Modules.GAnalytics.Admin'),
96+
'label' => $this->module->getTranslator()->trans('Enable User ID tracking', [], 'Modules.Googleanalytics.Admin'),
11997
'name' => 'GA_USERID_ENABLED',
12098
'values' => [
12199
[
122100
'id' => 'ga_userid_enabled',
123101
'value' => 1,
124-
'label' => $this->module->trans('Yes', [], 'Modules.GAnalytics.Admin'),
102+
'label' => $this->module->getTranslator()->trans('Yes', [], 'Modules.Googleanalytics.Admin'),
125103
],
126104
[
127105
'id' => 'ga_userid_disabled',
128106
'value' => 0,
129-
'label' => $this->module->trans('No', [], 'Modules.GAnalytics.Admin'),
107+
'label' => $this->module->getTranslator()->trans('No', [], 'Modules.Googleanalytics.Admin'),
130108
],
131109
],
132110
],
133111
[
134112
'type' => 'switch',
135-
'label' => $this->module->trans('Anonymize IP', [], 'Modules.GAnalytics.Admin'),
113+
'label' => $this->module->getTranslator()->trans('Anonymize IP', [], 'Modules.Googleanalytics.Admin'),
136114
'name' => 'GA_ANONYMIZE_ENABLED',
137-
'hint' => $this->module->trans('Use this option to anonymize the visitor’s IP to comply with data privacy laws in some countries', [], 'Modules.GAnalytics.Admin'),
115+
'hint' => $this->module->getTranslator()->trans('Use this option to anonymize the visitor’s IP to comply with data privacy laws in some countries', [], 'Modules.Googleanalytics.Admin'),
138116
'values' => [
139117
[
140118
'id' => 'ga_anonymize_enabled',
141119
'value' => 1,
142-
'label' => $this->module->trans('Yes', [], 'Modules.GAnalytics.Admin'),
120+
'label' => $this->module->getTranslator()->trans('Yes', [], 'Modules.Googleanalytics.Admin'),
143121
],
144122
[
145123
'id' => 'ga_anonymize_disabled',
146124
'value' => 0,
147-
'label' => $this->module->trans('No', [], 'Modules.GAnalytics.Admin'),
125+
'label' => $this->module->getTranslator()->trans('No', [], 'Modules.Googleanalytics.Admin'),
148126
],
149127
],
150128
],
151129
[
152130
'type' => 'switch',
153-
'label' => $this->module->trans('Enable Back Office Tracking', [], 'Modules.GAnalytics.Admin'),
131+
'label' => $this->module->getTranslator()->trans('Enable Back Office Tracking', [], 'Modules.Googleanalytics.Admin'),
154132
'name' => 'GA_TRACK_BACKOFFICE_ENABLED',
155-
'hint' => $this->module->trans('Use this option to enable the tracking inside the Back Office', [], 'Modules.GAnalytics.Admin'),
133+
'hint' => $this->module->getTranslator()->trans('Use this option to enable the tracking inside the Back Office', [], 'Modules.Googleanalytics.Admin'),
156134
'values' => [
157135
[
158136
'id' => 'ga_track_backoffice',
159137
'value' => 1,
160-
'label' => $this->module->trans('Yes', [], 'Modules.GAnalytics.Admin'),
138+
'label' => $this->module->getTranslator()->trans('Yes', [], 'Modules.Googleanalytics.Admin'),
161139
],
162140
[
163141
'id' => 'ga_do_not_track_backoffice',
164142
'value' => 0,
165-
'label' => $this->module->trans('No', [], 'Modules.GAnalytics.Admin'),
143+
'label' => $this->module->getTranslator()->trans('No', [], 'Modules.Googleanalytics.Admin'),
166144
],
167145
],
168146
],
169147
[
170148
'type' => 'select',
171-
'label' => $this->module->trans('Canceled order states', [], 'Modules.GAnalytics.Admin'),
149+
'label' => $this->module->getTranslator()->trans('Canceled order states', [], 'Modules.Googleanalytics.Admin'),
172150
'name' => 'GA_CANCELLED_STATES',
173-
'desc' => $this->module->trans('Choose order states in which you consider the given order canceled. This will usually be the default "Canceled" state, but some stores may have extra states like "Returned", etc.', [], 'Modules.GAnalytics.Admin'),
151+
'desc' => $this->module->getTranslator()->trans('Choose order states in which you consider the given order canceled. This will usually be the default "Canceled" state, but some stores may have extra states like "Returned", etc.', [], 'Modules.Googleanalytics.Admin'),
174152
'class' => 'chosen',
175153
'multiple' => true,
176154
'options' => [
@@ -181,35 +159,13 @@ public function generate()
181159
],
182160
],
183161
'submit' => [
184-
'title' => $this->module->trans('Save', [], 'Modules.GAnalytics.Admin'),
162+
'title' => $this->module->getTranslator()->trans('Save', [], 'Modules.Googleanalytics.Admin'),
185163
],
186164
];
187165

188-
if ($is_multistore_active) {
189-
$fields_form[0]['form']['input'][] = [
190-
'type' => 'switch',
191-
'label' => $this->module->trans('Enable Cross-Domain tracking', [], 'Modules.GAnalytics.Admin'),
192-
'name' => 'GA_CROSSDOMAIN_ENABLED',
193-
'values' => [
194-
[
195-
'id' => 'ga_crossdomain_enabled',
196-
'value' => 1,
197-
'label' => $this->module->trans('Yes', [], 'Modules.GAnalytics.Admin'),
198-
],
199-
[
200-
'id' => 'ga_crossdomain_disabled',
201-
'value' => 0,
202-
'label' => $this->module->trans('No', [], 'Modules.GAnalytics.Admin'),
203-
],
204-
],
205-
];
206-
}
207-
208166
// Load current value
209167
$helper->fields_value['GA_ACCOUNT_ID'] = Configuration::get('GA_ACCOUNT_ID');
210-
$helper->fields_value['GA_V4_ENABLED'] = Configuration::get('GA_V4_ENABLED');
211168
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
212-
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = Configuration::get('GA_CROSSDOMAIN_ENABLED');
213169
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = Configuration::get('GA_ANONYMIZE_ENABLED');
214170
$helper->fields_value['GA_TRACK_BACKOFFICE_ENABLED'] = Configuration::get('GA_TRACK_BACKOFFICE_ENABLED');
215171
$helper->fields_value['GA_CANCELLED_STATES[]'] = json_decode(Configuration::get('GA_CANCELLED_STATES'), true);
@@ -224,13 +180,8 @@ public function generate()
224180
*/
225181
public function treat()
226182
{
227-
// Check if multistore is active
228-
$is_multistore_active = Shop::isFeatureActive();
229-
230183
$gaAccountId = Tools::getValue('GA_ACCOUNT_ID');
231-
$gaV4Enabled = Tools::getValue('GA_V4_ENABLED');
232184
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
233-
$gaCrossdomainEnabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
234185
$gaAnonymizeEnabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
235186
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_ENABLED');
236187
$gaCancelledStates = Tools::getValue('GA_CANCELLED_STATES');
@@ -240,18 +191,10 @@ public function treat()
240191
Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
241192
}
242193

243-
if (null !== $gaV4Enabled) {
244-
Configuration::updateValue('GA_V4_ENABLED', (bool) $gaV4Enabled);
245-
}
246-
247194
if (null !== $gaUserIdEnabled) {
248195
Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
249196
}
250197

251-
if ($is_multistore_active) {
252-
Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool) $gaCrossdomainEnabled);
253-
}
254-
255198
if (null !== $gaAnonymizeEnabled) {
256199
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
257200
}
@@ -266,6 +209,6 @@ public function treat()
266209
Configuration::updateValue('GA_CANCELLED_STATES', json_encode($gaCancelledStates));
267210
}
268211

269-
return $this->module->displayConfirmation($this->module->trans('Settings updated successfully.', [], 'Modules.GAnalytics.Admin'));
212+
return $this->module->displayConfirmation($this->module->getTranslator()->trans('Settings updated successfully.', [], 'Modules.Googleanalytics.Admin'));
270213
}
271214
}

0 commit comments

Comments
 (0)