1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Stock |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Stock\Item; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default product stock item implementation. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Stock |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\MShop\Common\Item\Base |
|
|
|
|
23
|
|
|
implements \Aimeos\MShop\Stock\Item\Iface |
24
|
|
|
{ |
25
|
|
|
private $values; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initializes the stock item object with the given values |
30
|
|
|
* |
31
|
|
|
* @param array $values Associative list of product stock key/value pairs |
32
|
|
|
*/ |
33
|
|
|
public function __construct( array $values = [] ) |
34
|
|
|
{ |
35
|
|
|
parent::__construct( 'stock.', $values ); |
36
|
|
|
|
37
|
|
|
$this->values = $values; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns the type code of the product stock item. |
43
|
|
|
* |
44
|
|
|
* @return string|null Type code of the product stock item |
45
|
|
|
*/ |
46
|
|
|
public function getType() |
47
|
|
|
{ |
48
|
|
|
if( isset( $this->values['stock.type'] ) ) { |
49
|
|
|
return (string) $this->values['stock.type']; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the localized name of the type |
56
|
|
|
* |
57
|
|
|
* @return string|null Localized name of the type |
58
|
|
|
*/ |
59
|
|
|
public function getTypeName() |
60
|
|
|
{ |
61
|
|
|
if( isset( $this->values['stock.typename'] ) ) { |
62
|
|
|
return (string) $this->values['stock.typename']; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the type id of the product stock item |
69
|
|
|
* |
70
|
|
|
* @return string|null Type of the product stock item |
71
|
|
|
*/ |
72
|
|
|
public function getTypeId() |
73
|
|
|
{ |
74
|
|
|
if( isset( $this->values['stock.typeid'] ) ) { |
75
|
|
|
return (string) $this->values['stock.typeid']; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Sets the new type of the product stock item |
82
|
|
|
* |
83
|
|
|
* @param string $id Type of the product stock item |
84
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
85
|
|
|
*/ |
86
|
|
|
public function setTypeId( $id ) |
87
|
|
|
{ |
88
|
|
|
if( (string) $id !== $this->getTypeId() ) |
89
|
|
|
{ |
90
|
|
|
$this->values['stock.typeid'] = (string) $id; |
91
|
|
|
$this->setModified(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns the code of the stock item. |
100
|
|
|
* |
101
|
|
|
* @return string Product code (SKU) |
102
|
|
|
*/ |
103
|
|
|
public function getProductCode() |
104
|
|
|
{ |
105
|
|
|
if( isset( $this->values['stock.productcode'] ) ) { |
106
|
|
|
return (string) $this->values['stock.productcode']; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return ''; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Sets a new code of the stock item. |
115
|
|
|
* |
116
|
|
|
* @param string $code New product code (SKU) |
117
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
118
|
|
|
*/ |
119
|
|
|
public function setProductCode( $code ) |
120
|
|
|
{ |
121
|
|
|
if( (string) $code !== $this->getProductCode() ) |
122
|
|
|
{ |
123
|
|
|
$this->values['stock.productcode'] = (string) $code; |
124
|
|
|
$this->setModified(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns the stock level. |
133
|
|
|
* |
134
|
|
|
* @return integer|null Stock level |
135
|
|
|
*/ |
136
|
|
|
public function getStocklevel() |
137
|
|
|
{ |
138
|
|
|
if( isset( $this->values['stock.stocklevel'] ) ) { |
139
|
|
|
return (int) $this->values['stock.stocklevel']; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Sets the stock level. |
146
|
|
|
* |
147
|
|
|
* @param integer|null $stocklevel New stock level |
148
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
149
|
|
|
*/ |
150
|
|
|
public function setStocklevel( $stocklevel ) |
151
|
|
|
{ |
152
|
|
|
$stocklevel = ( is_numeric( $stocklevel ) ? (int) $stocklevel : null ); |
153
|
|
|
|
154
|
|
|
if( $stocklevel !== $this->getStocklevel() ) |
155
|
|
|
{ |
156
|
|
|
$this->values['stock.stocklevel'] = $stocklevel; |
157
|
|
|
$this->setModified(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Returns the back in stock date of the |
167
|
|
|
* |
168
|
|
|
* @return string|null Back in stock date of the product |
169
|
|
|
*/ |
170
|
|
|
public function getDateBack() |
171
|
|
|
{ |
172
|
|
|
if( isset( $this->values['stock.backdate'] ) ) { |
173
|
|
|
return (string) $this->values['stock.backdate']; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Sets the product back in stock date. |
180
|
|
|
* |
181
|
|
|
* @param string|null $backdate New back in stock date of the product |
182
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
183
|
|
|
*/ |
184
|
|
|
public function setDateBack( $backdate ) |
185
|
|
|
{ |
186
|
|
|
if( $backdate !== $this->getDateBack() ) |
187
|
|
|
{ |
188
|
|
|
$this->values['stock.backdate'] = $this->checkDateFormat( $backdate ); |
189
|
|
|
$this->setModified(); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Returns the item type |
199
|
|
|
* |
200
|
|
|
* @return string Item type, subtypes are separated by slashes |
201
|
|
|
*/ |
202
|
|
|
public function getResourceType() |
203
|
|
|
{ |
204
|
|
|
return 'stock'; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Sets the item values from the given array. |
210
|
|
|
* |
211
|
|
|
* @param array $list Associative list of item keys and their values |
212
|
|
|
* @return array Associative list of keys and their values that are unknown |
213
|
|
|
*/ |
214
|
|
|
public function fromArray( array $list ) |
215
|
|
|
{ |
216
|
|
|
$unknown = []; |
217
|
|
|
$list = parent::fromArray( $list ); |
218
|
|
|
|
219
|
|
|
foreach( $list as $key => $value ) |
220
|
|
|
{ |
221
|
|
|
switch( $key ) |
222
|
|
|
{ |
223
|
|
|
case 'stock.productcode': $this->setProductCode( $value ); break; |
224
|
|
|
case 'stock.stocklevel': $this->setStocklevel( $value ); break; |
225
|
|
|
case 'stock.dateback': $this->setDateBack( $value ); break; |
226
|
|
|
case 'stock.typeid': $this->setTypeId( $value ); break; |
227
|
|
|
default: $unknown[$key] = $value; |
|
|
|
|
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
return $unknown; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Returns the item values as array. |
237
|
|
|
* |
238
|
|
|
* @param boolean True to return private properties, false for public only |
239
|
|
|
* @return array Associative list of item properties and their values |
240
|
|
|
*/ |
241
|
|
|
public function toArray( $private = false ) |
242
|
|
|
{ |
243
|
|
|
$list = parent::toArray( $private ); |
244
|
|
|
|
245
|
|
|
$list['stock.productcode'] = $this->getProductCode(); |
246
|
|
|
$list['stock.stocklevel'] = $this->getStocklevel(); |
247
|
|
|
$list['stock.dateback'] = $this->getDateBack(); |
248
|
|
|
$list['stock.typename'] = $this->getTypeName(); |
249
|
|
|
$list['stock.type'] = $this->getType(); |
250
|
|
|
|
251
|
|
|
if( $private === true ) { |
252
|
|
|
$list['stock.typeid'] = $this->getTypeId(); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
return $list; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
} |