|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/netshoes-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 <http://www.g1mr.com/>. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gpupo\NetshoesSdk\Entity\Order; |
|
16
|
|
|
|
|
17
|
|
|
use DateInterval; |
|
18
|
|
|
use DateTime; |
|
19
|
|
|
use Gpupo\CommonSdk\Entity\EntityInterface; |
|
20
|
|
|
use Gpupo\CommonSdk\Traits\TranslatorManagerTrait; |
|
21
|
|
|
use Gpupo\NetshoesSdk\Entity\AbstractManager; |
|
22
|
|
|
|
|
23
|
|
|
class Manager extends AbstractManager |
|
24
|
|
|
{ |
|
25
|
|
|
use TranslatorManagerTrait; |
|
26
|
|
|
|
|
27
|
|
|
protected $entity = 'Order'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @codeCoverageIgnore |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->maps = include 'map.config.php'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function factoryDecorator(Order $order, $decoratorName) |
|
38
|
|
|
{ |
|
39
|
1 |
|
$className = __NAMESPACE__.'\\Decorator\\'.$decoratorName; |
|
40
|
1 |
|
$instance = new $className(); |
|
41
|
1 |
|
$instance->setOrder($order); |
|
42
|
|
|
|
|
43
|
1 |
|
return $instance; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
7 |
|
public function update(EntityInterface $entity, EntityInterface $existent = null) |
|
50
|
|
|
{ |
|
51
|
7 |
|
if (!empty($existent)) { |
|
52
|
|
|
if ($entity->getOrderStatus() === $existent->getOrderStatus()) { |
|
|
|
|
|
|
53
|
|
|
$this->log('info', 'Order sem atualização'); |
|
54
|
|
|
|
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
7 |
|
if (in_array($entity->getOrderStatus(), ['approved', 'canceled', |
|
|
|
|
|
|
60
|
7 |
|
'delivered', 'invoiced', 'shipped', ], true)) { |
|
61
|
6 |
|
$decorator = $this->factoryDecorator($entity, 'Status\\'.ucfirst($entity->getOrderStatus())); |
|
|
|
|
|
|
62
|
6 |
|
$json = $decorator->toJson(); |
|
63
|
6 |
|
$mapKey = 'to'.ucfirst($entity->getOrderStatus()); |
|
|
|
|
|
|
64
|
6 |
|
$shipping = $entity->getShipping(); |
|
|
|
|
|
|
65
|
6 |
|
$code = $shipping->getShippingCode(); |
|
66
|
6 |
|
$shipping->toJson(); |
|
67
|
5 |
|
$map = $this->factoryMap($mapKey, [ |
|
68
|
5 |
|
'orderNumber' => $entity->getOrderNumber(), |
|
|
|
|
|
|
69
|
5 |
|
'itemId' => $entity->getOrderNumber(), |
|
|
|
|
|
|
70
|
5 |
|
'shippingCode' => $code, |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
5 |
|
return $this->execute($map, $json); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
throw new \InvalidArgumentException('Order Status não suportado', 1); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function factoryTranslator(array $data = []) |
|
80
|
|
|
{ |
|
81
|
|
|
$translator = new Translator($data); |
|
82
|
|
|
|
|
83
|
|
|
return $translator; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
public function fetchQueue($offset = 0, $limit = 50, array $parameters = []) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
1 |
|
$date = new DateTime(); |
|
89
|
1 |
|
$date->sub(new DateInterval('P4D')); |
|
90
|
|
|
|
|
91
|
1 |
|
return $this->translatorFetch(0, 50, [ |
|
|
|
|
|
|
92
|
1 |
|
'orderStatus' => 'approved', |
|
93
|
1 |
|
'orderStartDate' => $date->format('Y-m-d'), |
|
94
|
|
|
]); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: