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\Product\Sku; |
16
|
|
|
|
17
|
|
|
use Gpupo\CommonSdk\Entity\EntityAbstract; |
18
|
|
|
use Gpupo\CommonSdk\Entity\EntityInterface; |
19
|
|
|
|
20
|
|
|
final class Item extends EntityAbstract implements EntityInterface |
21
|
|
|
{ |
22
|
|
|
protected $primaryKey = 'sku'; |
23
|
|
|
|
24
|
|
|
protected $exclude = ['price', 'priceSchedule', 'stock', 'status']; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @codeCoverageIgnore |
28
|
|
|
*/ |
29
|
|
|
public function getSchema() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
'sku' => 'string', |
33
|
|
|
'name' => 'string', |
34
|
|
|
'description' => 'string', |
35
|
|
|
'color' => 'string', |
36
|
|
|
'size' => 'string', |
37
|
|
|
'gender' => 'string', |
38
|
|
|
'eanIsbn' => 'string', |
39
|
|
|
'images' => 'object', |
40
|
|
|
'video' => 'string', |
41
|
|
|
'height' => 'string', |
42
|
|
|
'width' => 'string', |
43
|
|
|
'depth' => 'string', |
44
|
|
|
'weight' => 'string', |
45
|
|
|
'price' => 'object', |
46
|
|
|
'priceSchedule' => 'object', |
47
|
|
|
'stock' => 'object', |
48
|
|
|
'status' => 'object', |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
109 |
|
protected function setUp() |
56
|
|
|
{ |
57
|
109 |
|
$this->setOptionalSchema($this->exclude); |
58
|
109 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
113 |
|
protected function beforeConstruct($data = null) |
64
|
|
|
{ |
65
|
113 |
|
if (empty($data)) { |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
113 |
|
if (is_array($data)) { |
70
|
113 |
|
if (array_key_exists('stock', $data)) { |
71
|
106 |
|
$data['stock'] = ['available' => $data['stock']]; |
72
|
|
|
} |
73
|
|
|
|
74
|
113 |
|
if (array_key_exists('listPrice', $data)) { |
75
|
106 |
|
$data['price'] = ['price' => $data['listPrice']]; |
76
|
106 |
|
unset($data['listPrice']); |
77
|
|
|
} |
78
|
|
|
|
79
|
113 |
|
if (array_key_exists('sellPrice', $data)) { |
80
|
106 |
|
$data['priceSchedule'] = ['priceTo' => $data['sellPrice']]; |
81
|
106 |
|
unset($data['sellPrice']); |
82
|
|
|
} |
83
|
|
|
|
84
|
113 |
|
if (array_key_exists('status', $data)) { |
85
|
106 |
|
$data['status'] = ['active' => $data['status']]; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
113 |
|
return $data; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
8 |
|
public function toArray() |
96
|
|
|
{ |
97
|
8 |
|
$a = parent::toArray(); |
98
|
|
|
|
99
|
8 |
|
foreach ($this->exclude as $k) { |
100
|
8 |
|
unset($a[$k]); |
101
|
|
|
} |
102
|
|
|
|
103
|
8 |
|
return $a; |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
protected function toPrice() |
107
|
|
|
{ |
108
|
1 |
|
return $this->getPrice()->toArray(); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
protected function toPriceSchedule() |
112
|
|
|
{ |
113
|
1 |
|
return $this->getPriceSchedule()->toArray(); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
1 |
|
protected function toStatus() |
117
|
|
|
{ |
118
|
1 |
|
return $this->getStatus()->toArray(); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
protected function toStock() |
122
|
|
|
{ |
123
|
1 |
|
return $this->getStock()->toArray(); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: