|
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\Service; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Default implementation for order item base service. |
|
17
|
|
|
* |
|
18
|
|
|
* @package MShop |
|
19
|
|
|
* @subpackage Order |
|
20
|
|
|
*/ |
|
21
|
|
|
class Standard extends Base implements Iface |
|
22
|
|
|
{ |
|
23
|
|
|
private $serviceItem; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initializes the order base service item |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Aimeos\MShop\Price\Item\Iface $price Price object |
|
30
|
|
|
* @param array $values Values to be set on initialisation |
|
31
|
|
|
* @param array $attributes Attributes to be set on initialisation |
|
32
|
|
|
* @param \Aimeos\MShop\Service\Item\Iface|null $serviceItem Service item |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( \Aimeos\MShop\Price\Item\Iface $price, array $values = [], array $attributes = [], |
|
35
|
|
|
array $transactions = [], ?\Aimeos\MShop\Service\Item\Iface $serviceItem = null ) |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct( $price, $values, $attributes, $transactions ); |
|
38
|
|
|
|
|
39
|
|
|
$this->serviceItem = $serviceItem; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Returns the associated service item |
|
45
|
|
|
* |
|
46
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface|null Service item |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getServiceItem() : ?\Aimeos\MShop\Service\Item\Iface |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->serviceItem; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns the ID of the site the item is stored |
|
56
|
|
|
* |
|
57
|
|
|
* @return string Site ID (or null if not available) |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getSiteId() : string |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->get( 'order.service.siteid', '' ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Sets the site ID of the item. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $value Unique site ID of the item |
|
69
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setSiteId( string $value ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->set( 'order.service.siteid', $value ); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the order base ID of the order service if available. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string|null Base ID of the item. |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getParentId() : ?string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->get( 'order.service.parentid' ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Sets the order service base ID of the order service item. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string|null $value Order service base ID |
|
92
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
93
|
|
|
*/ |
|
94
|
|
|
public function setParentId( ?string $value ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->set( 'order.service.parentid', $value ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Returns the original ID of the service item used for the order. |
|
102
|
|
|
* |
|
103
|
|
|
* @return string Original service ID |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getServiceId() : string |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->get( 'order.service.serviceid', '' ); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Sets a new ID of the service item used for the order. |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $servid ID of the service item used for the order |
|
115
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
116
|
|
|
*/ |
|
117
|
|
|
public function setServiceId( string $servid ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->set( 'order.service.serviceid', $servid ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Returns the code of the service item. |
|
125
|
|
|
* |
|
126
|
|
|
* @return string Service item code |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getCode() : string |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->get( 'order.service.code', '' ); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Sets a new code for the service item. |
|
136
|
|
|
* |
|
137
|
|
|
* @param string $code Code as defined by the service provider |
|
138
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setCode( string $code ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->set( 'order.service.code', $this->checkCode( $code ) ); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Returns the name of the service item. |
|
148
|
|
|
* |
|
149
|
|
|
* @return string Service item name |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getName() : string |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->get( 'order.service.name', '' ); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Sets a new name for the service item. |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $name service item name |
|
161
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setName( string $name ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->set( 'order.service.name', $name ); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns the type of the service item. |
|
171
|
|
|
* |
|
172
|
|
|
* @return string service item type |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getType() : string |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->get( 'order.service.type', '' ); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Sets a new type for the service item. |
|
182
|
|
|
* |
|
183
|
|
|
* @param string $type Type of the service item |
|
184
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->set( 'order.service.type', $this->checkCode( $type ) ); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Returns the location of the media. |
|
194
|
|
|
* |
|
195
|
|
|
* @return string Location of the media |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getMediaUrl() : string |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->get( 'order.service.mediaurl', '' ); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Sets the media url of the service item. |
|
205
|
|
|
* |
|
206
|
|
|
* @param string $value Location of the media/picture |
|
207
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
208
|
|
|
*/ |
|
209
|
|
|
public function setMediaUrl( string $value ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->set( 'order.service.mediaurl', $value ); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Returns the position of the service in the order. |
|
217
|
|
|
* |
|
218
|
|
|
* @return int|null Service position in the order from 0-n |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getPosition() : ?int |
|
221
|
|
|
{ |
|
222
|
|
|
if( ( $result = $this->get( 'order.service.position' ) ) !== null ) { |
|
223
|
|
|
return $result; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
return null; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Sets the position of the service within the list of ordered servicees |
|
232
|
|
|
* |
|
233
|
|
|
* @param int|null $value Service position in the order from 0-n or null for resetting the position |
|
234
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
235
|
|
|
* @throws \Aimeos\MShop\Order\Exception If the position is invalid |
|
236
|
|
|
*/ |
|
237
|
|
|
public function setPosition( ?int $value ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
238
|
|
|
{ |
|
239
|
|
|
if( $value < 0 ) { |
|
240
|
|
|
throw new \Aimeos\MShop\Order\Exception( sprintf( 'Order service position "%1$s" must be greater than 0', $value ) ); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
return $this->set( 'order.service.position', $value ); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
249
|
|
|
* |
|
250
|
|
|
* @param array &$list Associative list of item keys and their values |
|
251
|
|
|
* @param bool True to set private properties too, false for public only |
|
252
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order service item for chaining method calls |
|
253
|
|
|
*/ |
|
254
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
255
|
|
|
{ |
|
256
|
|
|
$price = $this->getPrice(); |
|
257
|
|
|
$item = parent::fromArray( $list, $private ); |
|
258
|
|
|
|
|
259
|
|
|
foreach( $list as $key => $value ) |
|
260
|
|
|
{ |
|
261
|
|
|
switch( $key ) |
|
262
|
|
|
{ |
|
263
|
|
|
case 'order.service.siteid': !$private ?: $item = $item->setSiteId( $value ); break; |
|
264
|
|
|
case 'order.service.parentid': !$private ?: $item = $item->setParentId( $value ); break; |
|
265
|
|
|
case 'order.service.serviceid': !$private ?: $item = $item->setServiceId( $value ); break; |
|
266
|
|
|
case 'order.service.type': $item = $item->setType( $value ); break; |
|
267
|
|
|
case 'order.service.code': $item = $item->setCode( $value ); break; |
|
268
|
|
|
case 'order.service.name': $item = $item->setName( $value ); break; |
|
269
|
|
|
case 'order.service.currencyid': $price = $price->setCurrencyId( $value ); break; |
|
270
|
|
|
case 'order.service.price': $price = $price->setValue( $value ); break; |
|
271
|
|
|
case 'order.service.costs': $price = $price->setCosts( $value ); break; |
|
272
|
|
|
case 'order.service.rebate': $price = $price->setRebate( $value ); break; |
|
273
|
|
|
case 'order.service.taxrates': $price = $price->setTaxRates( $value ); break; |
|
274
|
|
|
case 'order.service.taxvalue': $price = $price->setTaxValue( $value ); break; |
|
275
|
|
|
case 'order.service.taxflag': $price = $price->setTaxFlag( $value ); break; |
|
276
|
|
|
case 'order.service.position': $item = $item->setPosition( $value ); break; |
|
277
|
|
|
case 'order.service.mediaurl': $item = $item->setMediaUrl( $value ); break; |
|
278
|
|
|
default: continue 2; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
unset( $list[$key] ); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
return $item; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* Returns the item values as array. |
|
290
|
|
|
* |
|
291
|
|
|
* @param bool True to return private properties, false for public only |
|
292
|
|
|
* @return array Associative list of item properties and their values. |
|
293
|
|
|
*/ |
|
294
|
|
|
public function toArray( bool $private = false ) : array |
|
295
|
|
|
{ |
|
296
|
|
|
$price = $this->getPrice(); |
|
297
|
|
|
$list = parent::toArray( $private ); |
|
298
|
|
|
|
|
299
|
|
|
$list['order.service.type'] = $this->getType(); |
|
300
|
|
|
$list['order.service.code'] = $this->getCode(); |
|
301
|
|
|
$list['order.service.name'] = $this->getName(); |
|
302
|
|
|
$list['order.service.currencyid'] = $price->getCurrencyId(); |
|
303
|
|
|
$list['order.service.price'] = $price->getValue(); |
|
304
|
|
|
$list['order.service.costs'] = $price->getCosts(); |
|
305
|
|
|
$list['order.service.rebate'] = $price->getRebate(); |
|
306
|
|
|
$list['order.service.taxrates'] = $price->getTaxRates(); |
|
307
|
|
|
$list['order.service.taxvalue'] = $price->getTaxValue(); |
|
308
|
|
|
$list['order.service.taxflag'] = $price->getTaxFlag(); |
|
309
|
|
|
$list['order.service.position'] = $this->getPosition(); |
|
310
|
|
|
$list['order.service.mediaurl'] = $this->getMediaUrl(); |
|
311
|
|
|
$list['order.service.serviceid'] = $this->getServiceId(); |
|
312
|
|
|
|
|
313
|
|
|
if( $private === true ) { |
|
314
|
|
|
$list['order.service.parentid'] = $this->getParentId(); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
return $list; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* Copys all data from a given service item. |
|
323
|
|
|
* |
|
324
|
|
|
* @param \Aimeos\MShop\Service\Item\Iface $service New service item |
|
325
|
|
|
* @return \Aimeos\MShop\Order\Item\Service\Iface Order base service item for chaining method calls |
|
326
|
|
|
*/ |
|
327
|
|
|
public function copyFrom( \Aimeos\MShop\Service\Item\Iface $service ) : \Aimeos\MShop\Order\Item\Service\Iface |
|
328
|
|
|
{ |
|
329
|
|
|
$values = $service->toArray(); |
|
330
|
|
|
$this->fromArray( $values ); |
|
331
|
|
|
|
|
332
|
|
|
$this->setSiteId( $service->getSiteId() ); |
|
333
|
|
|
$this->setCode( $service->getCode() ); |
|
334
|
|
|
$this->setName( $service->getName() ); |
|
335
|
|
|
$this->setType( $service->getType() ); |
|
|
|
|
|
|
336
|
|
|
$this->setServiceId( $service->getId() ); |
|
|
|
|
|
|
337
|
|
|
|
|
338
|
|
|
if( ( $item = $service->getRefItems( 'media', 'default', 'default' )->first() ) !== null ) { |
|
339
|
|
|
$this->setMediaUrl( $item->getUrl() ); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
return $this->setModified(); |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|