@@ -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 (
0 commit comments