Skip to content

Commit f2733cd

Browse files
authored
Merge pull request #9 from zawaze/master
Add gtin on review export
2 parents 926fb66 + 66c843b commit f2733cd

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

Command/SendOrderCommand.php

+16-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use NetReviews\Model\NetreviewsOrderQueueQuery;
99
use NetReviews\Service\OrderService;
1010
use Propel\Runtime\ActiveQuery\Criteria;
11+
use Propel\Runtime\Propel;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314
use Thelia\Command\ContainerAwareCommand;
@@ -31,17 +32,24 @@ public function execute(InputInterface $input, OutputInterface $output)
3132
/** @var OrderService $netreviewsOrderService */
3233
$netreviewsOrderService = $this->getContainer()->get('netreviews.order.service');
3334

34-
$ordersInQueue = NetreviewsOrderQueueQuery::create()
35-
->filterByTreatedAt(null, Criteria::ISNULL)
36-
->find();
35+
$con = Propel::getConnection();
3736

38-
$orderCount = $ordersInQueue->count();
37+
$ordersInQueue = "
38+
SELECT n.order_id 'order_id'
39+
FROM netreviews_order_queue n
40+
JOIN `order` o on n.order_id = o.id
41+
WHERE o.status_id =4 AND n.treated_at IS NULL";
42+
43+
$stmt = $con->prepare($ordersInQueue);
44+
$stmt->execute();
45+
$results = $stmt->fetchAll();
46+
47+
$orderCount = count($results);
3948
$output->writeln(sprintf("<info>$orderCount orders found</info>"));
4049

41-
/** @var NetreviewsOrderQueue $order */
42-
foreach ($ordersInQueue as $order) {
50+
foreach ($results as $order) {
4351
try {
44-
$orderId = $order->getOrderId();
52+
$orderId = $order['order_id'];
4553
$response = $netreviewsOrderService->sendOrderToNetReviews($orderId);
4654
$return = $response->return;
4755

@@ -50,7 +58,7 @@ public function execute(InputInterface $input, OutputInterface $output)
5058
throw new \Exception($debug);
5159
}
5260
} catch (\Exception $e) {
53-
$output->writeln(sprintf("<error>Error on order id ".$order->getOrderId().":".$e->getMessage()."</error>"));
61+
$output->writeln(sprintf("<error>Error on order id ".$order['order_id'].":".$e->getMessage()."</error>"));
5462
}
5563
}
5664
} catch (\Exception $e) {

Object/NetReviewsProduct.php

+19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class NetReviewsProduct
1616
/** @var string */
1717
protected $imageUrl;
1818

19+
/** @var string */
20+
protected $gtinEan;
21+
1922
/**
2023
* @return int
2124
*/
@@ -88,5 +91,21 @@ public function setImageUrl($imageUrl)
8891
return $this;
8992
}
9093

94+
/**
95+
* @return string
96+
*/
97+
public function getGtinEan()
98+
{
99+
return $this->gtinEan;
100+
}
91101

102+
/**
103+
* @param string $gtinEan
104+
* @return NetReviewsProduct
105+
*/
106+
public function setGtinEan(string $gtinEan)
107+
{
108+
$this->gtinEan = $gtinEan;
109+
return $this;
110+
}
92111
}

Service/OrderService.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public function sendOrderToNetReviews($orderId)
5252
'id_product' => $product->getId(),
5353
'name_product' => $product->getName(),
5454
'url_product' => $product->getUrl(),
55-
'url_product_image' => $product->getImageUrl()
55+
'url_product_image' => $product->getImageUrl(),
56+
'GTIN_EAN' => $product->getGtinEan()
5657
];
5758
}
5859

@@ -109,7 +110,7 @@ public function getNetreviewsOrder($orderId)
109110
$statusToExport = NetReviews::getConfigValue('status_to_export', '3,4');
110111
$delay = NetReviews::getConfigValue('email_delay', '3');
111112

112-
$orderProductSql = "SELECT o.ref, o.created_at, cu.firstname, cu.lastname, cu.email, op.product_ref, op.title, ru.url, pi.file
113+
$orderProductSql = "SELECT o.ref, o.created_at, cu.firstname, cu.lastname, cu.email, op.product_ref, op.title, op.ean_code, ru.url, pi.file
113114
FROM order_product op
114115
LEFT JOIN `order` o ON (op.order_id = o.id)
115116
LEFT JOIN `customer` cu ON (o.customer_id = cu.id)
@@ -142,7 +143,8 @@ public function getNetreviewsOrder($orderId)
142143

143144
foreach ($results as $orderProduct) {
144145
$product = new NetReviewsProduct();
145-
$product->setId($orderProduct['product_ref'])
146+
$product
147+
->setId($orderProduct['product_ref'])
146148
->setName($orderProduct['title']);
147149

148150
if ($orderProduct['file'] !== null) {
@@ -156,6 +158,10 @@ public function getNetreviewsOrder($orderId)
156158
$product->setUrl($baseUrl . "/" . $orderProduct['url']);
157159
}
158160

161+
if($orderProduct['ean_code']){
162+
$product->setGtinEan($orderProduct['ean_code']);
163+
}
164+
159165
$products[] = $product;
160166
}
161167

0 commit comments

Comments
 (0)