Passed
Push — master ( fa0ea1...d7cab9 )
by Aimeos
05:50
created

Standard::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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