|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/netshoes-sdk |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* For more information, see <http://www.g1mr.com/>. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Gpupo\NetshoesSdk\Entity\Product\Sku; |
|
12
|
|
|
|
|
13
|
|
|
use Gpupo\CommonSdk\Entity\EntityAbstract; |
|
14
|
|
|
use Gpupo\CommonSdk\Entity\EntityInterface; |
|
15
|
|
|
|
|
16
|
|
|
class Item extends EntityAbstract implements EntityInterface |
|
17
|
|
|
{ |
|
18
|
|
|
protected $primaryKey = 'sku'; |
|
19
|
|
|
|
|
20
|
|
|
protected $exclude = ['price', 'priceSchedule', 'stock', 'status']; |
|
21
|
|
|
|
|
22
|
7 |
|
public function getSchema() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
7 |
|
'sku' => 'string', |
|
26
|
|
|
'name' => 'string', |
|
27
|
|
|
'description' => 'string', |
|
28
|
|
|
'color' => 'string', |
|
29
|
|
|
'size' => 'string', |
|
30
|
|
|
'gender' => 'string', |
|
31
|
|
|
'eanIsbn' => 'string', |
|
32
|
|
|
'images' => 'object', |
|
33
|
|
|
'video' => 'string', |
|
34
|
|
|
'height' => 'string', |
|
35
|
|
|
'width' => 'string', |
|
36
|
|
|
'depth' => 'string', |
|
37
|
|
|
'weight' => 'string', |
|
38
|
|
|
'price' => 'object', |
|
39
|
|
|
'priceSchedule' => 'object', |
|
40
|
|
|
'stock' => 'object', |
|
41
|
|
|
'status' => 'object', |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
7 |
|
protected function setUp() |
|
49
|
|
|
{ |
|
50
|
7 |
|
$this->setOptionalSchema($this->exclude); |
|
51
|
7 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
7 |
|
protected function beforeConstruct($data = null) |
|
57
|
|
|
{ |
|
58
|
7 |
|
if (empty($data)) { |
|
59
|
|
|
return; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
7 |
|
if (is_array($data)) { |
|
63
|
7 |
|
if (array_key_exists('stock', $data)) { |
|
64
|
|
|
$data['stock'] = ['available' => $data['stock']]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
7 |
|
if (array_key_exists('listPrice', $data)) { |
|
68
|
|
|
$data['price'] = ['price' => $data['listPrice']]; |
|
69
|
|
|
unset($data['listPrice']); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
7 |
|
if (array_key_exists('sellPrice', $data)) { |
|
73
|
|
|
$data['priceSchedule'] = ['priceTo' => $data['sellPrice']]; |
|
74
|
|
|
unset($data['sellPrice']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
7 |
|
if (array_key_exists('status', $data)) { |
|
78
|
|
|
$data['status'] = ['active' => $data['status']]; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
7 |
|
return $data; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public function toArray() |
|
89
|
|
|
{ |
|
90
|
2 |
|
$a = parent::toArray(); |
|
91
|
|
|
|
|
92
|
2 |
|
foreach ($this->exclude as $k) { |
|
93
|
2 |
|
unset($a[$k]); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
2 |
|
return $a; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|