Passed
Push — master ( d7cab9...07cded )
by Aimeos
04:47
created

Standard::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022-2024
6
 * @package MShop
7
 * @subpackage Order
8
 */
9
10
11
namespace Aimeos\MShop\Order\Item\Service\Transaction;
12
13
14
/**
15
 * Default order item base service transaction.
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\Transaction\Iface
23
{
24
	use \Aimeos\MShop\Common\Item\Config\Traits;
25
26
27
	/**
28
	 * Returns the ID of the site the item is stored
29
	 *
30
	 * @return string Site ID (or null if not available)
31
	 */
32
	public function getSiteId() : string
33
	{
34
		return $this->get( 'order.service.transaction.siteid', '' );
35
	}
36
37
38
	/**
39
	 * Sets the site ID of the item.
40
	 *
41
	 * @param string $value Unique site ID of the item
42
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order base service transaction item for chaining method calls
43
	 */
44
	public function setSiteId( string $value ) : \Aimeos\MShop\Order\Item\Service\Transaction\Iface
45
	{
46
		return $this->set( 'order.service.transaction.siteid', $value );
47
	}
48
49
50
	/**
51
	 * Returns the ID of the ordered service item as parent
52
	 *
53
	 * @return string|null ID of the ordered service item
54
	 */
55
	public function getParentId() : ?string
56
	{
57
		return $this->get( 'order.service.transaction.parentid' );
58
	}
59
60
61
	/**
62
	 * Sets the ID of the ordered service item as parent
63
	 *
64
	 * @param string|null $id ID of the ordered service item
65
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order base service transaction item for chaining method calls
66
	 */
67
	public function setParentId( ?string $id ) : \Aimeos\MShop\Common\Item\Iface
68
	{
69
		return $this->set( 'order.service.transaction.parentid', $id );
70
	}
71
72
73
	/**
74
	 * Returns the type of the service transaction item.
75
	 *
76
	 * @return string Type of the service transaction item
77
	 */
78
	public function getType() : string
79
	{
80
		return $this->get( 'order.service.transaction.type', '' );
81
	}
82
83
84
	/**
85
	 * Sets a new type for the service transaction item.
86
	 *
87
	 * @param string $type Type of the service transaction
88
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order base service transaction item for chaining method calls
89
	 */
90
	public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface
91
	{
92
		return $this->set( 'order.service.transaction.type', $this->checkCode( $type ) );
93
	}
94
95
96
	/**
97
	 * Returns the configuration values of the item
98
	 *
99
	 * @return array Configuration values
100
	 */
101
	public function getConfig() : array
102
	{
103
		return $this->get( 'order.service.transaction.config', [] );
104
	}
105
106
107
	/**
108
	 * Sets the configuration values of the item.
109
	 *
110
	 * @param array $config Configuration values
111
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order base service transaction item for chaining method calls
112
	 */
113
	public function setConfig( array $config ) : \Aimeos\MShop\Common\Item\Iface
114
	{
115
		return $this->set( 'order.service.transaction.config', $config );
116
	}
117
118
119
	/**
120
	 * Returns the price item for the transaction.
121
	 *
122
	 * @return \Aimeos\MShop\Price\Item\Iface Price item with price, costs and rebate
123
	 */
124
	public function getPrice() : \Aimeos\MShop\Price\Item\Iface
125
	{
126
		return $this->get( '.price' );
127
	}
128
129
130
	/**
131
	 * Sets the price item for the transaction.
132
	 *
133
	 * @param \Aimeos\MShop\Price\Item\Iface $price Price item containing price and additional costs
134
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order base service transaction item for chaining method calls
135
	 */
136
	public function setPrice( \Aimeos\MShop\Price\Item\Iface $price ) : \Aimeos\MShop\Order\Item\Service\Transaction\Iface
137
	{
138
		return $this->set( '.price', $price );
139
	}
140
141
142
	/**
143
	 * Returns the status of the transaction
144
	 *
145
	 * @return int Status of the transaction
146
	 */
147
	public function getStatus() : int
148
	{
149
		return $this->get( 'order.service.transaction.status', -1 );
150
	}
151
152
153
	/**
154
	 * Sets the new status of the transaction
155
	 *
156
	 * @param int $status New status of the transaction
157
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order base service transaction item for chaining method calls
158
	 */
159
	public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface
160
	{
161
		return $this->set( 'order.service.transaction.status', $status );
162
	}
163
164
165
	/*
166
	 * Sets the item values from the given array and removes that entries from the list
167
	 *
168
	 * @param array &$list Associative list of item keys and their values
169
	 * @param bool True to set private properties too, false for public only
170
	 * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface Order service transaction item for chaining method calls
171
	 */
172
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
173
	{
174
		$item = parent::fromArray( $list, $private );
175
		$price = $item->getPrice();
176
177
		foreach( $list as $key => $value )
178
		{
179
			switch( $key )
180
			{
181
				case 'order.service.transaction.parentid': !$private ?: $item = $item->setParentId( $value ); break;
182
				case 'order.service.transaction.siteid': !$private ?: $item = $item->setSiteId( $value ); break;
183
				case 'order.service.transaction.config': $item = $item->setConfig( (array) $value ); break;
184
				case 'order.service.transaction.status': $item = $item->setStatus( (int) $value ); break;
185
				case 'order.service.transaction.currencyid': $price->setCurrencyId( $value ); break;
186
				case 'order.service.transaction.type': $item = $item->setType( $value ); break;
187
				case 'order.service.transaction.price': $price->setValue( $value ); break;
188
				case 'order.service.transaction.costs': $price->setCosts( $value ); break;
189
				case 'order.service.transaction.rebate': $price->setRebate( $value ); break;
190
				case 'order.service.transaction.taxvalue': $price->setTaxvalue( $value ); break;
191
				case 'order.service.transaction.taxflag': $price->setTaxflag( (bool) $value ); break;
192
				default: continue 2;
193
			}
194
195
			unset( $list[$key] );
196
		}
197
198
		return $item;
199
	}
200
201
202
	/**
203
	 * Returns the item values as array.
204
	 *
205
	 * @param bool True to return private properties, false for public only
206
	 * @return array Associative list of item properties and their values
207
	 */
208
	public function toArray( bool $private = false ) : array
209
	{
210
		$list = parent::toArray( $private );
211
		$price = $this->getPrice();
212
213
		$list['order.service.transaction.type'] = $this->getType();
214
		$list['order.service.transaction.config'] = $this->getConfig();
215
		$list['order.service.transaction.status'] = $this->getStatus();
216
		$list['order.service.transaction.currencyid'] = $price->getCurrencyId();
217
		$list['order.service.transaction.price'] = $price->getValue();
218
		$list['order.service.transaction.costs'] = $price->getCosts();
219
		$list['order.service.transaction.rebate'] = $price->getRebate();
220
		$list['order.service.transaction.taxvalue'] = $price->getTaxvalue();
221
		$list['order.service.transaction.taxflag'] = $price->getTaxflag();
222
223
		if( $private === true ) {
224
			$list['order.service.transaction.parentid'] = $this->getParentId();
225
		}
226
227
		return $list;
228
	}
229
}
230