Skip to content

Commit db6d80b

Browse files
committed
Using namespace when using Core Classes
1 parent 5cd1241 commit db6d80b

21 files changed

Lines changed: 200 additions & 118 deletions

classes/Database/Install.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics\Database;
2222

23+
use Db;
24+
use Ps_Googleanalytics;
25+
use Shop;
26+
2327
class Install
2428
{
2529
/**
26-
* @var \Ps_Googleanalytics
30+
* @var Ps_Googleanalytics
2731
*/
2832
private $module;
2933

30-
public function __construct(\Ps_Googleanalytics $module)
34+
public function __construct(Ps_Googleanalytics $module)
3135
{
32-
if (\Shop::isFeatureActive()) {
33-
\Shop::setContext(\Shop::CONTEXT_ALL);
36+
if (Shop::isFeatureActive()) {
37+
Shop::setContext(Shop::CONTEXT_ALL);
3438
}
3539

3640
$this->module = $module;
@@ -65,7 +69,7 @@ public function installTables()
6569
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
6670

6771
foreach ($sql as $query) {
68-
if (!\Db::getInstance()->execute($query)) {
72+
if (!Db::getInstance()->execute($query)) {
6973
return false;
7074
}
7175
}

classes/Database/Uninstall.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics\Database;
2222

23+
use Db;
24+
2325
class Uninstall
2426
{
2527
/**
@@ -33,7 +35,7 @@ public function uninstallTables()
3335
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'ganalytics_data`';
3436

3537
foreach ($sql as $query) {
36-
if (!\Db::getInstance()->execute($query)) {
38+
if (!Db::getInstance()->execute($query)) {
3739
return false;
3840
}
3941
}

classes/Form/ConfigurationForm.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics\Form;
2222

23+
use AdminController;
24+
use Configuration;
25+
use HelperForm;
26+
use Ps_Googleanalytics;
27+
use Shop;
28+
use Tools;
29+
2330
class ConfigurationForm
2431
{
2532
private $module;
2633

27-
public function __construct(\Ps_Googleanalytics $module)
34+
public function __construct(Ps_Googleanalytics $module)
2835
{
2936
$this->module = $module;
3037
}
@@ -37,18 +44,18 @@ public function __construct(\Ps_Googleanalytics $module)
3744
public function generate()
3845
{
3946
// Check if multistore is active
40-
$is_multistore_active = \Shop::isFeatureActive();
47+
$is_multistore_active = Shop::isFeatureActive();
4148

4249
// Get default language
43-
$default_lang = (int) \Configuration::get('PS_LANG_DEFAULT');
50+
$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
4451

45-
$helper = new \HelperForm();
52+
$helper = new HelperForm();
4653

4754
// Module, token and currentIndex
4855
$helper->module = $this->module;
4956
$helper->name_controller = $this->module->name;
50-
$helper->token = \Tools::getAdminTokenLite('AdminModules');
51-
$helper->currentIndex = \AdminController::$currentIndex . '&configure=' . $this->module->name;
57+
$helper->token = Tools::getAdminTokenLite('AdminModules');
58+
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->module->name;
5259

5360
// Language
5461
$helper->default_form_language = $default_lang;
@@ -62,11 +69,11 @@ public function generate()
6269
$helper->toolbar_btn = [
6370
'save' => [
6471
'desc' => $this->module->l('Save'),
65-
'href' => \AdminController::$currentIndex . '&configure=' . $this->module->name . '&save' . $this->module->name .
66-
'&token=' . \Tools::getAdminTokenLite('AdminModules'),
72+
'href' => AdminController::$currentIndex . '&configure=' . $this->module->name . '&save' . $this->module->name .
73+
'&token=' . Tools::getAdminTokenLite('AdminModules'),
6774
],
6875
'back' => [
69-
'href' => \AdminController::$currentIndex . '&token=' . \Tools::getAdminTokenLite('AdminModules'),
76+
'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
7077
'desc' => $this->module->l('Back to list'),
7178
],
7279
];
@@ -147,10 +154,10 @@ public function generate()
147154
}
148155

149156
// Load current value
150-
$helper->fields_value['GA_ACCOUNT_ID'] = \Configuration::get('GA_ACCOUNT_ID');
151-
$helper->fields_value['GA_USERID_ENABLED'] = \Configuration::get('GA_USERID_ENABLED');
152-
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = \Configuration::get('GA_CROSSDOMAIN_ENABLED');
153-
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = \Configuration::get('GA_ANONYMIZE_ENABLED');
157+
$helper->fields_value['GA_ACCOUNT_ID'] = Configuration::get('GA_ACCOUNT_ID');
158+
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
159+
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = Configuration::get('GA_CROSSDOMAIN_ENABLED');
160+
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = Configuration::get('GA_ANONYMIZE_ENABLED');
154161

155162
return $helper->generateForm($fields_form);
156163
}
@@ -163,29 +170,29 @@ public function generate()
163170
public function treat()
164171
{
165172
$treatmentResult = '';
166-
$gaAccountId = \Tools::getValue('GA_ACCOUNT_ID');
167-
$gaUserIdEnabled = \Tools::getValue('GA_USERID_ENABLED');
168-
$gaCrossdomainEnabled = \Tools::getValue('GA_CROSSDOMAIN_ENABLED');
169-
$gaAnonymizeEnabled = \Tools::getValue('GA_ANONYMIZE_ENABLED');
173+
$gaAccountId = Tools::getValue('GA_ACCOUNT_ID');
174+
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
175+
$gaCrossdomainEnabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
176+
$gaAnonymizeEnabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
170177

171178
if (!empty($gaAccountId)) {
172-
\Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
173-
\Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
179+
Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
180+
Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
174181
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Account ID updated successfully'));
175182
}
176183

177184
if (null !== $gaUserIdEnabled) {
178-
\Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
185+
Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
179186
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for User ID updated successfully'));
180187
}
181188

182189
if (null !== $gaCrossdomainEnabled) {
183-
\Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool) $gaCrossdomainEnabled);
190+
Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool) $gaCrossdomainEnabled);
184191
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for User ID updated successfully'));
185192
}
186193

187194
if (null !== $gaAnonymizeEnabled) {
188-
\Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
195+
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
189196
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for Anonymize IP updated successfully'));
190197
}
191198

classes/Handler/GanalyticsJsHandler.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics\Handler;
2222

23+
use Configuration;
24+
use Context;
25+
use Ps_Googleanalytics;
26+
use Tools;
27+
2328
class GanalyticsJsHandler
2429
{
2530
private $module;
2631
private $context;
2732

28-
public function __construct(\Ps_Googleanalytics $module, \Context $context)
33+
public function __construct(Ps_Googleanalytics $module, Context $context)
2934
{
3035
$this->module = $module;
3136
$this->context = $context;
@@ -41,11 +46,11 @@ public function __construct(\Ps_Googleanalytics $module, \Context $context)
4146
*/
4247
public function generate($jsCode, $isBackoffice = 0)
4348
{
44-
if (\Configuration::get('GA_ACCOUNT_ID')) {
49+
if (Configuration::get('GA_ACCOUNT_ID')) {
4550
$this->context->smarty->assign(
4651
[
4752
'jsCode' => $jsCode,
48-
'isoCode' => \Tools::safeOutput($this->context->currency->iso_code),
53+
'isoCode' => Tools::safeOutput($this->context->currency->iso_code),
4954
'jsState' => $this->module->js_state,
5055
'isBackoffice' => $isBackoffice,
5156
]

classes/Handler/ModuleHandler.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics\Handler;
2222

23+
use Module;
24+
2325
class ModuleHandler
2426
{
2527
/**
@@ -31,13 +33,13 @@ class ModuleHandler
3133
*/
3234
public function isModuleEnabled($moduleName)
3335
{
34-
$module = \Module::getInstanceByName($moduleName);
36+
$module = Module::getInstanceByName($moduleName);
3537

3638
if (false === $module) {
3739
return false;
3840
}
3941

40-
if (false === \Module::isInstalled($moduleName)) {
42+
if (false === Module::isInstalled($moduleName)) {
4143
return false;
4244
}
4345

@@ -57,11 +59,11 @@ public function isModuleEnabled($moduleName)
5759
*/
5860
public function uninstallModule($moduleName)
5961
{
60-
if (false === \Module::isInstalled($moduleName)) {
62+
if (false === Module::isInstalled($moduleName)) {
6163
return false;
6264
}
6365

64-
$oldModule = \Module::getInstanceByName($moduleName);
66+
$oldModule = Module::getInstanceByName($moduleName);
6567

6668
if (false === $oldModule) {
6769
return false;

classes/Hook/HookActionCarrierProcess.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222

2323
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsDataHandler;
2424
use PrestaShop\Module\Ps_Googleanalytics\Repository\CarrierRepository;
25+
use Ps_Googleanalytics;
2526

2627
class HookActionCarrierProcess implements HookInterface
2728
{
2829
private $module;
2930
private $context;
3031
private $params;
3132

32-
public function __construct(\Ps_Googleanalytics $module, \Context $context)
33+
public function __construct(Ps_Googleanalytics $module, Context $context)
3334
{
3435
$this->module = $module;
3536
$this->context = $context;

classes/Hook/HookActionCartSave.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
2222

23+
use Configuration;
24+
use Context;
2325
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsDataHandler;
2426
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
27+
use Product;
28+
use Ps_Googleanalytics;
29+
use Tools;
30+
use Validate;
2531

2632
class HookActionCartSave implements HookInterface
2733
{
2834
private $module;
2935

3036
/**
31-
* @var \Context
37+
* @var Context
3238
*/
3339
private $context;
3440

35-
public function __construct(\Ps_Googleanalytics $module, \Context $context)
41+
public function __construct(Ps_Googleanalytics $module, Context $context)
3642
{
3743
$this->module = $module;
3844
$this->context = $context;
@@ -49,30 +55,30 @@ public function run()
4955
return;
5056
}
5157

52-
if (!\Tools::getIsset('id_product')) {
58+
if (!Tools::getIsset('id_product')) {
5359
return;
5460
}
5561

5662
$cart = [
57-
'controller' => \Tools::getValue('controller'),
58-
'addAction' => \Tools::getValue('add') ? 'add' : '',
59-
'removeAction' => \Tools::getValue('delete') ? 'delete' : '',
60-
'extraAction' => \Tools::getValue('op'),
61-
'qty' => (int) \Tools::getValue('qty', 1),
63+
'controller' => Tools::getValue('controller'),
64+
'addAction' => Tools::getValue('add') ? 'add' : '',
65+
'removeAction' => Tools::getValue('delete') ? 'delete' : '',
66+
'extraAction' => Tools::getValue('op'),
67+
'qty' => (int) Tools::getValue('qty', 1),
6268
];
6369

6470
$cartProducts = $this->context->cart->getProducts();
6571
if (!empty($cartProducts)) {
6672
foreach ($cartProducts as $cartProduct) {
67-
if ($cartProduct['id_product'] == \Tools::getValue('id_product')) {
73+
if ($cartProduct['id_product'] == Tools::getValue('id_product')) {
6874
$addProduct = $cartProduct;
6975
}
7076
}
7177
}
7278

7379
if ($cart['removeAction'] == 'delete') {
74-
$addProductObject = new \Product((int) \Tools::getValue('id_product'), true, (int) \Configuration::get('PS_LANG_DEFAULT'));
75-
if (\Validate::isLoadedObject($addProductObject)) {
80+
$addProductObject = new Product((int) Tools::getValue('id_product'), true, (int) Configuration::get('PS_LANG_DEFAULT'));
81+
if (Validate::isLoadedObject($addProductObject)) {
7682
$addProduct['name'] = $addProductObject->name;
7783
$addProduct['manufacturer_name'] = $addProductObject->manufacturer_name;
7884
$addProduct['category'] = $addProductObject->category;
@@ -81,29 +87,29 @@ public function run()
8187
$addProduct['link'] = $addProductObject->link_rewrite;
8288
$addProduct['price'] = $addProductObject->price;
8389
$addProduct['ean13'] = $addProductObject->ean13;
84-
$addProduct['id_product'] = \Tools::getValue('id_product');
90+
$addProduct['id_product'] = Tools::getValue('id_product');
8591
$addProduct['id_category_default'] = $addProductObject->id_category_default;
8692
$addProduct['out_of_stock'] = $addProductObject->out_of_stock;
8793
$addProduct['minimal_quantity'] = 1;
8894
$addProduct['unit_price_ratio'] = 0;
89-
$addProduct = \Product::getProductProperties((int) \Configuration::get('PS_LANG_DEFAULT'), $addProduct);
95+
$addProduct = Product::getProductProperties((int) Configuration::get('PS_LANG_DEFAULT'), $addProduct);
9096
}
9197
}
9298

93-
if (isset($addProduct) && !in_array((int) \Tools::getValue('id_product'), $this->module->products)) {
99+
if (isset($addProduct) && !in_array((int) Tools::getValue('id_product'), $this->module->products)) {
94100
$ganalyticsDataHandler = new GanalyticsDataHandler(
95101
$this->context->cart->id,
96102
$this->context->shop->id
97103
);
98104

99-
$this->module->products[] = (int) \Tools::getValue('id_product');
105+
$this->module->products[] = (int) Tools::getValue('id_product');
100106
$productWrapper = new ProductWrapper($this->context);
101107
$gaProducts = $productWrapper->wrapProduct($addProduct, $cart, 0, true);
102108

103109
if (array_key_exists('id_product_attribute', $gaProducts) && $gaProducts['id_product_attribute'] != '' && $gaProducts['id_product_attribute'] != 0) {
104110
$productId = $gaProducts['id_product_attribute'];
105111
} else {
106-
$productId = \Tools::getValue('id_product');
112+
$productId = Tools::getValue('id_product');
107113
}
108114

109115
$gaCart = $ganalyticsDataHandler->manageData('', 'R');
@@ -116,7 +122,7 @@ public function run()
116122
} else {
117123
$gaProducts['quantity'] = $cart['qty'] * -1;
118124
}
119-
} elseif (\Tools::getValue('step') <= 0) { // Sometimes cartsave is called in checkout
125+
} elseif (Tools::getValue('step') <= 0) { // Sometimes cartsave is called in checkout
120126
if (array_key_exists($productId, $gaCart)) {
121127
$gaProducts['quantity'] = $gaCart[$productId]['quantity'] + $cart['qty'];
122128
}

0 commit comments

Comments
 (0)