Passed
Push — master ( a045db...b8904b )
by Aimeos
04:49
created

Standard::getChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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-2021
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
	/**
106
	 * Returns the channel of the invoice (repeating, web, phone, etc).
107
	 *
108
	 * @return string Invoice channel
109
	 */
110
	public function getChannel() : string
111
	{
112
		return $this->get( 'order.channel', '' );
113
	}
114
115
116
	/**
117
	 * Sets the channel of the invoice.
118
	 *
119
	 * @param string $channel Invoice channel
120
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
121
	 */
122
	public function setChannel( string $channel ) : \Aimeos\MShop\Common\Item\Iface
123
	{
124
		return $this->set( 'order.channel', $this->checkCode( $channel ) );
125
	}
126
127
128
	/**
129
	 * Returns the delivery date of the invoice.
130
	 *
131
	 * @return string|null ISO date in yyyy-mm-dd HH:ii:ss format
132
	 */
133
	public function getDateDelivery() : ?string
134
	{
135
		$value = $this->get( 'order.datedelivery' );
136
		return $value ? substr( $value, 0, 19 ) : null;
137
	}
138
139
140
	/**
141
	 * Sets the delivery date of the invoice.
142
	 *
143
	 * @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format
144
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
145
	 */
146
	public function setDateDelivery( ?string $date ) : \Aimeos\MShop\Order\Item\Iface
147
	{
148
		return $this->set( 'order.datedelivery', $this->checkDateFormat( $date ) );
149
	}
150
151
152
	/**
153
	 * Returns the purchase date of the invoice.
154
	 *
155
	 * @return string|null ISO date in yyyy-mm-dd HH:ii:ss format
156
	 */
157
	public function getDatePayment() : ?string
158
	{
159
		$value = $this->get( 'order.datepayment' );
160
		return $value ? substr( $value, 0, 19 ) : null;
161
	}
162
163
164
	/**
165
	 * Sets the purchase date of the invoice.
166
	 *
167
	 * @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format
168
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
169
	 */
170
	public function setDatePayment( ?string $date ) : \Aimeos\MShop\Order\Item\Iface
171
	{
172
		return $this->set( 'order.datepayment', $this->checkDateFormat( $date ) );
173
	}
174
175
176
	/**
177
	 * Returns the delivery status of the invoice.
178
	 *
179
	 * @return int Status code constant from \Aimeos\MShop\Order\Item\Base
180
	 */
181
	public function getStatusDelivery() : ?int
182
	{
183
		return $this->get( 'order.statusdelivery' );
184
	}
185
186
187
	/**
188
	 * @deprecated 2022.01
189
	 */
190
	public function getDeliveryStatus() : ?int
191
	{
192
		return $this->getStatusDelivery();
193
	}
194
195
196
	/**
197
	 * Sets the delivery status of the invoice.
198
	 *
199
	 * @param int|null $status Status code constant from \Aimeos\MShop\Order\Item\Base
200
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
201
	 */
202
	public function setStatusDelivery( ?int $status ) : \Aimeos\MShop\Order\Item\Iface
203
	{
204
		if( $status !== null ) {
205
			$this->set( '.statusdelivery', $this->get( 'order.statusdelivery' ) );
206
		}
207
208
		return $this->set( 'order.statusdelivery', $status );
209
	}
210
211
212
	/**
213
	 * @deprecated 2022.01
214
	 */
215
	public function setDeliveryStatus( ?int $status ) : \Aimeos\MShop\Order\Item\Iface
216
	{
217
		return $this->setStatusDelivery( $status );
218
	}
219
220
221
	/**
222
	 * Returns the payment status of the invoice.
223
	 *
224
	 * @return int Payment constant from \Aimeos\MShop\Order\Item\Base
225
	 */
226
	public function getStatusPayment() : ?int
227
	{
228
		return $this->get( 'order.statuspayment' );
229
	}
230
231
232
	/**
233
	 * @deprecated 2022.01
234
	 */
235
	public function getPaymentStatus() : ?int
236
	{
237
		return $this->getStatusPayment();
238
	}
239
240
241
	/**
242
	 * Sets the payment status of the invoice.
243
	 *
244
	 * @param int|null $status Payment constant from \Aimeos\MShop\Order\Item\Base
245
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
246
	 */
247
	public function setStatusPayment( ?int $status ) : \Aimeos\MShop\Order\Item\Iface
248
	{
249
		if( $status !== $this->getStatusPayment() ) {
250
			$this->set( 'order.datepayment', date( 'Y-m-d H:i:s' ) );
251
		}
252
253
		if( $status !== null ) {
254
			$this->set( '.statuspayment', $this->get( 'order.statuspayment' ) );
255
		}
256
257
		return $this->set( 'order.statuspayment', $status );
258
	}
