Passed
Push — master ( 521642...f94b4e )
by Aimeos
05:37
created

Standard::setDeliveryStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
	/**
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
	 * Sets the delivery status of the invoice.
189
	 *
190
	 * @param int|null $status Status code constant from \Aimeos\MShop\Order\Item\Base
191
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
192
	 */
193
	public function setStatusDelivery( ?int $status ) : \Aimeos\MShop\Order\Item\Iface
194
	{
195
		if( $status !== null ) {
196
			$this->set( '.statusdelivery', $this->get( 'order.statusdelivery' ) );
197
		}
198
199
		return $this->set( 'order.statusdelivery', $status );
200
	}
201
202
203
	/**
204
	 * Returns the payment status of the invoice.
205
	 *
206
	 * @return int Payment constant from \Aimeos\MShop\Order\Item\Base
207
	 */
208
	public function getStatusPayment() : ?int
209
	{
210
		return $this->get( 'order.statuspayment' );
211
	}
212
213
214
	/**
215
	 * Sets the payment status of the invoice.
216
	 *
217
	 * @param int|null $status Payment constant from \Aimeos\MShop\Order\Item\Base
218
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
219
	 */
220
	public function setStatusPayment( ?int $status ) : \Aimeos\MShop\Order\Item\Iface
221
	{
222
		if( $status !== $this->getStatusPayment() ) {
223
			$this->set( 'order.datepayment', date( 'Y-m-d H:i:s' ) );
224
		}
225
226
		if( $status !== null ) {
227
			$this->set( '.statuspayment', $this->get( 'order.statuspayment' ) );
228
		}
229
230
		return $this->set( 'order.statuspayment', $status );
231
	}
232
233
234
	/**
235
	 * Returns the related invoice ID.
236
	 *
237
	 * @return string Related invoice ID
238
	 */
239
	public function getRelatedId() : string
240
	{
241
		return $this->get( 'order.relatedid', '' );
242
	}
243
244
245
	/**
246
	 * Sets the related invoice ID.
247
	 *
248
	 * @param string|null $id Related invoice ID
249
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
250
	 * @throws \Aimeos\MShop\Order\Exception If ID is invalid
251
	 */
252
	public function setRelatedId( ?string $id ) : \Aimeos\MShop\Order\Item\Iface
253
	{
254
		return $this->set( 'order.relatedid', (string) $id );
255
	}
256
257
258
	/*
259
	 * Sets the item values from the given array and removes that entries from the list
260
	 *
261
	 * @param array &$list Associative list of item keys and their values
262
	 * @param bool True to set private properties too, false for public only
263
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
264
	 */
265
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
266
	{
267
		$item = parent::fromArray( $list, $private );
268
269
		foreach( $list as $key => $value )
270
		{
271
			switch( $key )
272
			{
273
				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

273
				case 'order.channel': /** @scrutinizer ignore-call */ $item = $item->setChannel( $value ); break;
Loading history...
274
				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

274
				case 'order.baseid': !$private ?: $item = $item->/** @scrutinizer ignore-call */ setBaseId( $value ); break;
Loading history...
275
				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

275
				case 'order.statusdelivery': /** @scrutinizer ignore-call */ $item = $item->setStatusDelivery( is_numeric( $value ) ? (int) $value : null ); break;
Loading history...
276
				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

276
				case 'order.statuspayment': /** @scrutinizer ignore-call */ $item = $item->setStatusPayment( is_numeric( $value ) ? (int) $value : null ); break;
Loading history...
277
				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

277
				case 'order.datedelivery': /** @scrutinizer ignore-call */ $item = $item->setDateDelivery( $value ); break;
Loading history...
278
				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

278
				case 'order.datepayment': /** @scrutinizer ignore-call */ $item = $item->setDatePayment( $value ); break;
Loading history...
279
				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

279
				case 'order.relatedid': /** @scrutinizer ignore-call */ $item = $item->setRelatedId( $value ); break;
Loading history...
280
				default: continue 2;
281
			}
282
283
			unset( $list[$key] );
284
		}
285
286
		return $item;
287
	}
288
289
290
	/**
291
	 * Returns the item values as array.
292
	 *
293
	 * @param bool True to return private properties, false for public only
294
	 * @return array Associative list of item properties and their values
295
	 */
296
	public function toArray( bool $private = false ) : array
297
	{
298
		$list = parent::toArray( $private );
299
300
		$list['order.channel'] = $this->getChannel();
301
		$list['order.statusdelivery'] = $this->getStatusDelivery();
302
		$list['order.statuspayment'] = $this->getStatusPayment();
303
		$list['order.datedelivery'] = $this->getDateDelivery();
304
		$list['order.datepayment'] = $this->getDatePayment();
305
		$list['order.relatedid'] = $this->getRelatedId();
306
307
		if( $private === true ) {
308
			$list['order.baseid'] = $this->getBaseId();
309
		}
310
311
		return $list;
312
	}
313
}
314