1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2020 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Order |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Order\Item\Base\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 |
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
|
|
|
?\Aimeos\MShop\Service\Item\Iface $serviceItem = null ) |
36
|
|
|
{ |
37
|
|
|
parent::__construct( $price, $values, $attributes ); |
38
|
|
|
|
39
|
|
|
$this->serviceItem = $serviceItem; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the associated service item |
45
|
|
|
* |
46
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface|null Product 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|null Site ID (or null if not available) |
58
|
|
|
*/ |
59
|
|
|
public function getSiteId() : ?string |
60
|
|
|
{ |
61
|
|
|
return $this->get( 'order.base.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\Base\Service\Iface Order base service item for chaining method calls |
70
|
|
|
*/ |
71
|
|
|
public function setSiteId( string $value ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
72
|
|
|
{ |
73
|
|
|
return $this->set( 'order.base.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 getBaseId() : ?string |
83
|
|
|
{ |
84
|
|
|
return $this->get( 'order.base.service.baseid' ); |
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\Base\Service\Iface Order base service item for chaining method calls |
93
|
|
|
*/ |
94
|
|
|
public function setBaseId( ?string $value ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
95
|
|
|
{ |
96
|
|
|
return $this->set( 'order.base.service.baseid', $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.base.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\Base\Service\Iface Order base service item for chaining method calls |
116
|
|
|
*/ |
117
|
|
|
public function setServiceId( string $servid ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
118
|
|
|
{ |
119
|
|
|
return $this->set( 'order.base.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.base.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\Base\Service\Iface Order base service item for chaining method calls |
139
|
|
|
*/ |
140
|
|
|
public function setCode( string $code ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
141
|
|
|
{ |
142
|
|
|
return $this->set( 'order.base.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.base.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\Base\Service\Iface Order base service item for chaining method calls |
162
|
|
|
*/ |
163
|
|
|
public function setName( string $name ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
164
|
|
|
{ |
165
|
|
|
return $this->set( 'order.base.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.base.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\Base\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.base.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.base.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\Base\Service\Iface Order base service item for chaining method calls |
208
|
|
|
*/ |
209
|
|
|
public function setMediaUrl( string $value ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
210
|
|
|
{ |
211
|
|
|
return $this->set( 'order.base.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.base.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\Base\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\Base\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.base.service.position', ( $value !== null ? $value : null ) ); |
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\Base\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
|
|
|
$item = parent::fromArray( $list, $private ); |
257
|
|
|
|
258
|
|
|
foreach( $list as $key => $value ) |
259
|
|
|
{ |
260
|
|
|
switch( $key ) |
261
|
|
|
{ |
262
|
|
|
case 'order.base.service.siteid': !$private ?: $item = $item->setSiteId( $value ); break; |
263
|
|
|
case 'order.base.service.baseid': !$private ?: $item = $item->setBaseId( $value ); break; |
264
|
|
|
case 'order.base.service.serviceid': !$private ?: $item = $item->setServiceId( $value ); break; |
265
|
|
|
case 'order.base.service.type': $item = $item->setType( $value ); break; |
266
|
|
|
case 'order.base.service.code': $item = $item->setCode( $value ); break; |
267
|
|
|
case 'order.base.service.name': $item = $item->setName( $value ); break; |
268
|
|
|
case 'order.base.service.position': $item = $item->setPosition( $value ); break; |
269
|
|
|
case 'order.base.service.mediaurl': $item = $item->setMediaUrl( $value ); break; |
270
|
|
|
default: continue 2; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
unset( $list[$key] ); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
return $item; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Returns the item values as array. |
282
|
|
|
* |
283
|
|
|
* @param bool True to return private properties, false for public only |
284
|
|
|
* @return array Associative list of item properties and their values. |
285
|
|
|
*/ |
286
|
|
|
public function toArray( bool $private = false ) : array |
287
|
|
|
{ |
288
|
|
|
$list = parent::toArray( $private ); |
289
|
|
|
|
290
|
|
|
$list['order.base.service.type'] = $this->getType(); |
291
|
|
|
$list['order.base.service.code'] = $this->getCode(); |
292
|
|
|
$list['order.base.service.name'] = $this->getName(); |
293
|
|
|
$list['order.base.service.position'] = $this->getPosition(); |
294
|
|
|
$list['order.base.service.mediaurl'] = $this->getMediaUrl(); |
295
|
|
|
|
296
|
|
|
if( $private === true ) |
297
|
|
|
{ |
298
|
|
|
$list['order.base.service.baseid'] = $this->getBaseId(); |
299
|
|
|
$list['order.base.service.serviceid'] = $this->getServiceId(); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
return $list; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Copys all data from a given service item. |
308
|
|
|
* |
309
|
|
|
* @param \Aimeos\MShop\Service\Item\Iface $service New service item |
310
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Service\Iface Order base service item for chaining method calls |
311
|
|
|
*/ |
312
|
|
|
public function copyFrom( \Aimeos\MShop\Service\Item\Iface $service ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
313
|
|
|
{ |
314
|
|
|
$this->setSiteId( $service->getSiteId() ); |
|
|
|
|
315
|
|
|
$this->setCode( $service->getCode() ); |
316
|
|
|
$this->setName( $service->getName() ); |
317
|
|
|
$this->setType( $service->getType() ); |
|
|
|
|
318
|
|
|
$this->setServiceId( $service->getId() ); |
|
|
|
|
319
|
|
|
|
320
|
|
|
if( ( $item = $service->getRefItems( 'media', 'default', 'default' )->first() ) !== null ) { |
321
|
|
|
$this->setMediaUrl( $item->getUrl() ); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
return $this->setModified(); |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
|