|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
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
|
|
|
/** |
|
26
|
|
|
* Returns the back in stock date of the |
|
27
|
|
|
* |
|
28
|
|
|
* @return string|null Back in stock date of the product |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getDateBack() : ?string |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->get( 'stock.dateback' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Sets the product back in stock date. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string|null $dateback New back in stock date of the product |
|
40
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setDateBack( ?string $dateback ) : \Aimeos\MShop\Stock\Item\Iface |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->set( 'stock.dateback', $this->checkDateFormat( $dateback ) ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns the type code of the product stock item. |
|
50
|
|
|
* |
|
51
|
|
|
* @return string Type code of the product stock item |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getType() : string |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->get( 'stock.type', 'default' ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Sets the new type of the product stock item |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $type Type of the product stock item |
|
63
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->set( 'stock.type', $this->checkCode( $type ) ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns the ID of the product the stock item belongs to. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string Product ID |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getProductId() : string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->get( 'stock.productid', '' ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Sets a new product ID the stock item belongs to. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $value New product ID |
|
86
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setProductId( string $value ) : \Aimeos\MShop\Stock\Item\Iface |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->set( 'stock.productid', $value ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Returns the stock level. |
|
96
|
|
|
* |
|
97
|
|
|
* @return int|null Stock level |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getStockLevel() : ?int |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->get( 'stock.stocklevel' ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Sets the stock level. |
|
107
|
|
|
* |
|
108
|
|
|
* @param int|null $stocklevel New stock level |
|
109
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
|
110
|
|
|
*/ |
|
111
|
|
|
public function setStockLevel( $stocklevel = null ) : \Aimeos\MShop\Stock\Item\Iface |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->set( 'stock.stocklevel', is_numeric( $stocklevel ) ? (int) $stocklevel : null ); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Returns the expected delivery time frame |
|
119
|
|
|
* |
|
120
|
|
|
* @return string Expected delivery time frame |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getTimeframe() : string |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->get( 'stock.timeframe', '' ); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Sets the expected delivery time frame |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $timeframe Expected delivery time frame |
|
132
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock stock item for chaining method calls |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setTimeframe( ?string $timeframe ) : \Aimeos\MShop\Stock\Item\Iface |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->set( 'stock.timeframe', (string) $timeframe ); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
142
|
|
|
* |
|
143
|
|
|
* @param array &$list Associative list of item keys and their values |
|
144
|
|
|
* @param bool True to set private properties too, false for public only |
|
145
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item for chaining method calls |
|
146
|
|
|
*/ |
|
147
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
148
|
|
|
{ |
|
149
|
|
|
$item = parent::fromArray( $list, $private ); |
|
150
|
|
|
|
|
151
|
|
|
foreach( $list as $key => $value ) |
|
152
|
|
|
{ |
|
153
|
|
|
switch( $key ) |
|
154
|
|
|
{ |
|
155
|
|
|
case 'stock.productid': $item = $item->setProductId( $value ); break; |
|
156
|
|
|
case 'stock.stocklevel': $item = $item->setStockLevel( $value ); break; |
|
157
|
|
|
case 'stock.timeframe': $item = $item->setTimeFrame( $value ); break; |
|
158
|
|
|
case 'stock.dateback': $item = $item->setDateBack( $value ); break; |
|
159
|
|
|
case 'stock.type': $item = $item->setType( $value ); break; |
|
160
|
|
|
default: continue 2; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
unset( $list[$key] ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
return $item; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Returns the item values as array. |
|
172
|
|
|
* |
|
173
|
|
|
* @param bool True to return private properties, false for public only |
|
174
|
|
|
* @return array Associative list of item properties and their values |
|
175
|
|
|
*/ |
|
176
|
|
|
public function toArray( bool $private = false ) : array |
|
177
|
|
|
{ |
|
178
|
|
|
$list = parent::toArray( $private ); |
|
179
|
|
|
|
|
180
|
|
|
$list['stock.productid'] = $this->getProductId(); |
|
181
|
|
|
$list['stock.stocklevel'] = $this->getStockLevel(); |
|
182
|
|
|
$list['stock.timeframe'] = $this->getTimeFrame(); |
|
183
|
|
|
$list['stock.dateback'] = $this->getDateBack(); |
|
184
|
|
|
$list['stock.type'] = $this->getType(); |
|
185
|
|
|
|
|
186
|
|
|
return $list; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|