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
|
|
|
|
19
|
|
|
class CommonSchema extends AbstractDecorator implements DecoratorInterface |
20
|
|
|
{ |
21
|
|
|
protected $dict = [ |
22
|
|
|
'merchant' => [ |
23
|
|
|
'name' => 'string', |
24
|
|
|
], |
25
|
|
|
'price' => 'totalNet', |
26
|
|
|
'acceptedOffer' => [ |
27
|
|
|
[ |
28
|
|
|
'itemOffered' => [ |
29
|
|
|
'name' => 'string', |
30
|
|
|
'sku' => 'string', |
31
|
|
|
'url' => 'string', |
32
|
|
|
'image' => 'string', |
33
|
|
|
], |
34
|
|
|
'price' => 'string', |
35
|
|
|
'priceCurrency' => 'string', |
36
|
|
|
'eligibleQuantity' => [ |
37
|
|
|
'value' => 'string', |
38
|
|
|
], |
39
|
|
|
'seller' => [ |
40
|
|
|
'name' => 'string', |
41
|
|
|
], |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
'discount' => 'totalDiscount', |
45
|
|
|
'customer' => [ |
46
|
|
|
'name' => 'string', |
47
|
|
|
], |
48
|
|
|
'billingAddress' => [ |
49
|
|
|
'name' => 'string', |
50
|
|
|
'streetAddress' => 'string', |
51
|
|
|
'addressLocality' => 'string', |
52
|
|
|
'addressRegion' => 'string', |
53
|
|
|
'addressCountry' => 'string', |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
protected function getMerchant() |
58
|
|
|
{ |
59
|
|
|
$key = $this->callOrder('originSite'); |
60
|
|
|
$dict = [ |
61
|
|
|
'' => '', |
62
|
|
|
'ZT' => 'Zattini', |
63
|
|
|
'NS' => 'Netshoes', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
return $dict[$key]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function getPriceCurrency() |
70
|
|
|
{ |
71
|
|
|
'BRL'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function getAcceptedOffer() |
75
|
|
|
{ |
76
|
|
|
return $this->getOrder()->getItems()->toSchema(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function getUrl() |
80
|
|
|
{ |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function getPaymentMethod() |
84
|
|
|
{ |
85
|
|
|
} |
86
|
|
|
protected function getPaymentMethodId() |
87
|
|
|
{ |
88
|
|
|
} |
89
|
|
|
protected function getIsGift() |
90
|
|
|
{ |
91
|
|
|
} |
92
|
|
|
protected function getDiscountCurrency() |
93
|
|
|
{ |
94
|
|
|
} |
95
|
|
|
protected function getCustomer() |
96
|
|
|
{ |
97
|
|
|
} |
98
|
|
|
protected function getBillingAddress() |
99
|
|
|
{ |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function callOrder($key) |
103
|
|
|
{ |
104
|
|
|
if (array_key_exists($key, $this->dict) && !is_array($this->dict[$key])) { |
105
|
|
|
$key = $this->dict[$key]; |
106
|
|
|
} |
107
|
|
|
$method = 'get'.ucfirst($key); |
108
|
|
|
|
109
|
|
|
if (method_exists(__CLASS__, $method)) { |
110
|
|
|
return $this->$method(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
try { |
114
|
|
|
return $this->getOrder()->$method(); |
115
|
|
|
} catch (\BadMethodCallException $e) { |
116
|
|
|
error_log('protected function '.$method.'(){}'); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
1 |
|
public function toArray() |
121
|
|
|
{ |
122
|
1 |
|
$schema = OrderSchema::getInstance()->getSchema(); |
123
|
1 |
|
$output = []; |
124
|
1 |
|
foreach ($schema as $k => $v) { |
125
|
1 |
|
$output[$k] = $this->callOrder($k); |
126
|
|
|
} |
127
|
1 |
|
OrderSchema::getInstance()->validate($output); |
128
|
|
|
|
129
|
1 |
|
return $output; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|