Skip to content

Commit 49ba592

Browse files
committed
Unify order marking functions
1 parent b9e170f commit 49ba592

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

classes/Hook/HookDisplayBackOfficeHeader.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,8 @@ public function run()
8181
foreach ($gaOrderRecords as $row) {
8282
$transaction = $orderWrapper->wrapOrder($row['id_order']);
8383
if (!empty($transaction)) {
84-
$ganalyticsRepository->updateData(
85-
[
86-
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
87-
'sent' => 1,
88-
],
89-
'id_order = ' . (int) $row['id_order'] . ' AND id_shop = ' . (int) $this->context->shop->id
90-
);
84+
// Mark it as successfully sent
85+
$ganalyticsRepository->markOrderAsSent((int) $row['id_order']);
9186

9287
// Generate transaction event
9388
$callbackData = [

classes/Repository/GanalyticsRepository.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,23 @@ public function updateData($data, $where, $limit = 0)
116116
$limit
117117
);
118118
}
119+
120+
/**
121+
* Marks order as successfully sent to GA via callback
122+
*
123+
* @param int $idOrder
124+
*
125+
* @return bool
126+
*/
127+
public function markOrderAsSent($idOrder)
128+
{
129+
return Db::getInstance()->update(
130+
self::TABLE_NAME,
131+
[
132+
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
133+
'sent' => 1,
134+
],
135+
'id_order = ' . (int) $idOrder
136+
);
137+
}
119138
}

controllers/admin/AdminGanalyticsAjax.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@ public function init()
3030
$order = new Order($orderId);
3131

3232
if (Validate::isLoadedObject($order) && (isset($this->context->employee->id) && $this->context->employee->id)) {
33-
(new GanalyticsRepository())->updateData(
34-
[
35-
'sent' => 1,
36-
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
37-
],
38-
'id_order = ' . $orderId
39-
);
40-
33+
(new GanalyticsRepository())->markOrderAsSent((int) $orderId);
4134
$this->ajaxDie('OK');
4235
}
4336

controllers/front/ajax.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ public function initContent()
3838
$this->ajaxDie('KO');
3939
}
4040

41-
(new GanalyticsRepository())->updateData(
42-
[
43-
'sent' => 1,
44-
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
45-
],
46-
'id_order = ' . $orderId,
47-
1
48-
);
41+
(new GanalyticsRepository())->markOrderAsSent((int) $orderId);
4942

5043
$this->ajaxDie('OK');
5144
}

0 commit comments

Comments
 (0)