Skip to content

Commit 264bdf6

Browse files
committed
Fixes
1 parent c1e6737 commit 264bdf6

4 files changed

Lines changed: 16 additions & 21 deletions

File tree

classes/Hook/HookDisplayBackOfficeHeader.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ protected function backloadFailedOrders()
104104
);
105105

106106
// Process each failed order
107-
foreach ($failedOrders as $idOrder) {
108-
$gaScripts .= $this->processOrder((int) $idOrder);
107+
foreach ($failedOrders as $row) {
108+
$gaScripts .= $this->processOrder((int) $row['id_order']);
109109
}
110110

111111
return $gaScripts;
@@ -155,17 +155,18 @@ public function processOrder($idOrder)
155155
$productWrapper = new ProductWrapper($this->context);
156156
$orderWrapper = new OrderWrapper($this->context);
157157

158+
// If it's a completely new order, add order to repository, so we can later mark it as sent
159+
if (empty($ganalyticsRepository->findGaOrderByOrderId((int) $order->id))) {
160+
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
161+
}
162+
158163
// If the order was already sent for some reason, don't do anything
159164
if ($ganalyticsRepository->orderAlreadySent((int) $order->id)) {
160165
return $gaScripts;
161166
}
162-
163-
// Add order to repository, so we can later mark it as sent
164-
// If revisiting this page, repository inserts ignore, so no worries
165-
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
166167

167168
// Prepare transaction data
168-
$orderData = $orderWrapper->wrapOrder((int) $order->id);
169+
$orderData = $orderWrapper->wrapOrder($order);
169170

170171
// Add payment event
171172
$gaScripts .= $this->module->getTools()->renderEvent(

classes/Hook/HookDisplayOrderConfirmation.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,18 @@ public function run()
6363
$productWrapper = new ProductWrapper($this->context);
6464
$orderWrapper = new OrderWrapper($this->context);
6565

66+
// If it's a completely new order, add order to repository, so we can later mark it as sent
67+
if (empty($ganalyticsRepository->findGaOrderByOrderId((int) $order->id))) {
68+
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
69+
}
70+
6671
// If the customer is revisiting confirmation screen and the order was already sent, we don't do anything
6772
if ($ganalyticsRepository->orderAlreadySent((int) $order->id)) {
6873
return $gaScripts;
6974
}
70-
71-
// Add order to repository, so we can later mark it as sent
72-
// If revisiting this page, repository inserts ignore, so no worries
73-
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
7475

7576
// Prepare transaction data
76-
$orderData = $orderWrapper->wrapOrder((int) $order->id);
77+
$orderData = $orderWrapper->wrapOrder($order);
7778

7879
// Add payment event
7980
$gaScripts .= $this->module->getTools()->renderEvent(

classes/Repository/GanalyticsRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GanalyticsRepository
2727
const TABLE_NAME = 'ganalytics';
2828

2929
/**
30-
* findGaOrderByOrderId
30+
* Finds if we have a record for this order ID.
3131
*
3232
* @param int $orderId
3333
*

classes/Wrapper/OrderWrapper.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,8 @@ public function __construct(Context $context)
4040
/**
4141
* Return a detailed transaction for Google Analytics
4242
*/
43-
public function wrapOrder($id_order)
43+
public function wrapOrder($order)
4444
{
45-
$order = new Order((int) $id_order);
46-
47-
// Check order still exists
48-
if (!Validate::isLoadedObject($order)) {
49-
return;
50-
}
51-
5245
// Prepare currency information
5346
$currency = new Currency((int) $order->id_currency);
5447

0 commit comments

Comments
 (0)