259
260
261
	/**
262
	 * @deprecated 2022.01
263
	 */
264
	public function setPaymentStatus( ?int $status ) : \Aimeos\MShop\Order\Item\Iface
265
	{
266
		return $this->setStatusPayment( $status );
267
	}
268
269
270
	/**
271
	 * Returns the related invoice ID.
272
	 *
273
	 * @return string Related invoice ID
274
	 */
275
	public function getRelatedId() : string
276
	{
277
		return $this->get( 'order.relatedid', '' );
278
	}
279
280
281
	/**
282
	 * Sets the related invoice ID.
283
	 *
284
	 * @param string|null $id Related invoice ID
285
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
286
	 * @throws \Aimeos\MShop\Order\Exception If ID is invalid
287
	 */
288
	public function setRelatedId( ?string $id ) : \Aimeos\MShop\Order\Item\Iface
289
	{
290
		return $this->set( 'order.relatedid', (string) $id );
291
	}
292
293
294
	/*
295
	 * Sets the item values from the given array and removes that entries from the list
296
	 *
297
	 * @param array &$list Associative list of item keys and their values
298
	 * @param bool True to set private properties too, false for public only
299
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
300
	 */
301
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
302
	{
303
		$item = parent::fromArray( $list, $private );
304
305
		foreach( $list as $key => $value )
306
		{
307
			switch( $key )
308
			{
309
				case 'order.channel': $item = $item->setChannel( $value ); break;
0 ignored issues
show
Bug introduced by
The method setChannel() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

309
				case 'order.channel': /** @scrutinizer ignore-call */ $item = $item->setChannel( $value ); break;
Loading history...
310
				case 'order.baseid': !$private ?: $item = $item->setBaseId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setBaseId() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

310
				case 'order.baseid': !$private ?: $item = $item->/** @scrutinizer ignore-call */ setBaseId( $value ); break;
Loading history...
311
				case 'order.statusdelivery': $item = $item->setStatusDelivery( is_numeric( $value ) ? (int) $value : null ); break;
0 ignored issues
show
Bug introduced by
The method setStatusDelivery() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

311
				case 'order.statusdelivery': /** @scrutinizer ignore-call */ $item = $item->setStatusDelivery( is_numeric( $value ) ? (int) $value : null ); break;
Loading history...
312
				case 'order.statuspayment': $item = $item->setStatusPayment( is_numeric( $value ) ? (int) $value : null ); break;
0 ignored issues
show
Bug introduced by
The method setStatusPayment() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

312
				case 'order.statuspayment': /** @scrutinizer ignore-call */ $item = $item->setStatusPayment( is_numeric( $value ) ? (int) $value : null ); break;
Loading history...
313
				case 'order.datedelivery': $item = $item->setDateDelivery( $value ); break;
0 ignored issues
show
Bug introduced by
The method setDateDelivery() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

313
				case 'order.datedelivery': /** @scrutinizer ignore-call */ $item = $item->setDateDelivery( $value ); break;
Loading history...
314
				case 'order.datepayment': $item = $item->setDatePayment( $value ); break;
0 ignored issues
show
Bug introduced by
The method setDatePayment() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

314
				case 'order.datepayment': /** @scrutinizer ignore-call */ $item = $item->setDatePayment( $value ); break;
Loading history...
315
				case 'order.relatedid': $item = $item->setRelatedId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setRelatedId() does not exist on Aimeos\MShop\Order\Item\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

315
				case 'order.relatedid': /** @scrutinizer ignore-call */ $item = $item->setRelatedId( $value ); break;
Loading history...
316
				default: continue 2;
317
			}
318
319
			unset( $list[$key] );
320
		}
321
322
		return $item;
323
	}
324
325
326
	/**
327
	 * Returns the item values as array.
328
	 *
329
	 * @param bool True to return private properties, false for public only
330
	 * @return array Associative list of item properties and their values
331
	 */
332
	public function toArray( bool $private = false ) : array
333
	{
334
		$list = parent::toArray( $private );
335
336
		$list['order.channel'] = $this->getChannel();
337
		$list['order.statusdelivery'] = $this->getStatusDelivery();
338
		$list['order.statuspayment'] = $this->getStatusPayment();
339
		$list['order.datedelivery'] = $this->getDateDelivery();
340
		$list['order.datepayment'] = $this->getDatePayment();
341
		$list['order.relatedid'] = $this->getRelatedId();
342
343
		if( $private === true ) {
344
			$list['order.baseid'] = $this->getBaseId();
345
		}
346
347
		return $list;
348
	}
349
}
350