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-2022 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Order |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Order\Item; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation of an order invoice item. |
17
|
|
|
* |
18
|
|
|
* @property int oldPaymentStatus Last delivery status before it was changed by setDeliveryStatus() |
19
|
|
|
* @property int oldDeliveryStatus Last payment status before it was changed by setPaymentStatus() |
20
|
|
|
* |
21
|
|
|
* @package MShop |
22
|
|
|
* @subpackage Order |
23
|
|
|
*/ |
24
|
|
|
class Standard |
25
|
|
|
extends \Aimeos\MShop\Order\Item\Base |
26
|
|
|
implements \Aimeos\MShop\Order\Item\Iface |
27
|
|
|
{ |
28
|
|
|
private $baseItem; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initializes the object with the given values. |
33
|
|
|
* |
34
|
|
|
* @param array $values Associative list of values from database |
35
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface|null $baseItem Order basket if available |
36
|
|
|
*/ |
37
|
|
|
public function __construct( array $values = [], ?\Aimeos\MShop\Order\Item\Base\Iface $baseItem = null ) |
38
|
|
|
{ |
39
|
|
|
parent::__construct( 'order.', $values ); |
40
|
|
|
$this->baseItem = $baseItem; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the order number |
46
|
|
|
* |
47
|
|
|
* @return string Order number |
48
|
|
|
*/ |
49
|
|
|
public function getOrderNumber() : string |
50
|
|
|
{ |
51
|
|
|
if( $fcn = self::macro( 'ordernumber' ) ) { |
52
|
|
|
return (string) $fcn( $this ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return (string) $this->getId(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the associated order base item |
61
|
|
|
* |
62
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface|null Order base item |
63
|
|
|
*/ |
64
|
|
|
public function getBaseItem() : ?\Aimeos\MShop\Order\Item\Base\Iface |
65
|
|
|
{ |
66
|
|
|
return $this->baseItem; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Sets the associated order base item |
72
|
|
|
* |
73
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Order base item |
74
|
|
|
*/ |
75
|
|
|
public function setBaseItem( \Aimeos\MShop\Order\Item\Base\Iface $baseItem ) : \Aimeos\MShop\Order\Item\Iface |
76
|
|
|
{ |
77
|
|
|
$this->baseItem = $baseItem; |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the basic order ID. |
84
|
|
|
* |
85
|
|
|
* @return string|null Basic order ID |
86
|
|
|
*/ |
87
|
|
|
public function getBaseId() : ?string |
88
|
|
|
{ |
89
|
|
|
return $this->get( 'order.baseid' ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Sets the ID of the basic order item which contains the order details. |
95
|
|
|
* |
96
|
|
|
* @param string $id ID of the basic order item |
97
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
98
|
|
|
*/ |
99
|
|
|
public function setBaseId( string $id ) : \Aimeos\MShop\Order\Item\Iface |
100
|
|
|
{ |
101
|
|
|
return $this->set( 'order.baseid', $id ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the number of the invoice. |
106
|
|
|
* |
107
|
|
|
* @return string Invoice number |
108
|
|
|
*/ |
109
|
|
|
public function getInvoiceNumber() : string |
110
|
|
|
{ |
111
|
|
|
return $this->get( 'order.invoiceno', '' ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Sets the number of the invoice. |
117
|
|
|
* |
118
|
|
|
* @param string $value Invoice number |
119
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
120
|
|
|
*/ |
121
|
|
|
public function setInvoiceNumber( string $value ) : \Aimeos\MShop\Common\Item\Iface |
122
|
|
|
{ |
123
|
|
|
return $this->set( 'order.invoiceno', $value ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns the channel of the invoice (repeating, web, phone, etc). |
129
|
|
|
* |
130
|
|
|
* @return string Invoice channel |
131
|
|
|
*/ |
132
|
|
|
public function getChannel() : string |
133
|
|
|
{ |
134
|
|
|
return $this->get( 'order.channel', '' ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Sets the channel of the invoice. |
140
|
|
|
* |
141
|
|
|
* @param string $channel Invoice channel |
142
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
143
|
|
|
*/ |
144
|
|
|
public function setChannel( string $channel ) : \Aimeos\MShop\Common\Item\Iface |
145
|
|
|
{ |
146
|
|
|
return $this->set( 'order.channel', $this->checkCode( $channel ) ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Returns the delivery date of the invoice. |
152
|
|
|
* |
153
|
|
|
* @return string|null ISO date in yyyy-mm-dd HH:ii:ss format |
154
|
|
|
*/ |
155
|
|
|
public function getDateDelivery() : ?string |
156
|
|
|
{ |
157
|
|
|
$value = $this->get( 'order.datedelivery' ); |
158
|
|
|
return $value ? substr( $value, 0, 19 ) : null; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Sets the delivery date of the invoice. |
164
|
|
|
* |
165
|
|
|
* @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format |
166
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
167
|
|
|
*/ |
168
|
|
|
public function setDateDelivery( ?string $date ) : \Aimeos\MShop\Order\Item\Iface |
169
|
|
|
{ |
170
|
|
|
return $this->set( 'order.datedelivery', $this->checkDateFormat( $date ) ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Returns the purchase date of the invoice. |
176
|
|
|
* |
177
|
|
|
* @return string|null ISO date in yyyy-mm-dd HH:ii:ss format |
178
|
|
|
*/ |
179
|
|
|
public function getDatePayment() : ?string |
180
|
|
|
{ |
181
|
|
|
$value = $this->get( 'order.datepayment' ); |
182
|
|
|
return $value ? substr( $value, 0, 19 ) : null; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Sets the purchase date of the invoice. |
188
|
|
|
* |
189
|
|
|
* @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format |
190
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
191
|
|
|
*/ |
192
|
|
|
public function setDatePayment( ?string $date ) : \Aimeos\MShop\Order\Item\Iface |
193
|
|
|
{ |
194
|
|
|
return $this->set( 'order.datepayment', $this->checkDateFormat( $date ) ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Returns the delivery status of the invoice. |
200
|
|
|
* |
201
|
|
|
* @return int Status code constant from \Aimeos\MShop\Order\Item\Base |
202
|
|
|
*/ |
203
|
|
|
public function getStatusDelivery() : int |
204
|
|
|
{ |
205
|
|
|
return $this->get( 'order.statusdelivery', -1 ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Sets the delivery status of the invoice. |
211
|
|
|
* |
212
|
|
|
* @param int $status Status code constant from \Aimeos\MShop\Order\Item\Base |
213
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
214
|
|
|
*/ |
215
|
|
|
public function setStatusDelivery( int $status ) : \Aimeos\MShop\Order\Item\Iface |
216
|
|
|
{ |
217
|
|
|
$this->set( '.statusdelivery', $this->get( 'order.statusdelivery' ) ); |
218
|
|
|
return $this->set( 'order.statusdelivery', $status ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Returns the payment status of the invoice. |
224
|
|
|
* |
225
|
|
|
* @return int Payment constant from \Aimeos\MShop\Order\Item\Base |
226
|
|
|
*/ |
227
|
|
|
public function getStatusPayment() : int |
228
|
|
|
{ |
229
|
|
|
return $this->get( 'order.statuspayment', -1 ); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Sets the payment status of the invoice. |
235
|
|
|
* |
236
|
|
|
* @param int $status Payment constant from \Aimeos\MShop\Order\Item\Base |
237
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
238
|
|
|
*/ |
239
|
|
|
public function setStatusPayment( int $status ) : \Aimeos\MShop\Order\Item\Iface |
240
|
|
|
{ |
241
|
|
|
if( $status !== $this->getStatusPayment() ) { |
242
|
|
|
$this->set( 'order.datepayment', date( 'Y-m-d H:i:s' ) ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$this->set( '.statuspayment', $this->get( 'order.statuspayment' ) ); |
246
|
|
|
return $this->set( 'order.statuspayment', $status ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Returns the related invoice ID. |
252
|
|
|
* |
253
|
|
|
* @return string Related invoice ID |
254
|
|
|
*/ |
255
|
|
|
public function getRelatedId() : string |
256
|
|
|
{ |
257
|
|
|
return $this->get( 'order.relatedid', '' ); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Sets the related invoice ID. |
263
|
|
|
* |
264
|
|
|
* @param string|null $id Related invoice ID |
265
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
266
|
|
|
* @throws \Aimeos\MShop\Order\Exception If ID is invalid |
267
|
|
|
*/ |
268
|
|
|
public function setRelatedId( ?string $id ) : \Aimeos\MShop\Order\Item\Iface |
269
|
|
|
{ |
270
|
|
|
return $this->set( 'order.relatedid', (string) $id ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
/* |
275
|
|
|
* Sets the item values from the given array and removes that entries from the list |
276
|
|
|
* |
277
|
|
|
* @param array &$list Associative list of item keys and their values |
278
|
|
|
* @param bool True to set private properties too, false for public only |
279
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
280
|
|
|
*/ |
281
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
282
|
|
|
{ |
283
|
|
|
$item = parent::fromArray( $list, $private ); |
284
|
|
|
|
285
|
|
|
foreach( $list as $key => $value ) |
286
|
|
|
{ |
287
|
|
|
switch( $key ) |
288
|
|
|
{ |
289
|
|
|
case 'order.channel': $item = $item->setChannel( $value ); break; |
|
|
|
|
290
|
|
|
case 'order.baseid': !$private ?: $item = $item->setBaseId( $value ); break; |
|
|
|
|
291
|
|
|
case 'order.invoiceno': !$private ?: $item = $item->setInvoiceNumber( $value ); break; |
|
|
|
|
292
|
|
|
case 'order.statusdelivery': $item = $item->setStatusDelivery( (int) $value ); break; |
|
|
|
|
293
|
|
|
case 'order.statuspayment': $item = $item->setStatusPayment( (int) $value ); break; |
|
|
|
|
294
|
|
|
case 'order.datedelivery': $item = $item->setDateDelivery( $value ); break; |
|
|
|
|
295
|
|
|
case 'order.datepayment': $item = $item->setDatePayment( $value ); break; |
|
|
|
|
296
|
|
|
case 'order.relatedid': $item = $item->setRelatedId( $value ); break; |
|
|
|
|
297
|
|
|
default: continue 2; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
unset( $list[$key] ); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
return $item; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Returns the item values as array. |
309
|
|
|
* |
310
|
|
|
* @param bool True to return private properties, false for public only |
311
|
|
|
* @return array Associative list of item properties and their values |
312
|
|
|
*/ |
313
|
|
|
public function toArray( bool $private = false ) : array |
314
|
|
|
{ |
315
|
|
|
$list = parent::toArray( $private ); |
316
|
|
|
|
317
|
|
|
$list['order.channel'] = $this->getChannel(); |
318
|
|
|
$list['order.invoiceno'] = $this->getInvoiceNumber(); |
319
|
|
|
$list['order.statusdelivery'] = $this->getStatusDelivery(); |
320
|
|
|
$list['order.statuspayment'] = $this->getStatusPayment(); |
321
|
|
|
$list['order.datedelivery'] = $this->getDateDelivery(); |
322
|
|
|
$list['order.datepayment'] = $this->getDatePayment(); |
323
|
|
|
$list['order.relatedid'] = $this->getRelatedId(); |
324
|
|
|
|
325
|
|
|
if( $private === true ) { |
326
|
|
|
$list['order.baseid'] = $this->getBaseId(); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return $list; |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|