Skip to content

Commit 0756320

Browse files
committed
Fix many issues and improve json_decode data retreiving
1 parent e286981 commit 0756320

8 files changed

Lines changed: 29 additions & 10 deletions

File tree

classes/Form/ConfigurationForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function generate()
6969
$helper->toolbar_btn = [
7070
'save' => [
7171
'desc' => $this->module->l('Save'),
72-
'href' => AdminController::$currentIndex . '&configure=' . $this->module->name . '&save' . $this->module->name .
72+
'href' => AdminController::$currentIndex . '&configure=' . $this->module->name . '&save=' . $this->module->name .
7373
'&token=' . Tools::getAdminTokenLite('AdminModules'),
7474
],
7575
'back' => [

classes/Handler/GanalyticsDataHandler.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function readData()
9393
return [];
9494
}
9595

96-
return json_decode($dataReturned, true);
96+
return $this->jsonDecodeValidJson($dataReturned);
9797
}
9898

9999
/**
@@ -113,8 +113,7 @@ private function appendData($data)
113113
if (false === $dataReturned) {
114114
$newData = [$data];
115115
} else {
116-
$newData = json_decode($dataReturned, true);
117-
$newData[] = $data;
116+
$newData[] = $this->jsonDecodeValidJson($dataReturned);
118117
}
119118

120119
return $this->ganalyticsDataRepository->addNewRow(
@@ -123,4 +122,22 @@ private function appendData($data)
123122
json_encode($newData)
124123
);
125124
}
125+
126+
/**
127+
* Check if the json is valid and returns an empty array if not
128+
*
129+
* @param string $json
130+
*
131+
* @return array
132+
*/
133+
protected function jsonDecodeValidJson($json)
134+
{
135+
$array = json_decode($json, true);
136+
137+
if (JSON_ERROR_NONE === json_last_error()) {
138+
return $array;
139+
}
140+
141+
return [];
142+
}
126143
}

classes/Handler/GanalyticsJsHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function __construct(Ps_Googleanalytics $module, Context $context)
4040
* Generate Google Analytics js
4141
*
4242
* @param string $jsCode
43-
* @param int $isBackoffice
43+
* @param bool $isBackoffice
4444
*
4545
* @return void|string
4646
*/
47-
public function generate($jsCode, $isBackoffice = 0)
47+
public function generate($jsCode, $isBackoffice = false)
4848
{
4949
if (Configuration::get('GA_ACCOUNT_ID')) {
5050
$this->context->smarty->assign(

classes/Hook/HookActionCartSave.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function run()
7272
foreach ($cartProducts as $cartProduct) {
7373
if ($cartProduct['id_product'] == Tools::getValue('id_product')) {
7474
$addProduct = $cartProduct;
75+
break;
7576
}
7677
}
7778
}

classes/Hook/HookDisplayBackOfficeHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function run()
103103
}
104104
}
105105

106-
return $js . $this->module->hookdisplayHeader(null, true) . $gaTagHandler->generate($gaScripts, 1);
106+
return $js . $this->module->hookdisplayHeader(null, true) . $gaTagHandler->generate($gaScripts, true);
107107
}
108108

109109
return $js;

classes/Wrapper/OrderWrapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public function wrapOrder($id_order)
5151
'shipping' => $order->total_shipping,
5252
'tax' => $order->total_paid_tax_incl - $order->total_paid_tax_excl,
5353
'url' => $this->context->link->getAdminLink('AdminGanalyticsAjax'),
54-
'customer' => $order->id_customer, ];
54+
'customer' => $order->id_customer,
55+
];
5556
}
5657
}
5758
}

ps_googleanalytics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function hookDisplayAdminOrder()
141141

142142
echo $gaTagHandler->generate(
143143
$this->context->cookie->__get('ga_admin_refund'),
144-
1
144+
true
145145
);
146146
$this->context->cookie->__unset('ga_admin_refund');
147147
}

views/templates/hook/ga_tag.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
{/literal}
3030
{/if}
3131

32-
{if ($jsState != 1 && $isBackoffice == 0)}
32+
{if ($jsState != 1 && $isBackoffice === true)}
3333
{literal}
3434
<script type="text/javascript">
3535
ga('send', 'pageview');

0 commit comments

Comments
 (0)