Skip to content

Commit e8fb706

Browse files
committed
Treat the form data in configurationForm class
1 parent b37d2bb commit e8fb706

4 files changed

Lines changed: 48 additions & 37 deletions

File tree

classes/Form/ConfigurationForm.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public function __construct(\Ps_Googleanalytics $module) {
3535
}
3636

3737
/**
38-
* generateForm
38+
* generate
3939
*
4040
* @return string
4141
*/
42-
public function generateForm()
42+
public function generate()
4343
{
4444
// Check if multistore is active
4545
$is_multistore_active = \Shop::isFeatureActive();
@@ -158,6 +158,43 @@ public function generateForm()
158158
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = \Configuration::get('GA_CROSSDOMAIN_ENABLED');
159159
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = \Configuration::get('GA_ANONYMIZE_ENABLED');
160160

161-
return $helper->generateForm($fields_form);
161+
return $helper->generate($fields_form);
162+
}
163+
164+
/**
165+
* treat the form datas if submited
166+
*
167+
* @return string
168+
*/
169+
public function treat()
170+
{
171+
$treatmentResult = '';
172+
$gaAccountId = \Tools::getValue('GA_ACCOUNT_ID');
173+
$gaUserIdEnabled = \Tools::getValue('GA_USERID_ENABLED');
174+
$gaCrossdomainEnabled = \Tools::getValue('GA_CROSSDOMAIN_ENABLED');
175+
$gaAnonymizeEnabled = \Tools::getValue('GA_ANONYMIZE_ENABLED');
176+
177+
if (!empty($gaAccountId)) {
178+
\Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
179+
\Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
180+
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Account ID updated successfully'));
181+
}
182+
183+
if (null !== $gaUserIdEnabled) {
184+
\Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
185+
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for User ID updated successfully'));
186+
}
187+
188+
if (null !== $gaCrossdomainEnabled) {
189+
\Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool) $gaCrossdomainEnabled);
190+
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for User ID updated successfully'));
191+
}
192+
193+
if (null !== $gaAnonymizeEnabled) {
194+
\Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
195+
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for Anonymize IP updated successfully'));
196+
}
197+
198+
return $treatmentResult;
162199
}
163200
}

classes/Wrapper/OrderWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public function wrapOrder($id_order)
5555
'customer' => $order->id_customer);
5656
}
5757
}
58-
}
58+
}

classes/Wrapper/ProductWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ public function wrapProduct($product, $extras, $index = 0, $full = false)
131131
}
132132
return $ga_product;
133133
}
134-
}
134+
}

ps_googleanalytics.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,21 @@ public function __construct()
6262
$this->psVersionIs17 = (bool) version_compare(_PS_VERSION_, '1.7', '>=');
6363
}
6464

65-
public function displayForm()
66-
{
67-
$configurationForm = new PrestaShop\Module\Ps_Googleanalytics\Form\ConfigurationForm($this);
68-
return $configurationForm->generateForm();
69-
}
70-
7165
/**
7266
* back office module configuration page content
7367
*/
7468
public function getContent()
7569
{
76-
$output = '';
70+
$configurationForm = new PrestaShop\Module\Ps_Googleanalytics\Form\ConfigurationForm($this);
71+
$formOutput = '';
72+
7773
if (Tools::isSubmit('submit'.$this->name)) {
78-
$ga_account_id = Tools::getValue('GA_ACCOUNT_ID');
79-
if (!empty($ga_account_id)) {
80-
Configuration::updateValue('GA_ACCOUNT_ID', $ga_account_id);
81-
Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
82-
$output .= $this->displayConfirmation($this->l('Account ID updated successfully'));
83-
}
84-
$ga_userid_enabled = Tools::getValue('GA_USERID_ENABLED');
85-
if (null !== $ga_userid_enabled) {
86-
Configuration::updateValue('GA_USERID_ENABLED', (bool)$ga_userid_enabled);
87-
$output .= $this->displayConfirmation($this->l('Settings for User ID updated successfully'));
88-
}
89-
90-
$ga_crossdomain_enabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
91-
if (null !== $ga_crossdomain_enabled) {
92-
Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool)$ga_crossdomain_enabled);
93-
$output .= $this->displayConfirmation($this->l('Settings for User ID updated successfully'));
94-
}
95-
96-
$ga_anonymize_enabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
97-
if (null !== $ga_anonymize_enabled) {
98-
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool)$ga_anonymize_enabled);
99-
$output .= $this->displayConfirmation($this->l('Settings for Anonymize IP updated successfully'));
100-
}
74+
$formOutput = $configurationForm->treat();
10175
}
10276

103-
$output .= $this->displayForm();
77+
$formOutput .= $configurationForm->generate();
10478

105-
return $this->display(__FILE__, './views/templates/admin/configuration.tpl').$output;
79+
return $this->display(__FILE__, './views/templates/admin/configuration.tpl') . $formOutput;
10680
}
10781

10882
public function hookdisplayHeader($params, $back_office = false)

0 commit comments

Comments
 (0)