This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
forked from aimeos/aimeos-core
/
Default.php
192 lines (154 loc) · 3.98 KB
/
Default.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2011
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @package MShop
* @subpackage Product
*/
/**
* Default product stock item implementation.
*
* @package MShop
* @subpackage Product
*/
class MShop_Product_Item_Stock_Default
extends MShop_Common_Item_Abstract
implements MShop_Product_Item_Stock_Interface
{
private $_values;
/**
* Initializes the stock item object with the given values
*/
public function __construct( array $values = array( ) )
{
parent::__construct( 'product.stock.', $values );
$this->_values = $values;
}
/**
* Returns the product Id.
*
* @return integer Product Id
*/
public function getProductId()
{
return ( isset( $this->_values['prodid'] ) ? (int) $this->_values['prodid'] : null );
}
/**
* Sets the Product Id.
*
* @param integer $prodid New product Id
*/
public function setProductId( $prodid )
{
if( $prodid == $this->getProductId() ) { return; }
$this->_values['prodid'] = (int) $prodid;
$this->setModified();
}
/**
* Returns the warehouse Id.
*
* @return integer Warehouse Id
*/
public function getWarehouseId()
{
return ( isset( $this->_values['warehouseid'] ) ? (int) $this->_values['warehouseid'] : null );
}
/**
* Sets the warehouse Id.
*
* @param integer|null $warehouseid New warehouse Id
*/
public function setWarehouseId( $warehouseid )
{
if( $warehouseid === $this->getWarehouseId() ) { return; }
if( $warehouseid !== null ) {
$warehouseid = (int) $warehouseid;
}
$this->_values['warehouseid'] = $warehouseid;
$this->setModified();
}
/**
* Returns the stock level.
*
* @return integer Stock level
*/
public function getStocklevel()
{
return ( isset( $this->_values['stocklevel'] ) ? (int) $this->_values['stocklevel'] : null );
}
/**
* Sets the stock level.
*
* @param integer|null $stocklevel New stock level
*/
public function setStocklevel( $stocklevel )
{
if( $stocklevel === $this->getStocklevel() ) { return; }
if( $stocklevel !== null ) {
$stocklevel = (int) $stocklevel;
}
$this->_values['stocklevel'] = $stocklevel;
$this->setModified();
}
/**
* Returns the back in stock date of the product.
*
* @return string Back in stock date of the product
*/
public function getDateBack()
{
return ( isset( $this->_values['backdate'] ) ? (string) $this->_values['backdate'] : null );
}
/**
* Sets the product back in stock date.
*
* @param string|null $backdate New back in stock date of the product
*/
public function setDateBack( $backdate )
{
if( $backdate === $this->getDateBack() ) { return; }
$this->_checkDateFormat( $backdate );
if( $backdate !== null ) {
$backdate = (string) $backdate;
}
$this->_values['backdate'] = $backdate;
$this->setModified();
}
/**
* Sets the item values from the given array.
*
* @param array $list Associative list of item keys and their values
* @return array Associative list of keys and their values that are unknown
*/
public function fromArray( array $list )
{
$unknown = array();
$list = parent::fromArray( $list );
foreach( $list as $key => $value )
{
switch( $key )
{
case 'product.stock.productid': $this->setProductId( $value ); break;
case 'product.stock.warehouseid': $this->setWarehouseId( $value ); break;
case 'product.stock.stocklevel': $this->setStocklevel( $value ); break;
case 'product.stock.dateback': $this->setDateBack( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
/**
* Returns the item values as array.
*
* @return Associative list of item properties and their values
*/
public function toArray()
{
$list = parent::toArray();
$list['product.stock.productid'] = $this->getProductId();
$list['product.stock.warehouseid'] = $this->getWarehouseId();
$list['product.stock.stocklevel'] = $this->getStocklevel();
$list['product.stock.dateback'] = $this->getDateBack();
return $list;
}
}