1 | <?php |
||
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() |
|
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() |
|
105 | |||
106 | 1 | protected function toPrice() |
|
110 | |||
111 | 1 | protected function toPriceSchedule() |
|
112 | { |
||
113 | 1 | return $this->getPriceSchedule()->toArray(); |
|
114 | } |
||
115 | |||
116 | 1 | protected function toStatus() |
|
120 | |||
121 | 1 | protected function toStock() |
|
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: