|
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\Decorator; |
|
16
|
|
|
|
|
17
|
|
|
use Gpupo\CommonSchema\Trading\OrderSchema; |
|
18
|
|
|
use Gpupo\CommonSchema\Trading\OrderTrait; |
|
19
|
|
|
use Gpupo\CommonSchema\Trading\TradingInterface; |
|
20
|
|
|
|
|
21
|
|
|
class CommonSchema extends AbstractDecorator implements DecoratorInterface, TradingInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use OrderTrait; |
|
24
|
|
|
|
|
25
|
|
|
protected function getAcceptedOffer() |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->getOrder()->getItems()->toSchema(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function getCustomer() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->getOrder()->getShipping()->getCustomer()->toSchema(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function getBillingAddress() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->getOrder()->getShipping()->getCustomer()->getAddress()->toSchema(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getMerchant() |
|
41
|
|
|
{ |
|
42
|
|
|
return ['name' => $this->getOrder()->getOriginSite()]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function getPrice() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->getOrder()->getTotalNet(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function getDiscount() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->getOrder()->getTotalDiscount(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function getOrderNumber() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->getOrder()->getOrderNumber(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function getOrderStatus() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getOrder()->getOrderStatus(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function getOrderDate() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getOrder()->getOrderDate(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function fetch($key) |
|
71
|
|
|
{ |
|
72
|
|
|
$method = 'get'.ucfirst($key); |
|
73
|
|
|
|
|
74
|
|
|
if (method_exists(__CLASS__, $method)) { |
|
75
|
|
|
return $this->$method(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
error_log('protected function '.$method.'(){} missed!'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function toArray() |
|
82
|
|
|
{ |
|
83
|
|
|
$schema = OrderSchema::getInstance()->getSchema(); |
|
84
|
|
|
$output = []; |
|
85
|
|
|
foreach ($schema as $k => $v) { |
|
86
|
|
|
$output[$k] = $this->fetch($k); |
|
87
|
|
|
} |
|
88
|
|
|
OrderSchema::getInstance()->validate($output); |
|
89
|
|
|
|
|
90
|
|
|
return $output; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|