|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/cnova-sdk |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the information of copyright and license you should read the file |
|
7
|
|
|
* LICENSE which is distributed with this source code. |
|
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
|
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
|
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
|
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
|
12
|
|
|
* For more information, see <https://opensource.gpupo.com/>. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gpupo\CnovaSdk\Entity\Order; |
|
16
|
|
|
|
|
17
|
|
|
use Gpupo\CnovaSdk\Entity\ManagerAbstract; |
|
18
|
|
|
use Gpupo\CnovaSdk\Entity\Order\Trackings\Tracking\Tracking; |
|
19
|
|
|
|
|
20
|
|
|
class Manager extends ManagerAbstract |
|
21
|
|
|
{ |
|
22
|
|
|
protected $entity = 'Order'; |
|
23
|
|
|
|
|
24
|
|
|
protected $maps = [ |
|
25
|
|
|
'saveStatus' => ['POST', '/orders/{itemId}/trackings/{status}'], |
|
26
|
|
|
'findById' => ['GET', '/orders/{itemId}'], |
|
27
|
|
|
'fetch' => ['GET', '/orders/status/{status}/?_offset={offset}&_limit={limit}'], |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
6 |
|
protected function saveStatus(Order $order, $json) |
|
31
|
|
|
{ |
|
32
|
6 |
|
$status = $order->getStatus(); |
|
33
|
|
|
|
|
34
|
6 |
|
return $this->execute($this->factoryMap( |
|
35
|
6 |
|
'saveStatus', |
|
36
|
6 |
|
['itemId' => $order->getId(), 'status' => $status] |
|
37
|
6 |
|
), $json); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
8 |
|
protected function move($statusTo, Order $order, Tracking $tracking) |
|
41
|
|
|
{ |
|
42
|
8 |
|
if (in_array($statusTo, ['sent', 'delivered', 'cancel'], true)) { |
|
43
|
8 |
|
$order->setStatus($statusTo); |
|
44
|
|
|
|
|
45
|
8 |
|
return $this->saveStatus($order, $tracking->toJson()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Obtém a lista de pedidos recém aprovados e que esperam processamento. |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function fetchQueue($offset = 0, $limit = 50, array $parameters = []) |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $this->fetch($offset, $limit, array_merge(['status' => 'approved'], $parameters)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Registra uma nova operação de tracking de Envio para os itens do pedido. |
|
61
|
|
|
*/ |
|
62
|
4 |
|
public function moveToSent(Order $order, Tracking $tracking) |
|
63
|
|
|
{ |
|
64
|
4 |
|
return $this->move('sent', $order, $tracking); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Registra uma nova operação de tracking de Entrega para os itens do pedido. |
|
69
|
|
|
*/ |
|
70
|
2 |
|
public function moveToDelivered(Order $order, Tracking $tracking) |
|
71
|
|
|
{ |
|
72
|
2 |
|
return $this->move('delivered', $order, $tracking); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Registra uma nova operação de tracking de Entrega para os itens do pedido. |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function moveToCanceled(Order $order, Tracking $tracking) |
|
79
|
|
|
{ |
|
80
|
2 |
|
return $this->move('cancel', $order, $tracking); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|