Passed
Push — master ( ef7004...60f145 )
by Aimeos
09:20
created

Standard::getContent()   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
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
4
 * @copyright Aimeos (aimeos.org), 2022
5
 * @package MShop
6
 * @subpackage Order
7
 */
8
9
10
namespace Aimeos\MShop\Order\Item\Basket;
11
12
13
/**
14
 * Default implementation of the order status object.
15
 *
16
 * @package MShop
17
 * @subpackage Order
18
 */
19
class Standard
20
	extends \Aimeos\MShop\Common\Item\Base
21
	implements \Aimeos\MShop\Order\Item\Basket\Iface
22
{
23
	/**
24
	 * Initializes the object
25
	 *
26
	 * @param array $values Associative list of key/value pairs with order status properties
27
	 */
28
	public function __construct( array $values = [] )
29
	{
30
		parent::__construct( 'order.basket.', $values );
31
	}
32
33
34
	/**
35
	 * Sets the new ID of the item.
36
	 *
37
	 * @param string|null $id ID of the item
38
	 * @return \Aimeos\MShop\Common\Item\Iface Item for chaining method calls
39
	 */
40
	public function setId( ?string $id ) : \Aimeos\MShop\Common\Item\Iface
41
	{
42
		return parent::setId( $id )->setModified();
43
	}
44
45
46
	/**
47
	 * Returns the content of the basket.
48
	 *
49
	 * @return string Content of the basket
50
	 */
51
	public function getContent() : string
52
	{
53
		return (string) $this->get( 'order.basket.content' );
54
	}
55
56
57
	/**
58
	 * Sets the content of the basket.
59
	 *
60
	 * @param string $value Content of the basket
61
	 * @return \Aimeos\MShop\Order\Item\Basket\Iface Basket item for chaining method calls
62
	 */
63
	public function setContent( string $value ) : \Aimeos\MShop\Order\Item\Basket\Iface
64
	{
65
		return $this->set( 'order.basket.content', $value );
66
	}
67
68
69
	/**
70
	 * Returns the ID of the customer who owns the basket.
71
	 *
72
	 * @return string Unique ID of the customer
73
	 */
74
	public function getCustomerId() : string
75
	{
76
		return (string) $this->get( 'order.basket.customerid', '' );
77
	}
78
79
80
	/**
81
	 * Sets the ID of the customer who owned the basket.
82
	 *
83
	 * @param string $customerid Unique ID of the customer
84
	 * @return \Aimeos\MShop\Order\Item\Basket\Iface Basket item for chaining method calls
85
	 */
86
	public function setCustomerId( ?string $value ) : \Aimeos\MShop\Order\Item\Basket\Iface
87
	{
88
		return $this->set( 'order.basket.customerid', (string) $value );
89
	}
90
91
92
	/**
93
	 * Returns the name of the basket.
94
	 *
95
	 * @return string Name for the basket
96
	 */
97
	public function getName() : string
98
	{
99
		return (string) $this->get( 'order.basket.name', '' );
100
	}
101
102
103
	/**
104
	 * Sets the name of the basket.
105
	 *
106
	 * @param string $value Name for the basket
107
	 * @return \Aimeos\MShop\Order\Item\Basket\Iface Basket item for chaining method calls
108
	 */
109
	public function setName( ?string $value ) : \Aimeos\MShop\Order\Item\Basket\Iface
110
	{
111
		return $this->set( 'order.basket.name', (string) $value );
112
	}
113
114
115
	/**
116
	 * Returns the item type
117
	 *
118
	 * @return string Item type, subtypes are separated by slashes
119
	 */
120
	public function getResourceType() : string
121
	{
122
		return 'order/basket';
123
	}
124
125
126
	/*
127
	 * Sets the item values from the given array and removes that entries from the list
128
	 *
129
	 * @param array &$list Associative list of item keys and their values
130
	 * @param bool True to set private properties too, false for public only
131
	 * @return \Aimeos\MShop\Order\Item\Basket\Iface Order status item for chaining method calls
132
	 */
133
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
134
	{
135
		$item = parent::fromArray( $list, $private );
136
137
		foreach( $list as $key => $value )
138
		{
139
			switch( $key )
140
			{
141
				case 'order.basket.customerid': $item = $item->setCustomerId( $value ); break;
142
				case 'order.basket.content': $item = $item->setContent( $value ); break;
143
				case 'order.basket.name': $item = $item->setName( $value ); break;
144
				default: continue 2;
145
			}
146
147
			unset( $list[$key] );
148
		}
149
150
		return $item;
151
	}
152
153
154
155
	/**
156
	 * Returns the item values as array.
157
	 *
158
	 * @param bool True to return private properties, false for public only
159
	 * @return array Associative list of item properties and their values
160
	 */
161
	public function toArray( bool $private = false ) : array
162
	{
163
		$list = parent::toArray( $private );
164
165
		$list['order.basket.name'] = $this->getName();
166
		$list['order.basket.content'] = $this->getContent();
167
		$list['order.basket.customerid'] = $this->getCustomerId();
168
169
		return $list;
170
	}
171
172
}
173