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