Skip to content

Commit a40cb2b

Browse files
committed
Unify adding order to repository
1 parent 53ae405 commit a40cb2b

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

classes/Hook/HookDisplayBackOfficeHeader.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,8 @@ public function run()
6969
if (Validate::isLoadedObject($order) && strtotime('+1 day', strtotime($order->date_add)) > time()) {
7070
$gaOrderSent = $ganalyticsRepository->findGaOrderByOrderId((int) Tools::getValue('id_order'));
7171
if ($gaOrderSent === false) {
72-
$ganalyticsRepository->addNewRow(
73-
[
74-
'id_order' => (int) Tools::getValue('id_order'),
75-
'id_shop' => (int) $this->context->shop->id,
76-
'sent' => 0,
77-
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
78-
]
79-
);
72+
// Add order to repository, so we can later mark it as sent
73+
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
8074
}
8175
}
8276
} else {

classes/Hook/HookDisplayOrderConfirmation.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ public function run()
5656
$gaOrderSent = $ganalyticsRepository->findGaOrderByOrderId((int) $order->id);
5757

5858
if (false === $gaOrderSent) {
59-
$ganalyticsRepository->addNewRow(
60-
[
61-
'id_order' => (int) $order->id,
62-
'id_shop' => (int) $this->context->shop->id,
63-
'sent' => 0,
64-
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
65-
]
66-
);
59+
// Add order to repository, so we can later mark it as sent
60+
$ganalyticsRepository->addOrder((int) $order->id, (int) $order->id_shop);
6761

6862
$cart = new Cart($order->id_cart);
6963
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
@@ -96,6 +90,8 @@ public function run()
9690
foreach ($cart->getProducts() as $order_product) {
9791
$orderProducts[] = $productWrapper->wrapProduct($order_product);
9892
}
93+
94+
// Render transaction code
9995
$gaScripts .= $this->module->getTools()->addTransaction($orderProducts, $transaction);
10096

10197
return $gaTagHandler->generate($gaScripts);

classes/Repository/GanalyticsRepository.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ public function addNewRow(array $data, $type = Db::INSERT_IGNORE)
7878
);
7979
}
8080

81+
/**
82+
* Adds new order into repository
83+
*
84+
* @param int $idOrder
85+
* @param int $idShop
86+
*
87+
* @return bool
88+
*/
89+
public function addOrder(int $idOrder, int $idShop)
90+
{
91+
return $this->addNewRow(
92+
[
93+
'id_order' => (int) $idOrder,
94+
'id_shop' => (int) $idShop,
95+
'sent' => 0,
96+
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
97+
]
98+
);
99+
}
100+
81101
/**
82102
* updateData
83103
*

0 commit comments

Comments
 (0)