Skip to content

Commit 595eb51

Browse files
committed
Refacto frontend event sending
1 parent 39aed21 commit 595eb51

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

classes/Hook/HookDisplayHeader.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,22 @@ public function run()
6161
return '';
6262
}
6363

64+
// Resolve if we should add user ID into the code
6465
$userId = null;
65-
6666
if (Configuration::get('GA_USERID_ENABLED')
6767
&& $this->context->customer instanceof Customer
6868
&& $this->context->customer->isLogged()
6969
) {
7070
$userId = (int) $this->context->customer->id;
7171
}
7272

73-
$gaAnonymizeEnabled = Configuration::get('GA_ANONYMIZE_ENABLED');
74-
7573
$this->context->smarty->assign(
7674
[
7775
'backOffice' => $this->backOffice,
7876
'trackBackOffice' => Configuration::get('GA_TRACK_BACKOFFICE_ENABLED'),
7977
'userId' => $userId,
8078
'gaAccountId' => Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')),
81-
'gaAnonymizeEnabled' => $gaAnonymizeEnabled,
79+
'gaAnonymizeEnabled' => Configuration::get('GA_ANONYMIZE_ENABLED'),
8280
]
8381
);
8482

classes/Hook/HookDisplayOrderConfirmation.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ public function run()
5757
return $gaScripts;
5858
}
5959

60-
// Load up the order repository and try to find the order
60+
// Load up our handlers and repositories
6161
$ganalyticsRepository = new GanalyticsRepository();
62+
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
63+
$productWrapper = new ProductWrapper($this->context);
64+
$orderWrapper = new OrderWrapper($this->context);
65+
66+
// If the customer is revisiting confirmation screen and the order was already sent, we don't do anything
6267
if ($ganalyticsRepository->orderAlreadySent((int) $order->id)) {
6368
return $gaScripts;
6469
}
6570

6671
// Add order to repository, so we can later mark it as sent
67-
// Repository inserts ignore, so no worries
72+
// If revisiting this page, repository inserts ignore, so no worries
6873
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
6974

70-
// Load up our handlers
71-
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
72-
$productWrapper = new ProductWrapper($this->context);
73-
$orderWrapper = new OrderWrapper($this->context);
74-
7575
// Prepare transaction data
7676
$orderData = $orderWrapper->wrapOrder((int) $order->id);
7777

@@ -84,7 +84,7 @@ public function run()
8484
]
8585
);
8686

87-
// Prepare order products
87+
// Prepare order products, if the cart still exists
8888
$orderProducts = [];
8989
$cart = new Cart($order->id_cart);
9090
if (Validate::isLoadedObject($cart)) {

0 commit comments

Comments
 (0)