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