Skip to content

Commit 5ad5ab9

Browse files
committed
Fix tests
1 parent b110bc2 commit 5ad5ab9

9 files changed

Lines changed: 26 additions & 33 deletions

classes/Database/Uninstall.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use Db;
2424
use Tab;
25+
use Validate;
2526

2627
class Uninstall
2728
{

classes/GoogleAnalyticsTools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function filter($gaScripts, $filterable)
4545
* Renders purchase event for order
4646
*
4747
* @param array $orderProducts
48-
* @param array $transaction
48+
* @param array $orderData
4949
* @param string $callbackUrl
5050
*
5151
* @return string|void

classes/Hook/HookActionValidateOrder.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ public function __construct(Ps_Googleanalytics $module, Context $context)
5353
*/
5454
public function run()
5555
{
56-
// Check if we are creating backoffice order
57-
if ($this->context->controller->controller_name != 'AdminOrders' && $this->context->controller->controller_name != 'Admin') {
58-
return;
59-
}
56+
// Check if we are creating backoffice order
57+
if ($this->context->controller->controller_name != 'AdminOrders' && $this->context->controller->controller_name != 'Admin') {
58+
return;
59+
}
6060

61-
// Mark this ID to immediately display it on next page load
62-
if (!empty($this->context->cookie->__get('ga_admin_order'))) {
63-
$ga_admin_order = $this->context->cookie->__get('ga_admin_order') . "," . ($this->params['order'])->id;
64-
} else {
65-
$ga_admin_order = ($this->params['order'])->id;
66-
}
67-
$this->context->cookie->__set('ga_admin_order', $ga_admin_order);
68-
$this->context->cookie->write();
61+
// Mark this ID to immediately display it on next page load
62+
$order = $this->params['order'];
63+
if (!empty($this->context->cookie->__get('ga_admin_order'))) {
64+
$ga_admin_order = $this->context->cookie->__get('ga_admin_order') . ',' . $order->id;
65+
} else {
66+
$ga_admin_order = $order->id;
67+
}
68+
$this->context->cookie->__set('ga_admin_order', $ga_admin_order);
69+
$this->context->cookie->write();
6970
}
7071

7172
/**

classes/Hook/HookDisplayBackOfficeHeader.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Cart;
2424
use Configuration;
2525
use Context;
26-
use Currency;
2726
use Db;
2827
use Order;
2928
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
@@ -64,21 +63,13 @@ public function run()
6463

6564
// Process manual orders instantly, we have their IDs in cookie
6665
$gaScripts .= $this->processManualOrders();
67-
66+
6867
// Backload old orders that failed to load normally
6968
$gaScripts .= $this->backloadFailedOrders();
7069

7170
return $gaScripts;
7271
}
7372

74-
/**
75-
* @param array $params
76-
*/
77-
public function setParams($params)
78-
{
79-
$this->params = $params;
80-
}
81-
8273
/**
8374
* Checks if there are any orders that failed to be sent normally through front office and processes them
8475
*/
@@ -100,7 +91,7 @@ protected function backloadFailedOrders()
10091
$failedOrders = Db::getInstance()->ExecuteS(
10192
'SELECT DISTINCT o.id_order, g.sent FROM `' . _DB_PREFIX_ . 'orders` o
10293
LEFT JOIN `' . _DB_PREFIX_ . GanalyticsRepository::TABLE_NAME . '` g ON o.id_order = g.id_order
103-
WHERE (g.sent IS NULL OR g.sent = 0) AND o.date_add BETWEEN NOW() - INTERVAL ' . $backloadDays .' DAY AND NOW() - INTERVAL 30 MINUTE'
94+
WHERE (g.sent IS NULL OR g.sent = 0) AND o.date_add BETWEEN NOW() - INTERVAL ' . $backloadDays . ' DAY AND NOW() - INTERVAL 30 MINUTE'
10495
);
10596

10697
// Process each failed order
@@ -123,7 +114,7 @@ protected function processManualOrders()
123114
}
124115

125116
// Separate them by IDs and process one by one
126-
$adminOrders = explode(",", $adminOrders);
117+
$adminOrders = explode(',', $adminOrders);
127118
foreach ($adminOrders as $idOrder) {
128119
$gaScripts .= $this->processOrder((int) $idOrder);
129120
}
@@ -136,7 +127,7 @@ protected function processManualOrders()
136127
}
137128

138129
/**
139-
* Renders tracking code for given order
130+
* Renders tracking code for given order
140131
*
141132
* @param int $idOrder
142133
*/
@@ -167,7 +158,7 @@ public function processOrder($idOrder)
167158

168159
// Prepare transaction data
169160
$orderData = $orderWrapper->wrapOrder($order);
170-
161+
171162
// Add payment event
172163
$gaScripts .= $this->module->getTools()->renderEvent(
173164
'add_payment_info',

classes/Hook/HookDisplayOrderConfirmation.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
use Context;
2626
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
2727
use PrestaShop\Module\Ps_Googleanalytics\Repository\GanalyticsRepository;
28-
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
2928
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\OrderWrapper;
29+
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
3030
use Ps_Googleanalytics;
31-
use Shop;
3231
use Validate;
3332

3433
class HookDisplayOrderConfirmation implements HookInterface
@@ -75,7 +74,7 @@ public function run()
7574

7675
// Prepare transaction data
7776
$orderData = $orderWrapper->wrapOrder($order);
78-
77+
7978
// Add payment event
8079
$gaScripts .= $this->module->getTools()->renderEvent(
8180
'add_payment_info',

classes/Wrapper/OrderWrapper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
use Configuration;
2424
use Context;
2525
use Currency;
26-
use Order;
2726
use PrestaShop\Module\Ps_Googleanalytics\Hooks\WrapperInterface;
2827
use Shop;
29-
use Validate;
3028

3129
class OrderWrapper implements WrapperInterface
3230
{

tests/phpstan/phpstan-1.7.6.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ parameters:
55
ignoreErrors:
66
- '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#'
77
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
8+
- '#Property TabCore\:\:\$name \(string\) does not accept array.#'
9+
- '#Parameter \#1 \$id of class Currency constructor expects null, int given.#'

tests/phpstan/phpstan-1.7.7.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ includes:
44
parameters:
55
ignoreErrors:
66
- '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#'
7+
- '#Property TabCore\:\:\$name \(string\) does not accept array.#'

upgrade/upgrade-5.0.0.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function upgrade_module_5_0_0($object)
2828
{
2929
$database = new PrestaShop\Module\Ps_Googleanalytics\Database\Install($object);
3030

31-
return
31+
return
3232
Configuration::deleteByName('GA_V4_ENABLED') &&
3333
$object->registerHook('actionValidateOrder') &&
3434
$database->installTab() &&

0 commit comments

Comments
 (0)