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-2018 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Order |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Order\Item\Base\Address; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default order address container object |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Order |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\MShop\Order\Item\Base\Address\Base |
23
|
|
|
implements \Aimeos\MShop\Order\Item\Base\Address\Iface |
24
|
|
|
{ |
25
|
|
|
private $values; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the objects with the given array of values. |
29
|
|
|
* |
30
|
|
|
* @param array $values List of address elements |
31
|
|
|
*/ |
32
|
|
|
public function __construct( array $values = [] ) |
33
|
|
|
{ |
34
|
|
|
parent::__construct( 'order.base.address.', $values ); |
35
|
|
|
|
36
|
|
|
$this->values = $values; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns the order base ID the address belongs to. |
42
|
|
|
* |
43
|
|
|
* @return string|null Base ID |
44
|
|
|
*/ |
45
|
|
|
public function getBaseId() |
46
|
|
|
{ |
47
|
|
|
if( isset( $this->values['order.base.address.baseid'] ) ) { |
48
|
|
|
return (string) $this->values['order.base.address.baseid']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Sets the order base ID the address belongs to. |
57
|
|
|
* |
58
|
|
|
* @param string $value New base ID |
59
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls |
60
|
|
|
*/ |
61
|
|
|
public function setBaseId( $value ) |
62
|
|
|
{ |
63
|
|
|
if( (string) $value !== $this->getBaseId() ) |
64
|
|
|
{ |
65
|
|
|
$this->values['order.base.address.baseid'] = (string) $value; |
66
|
|
|
$this->setModified(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the original customer address ID. |
75
|
|
|
* |
76
|
|
|
* @return string Customer address ID |
77
|
|
|
*/ |
78
|
|
|
public function getAddressId() |
79
|
|
|
{ |
80
|
|
|
if( isset( $this->values['order.base.address.addressid'] ) ) { |
81
|
|
|
return (string) $this->values['order.base.address.addressid']; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return ''; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Sets the original customer address ID. |
90
|
|
|
* |
91
|
|
|
* @param string $addrid New customer address ID |
92
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls |
93
|
|
|
*/ |
94
|
|
|
public function setAddressId( $addrid ) |
95
|
|
|
{ |
96
|
|
|
if( (string) $addrid !== $this->getAddressId() ) |
97
|
|
|
{ |
98
|
|
|
$this->values['order.base.address.addressid'] = (string) $addrid; |
99
|
|
|
$this->setModified(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns the address type which can be billing or delivery. |
108
|
|
|
* |
109
|
|
|
* @return string Address type |
110
|
|
|
*/ |
111
|
|
|
public function getType() |
112
|
|
|
{ |
113
|
|
|
if( isset( $this->values['order.base.address.type'] ) ) { |
114
|
|
|
return (string) $this->values['order.base.address.type']; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Sets the new type of the address which can be billing or delivery. |
123
|
|
|
* |
124
|
|
|
* @param string $type New type of the address |
125
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls |
126
|
|
|
*/ |
127
|
|
|
public function setType( $type ) |
128
|
|
|
{ |
129
|
|
|
$this->checkType( $type ); |
130
|
|
|
|
131
|
|
|
if( (string) $type !== $this->getType() ) |
132
|
|
|
{ |
133
|
|
|
$this->values['order.base.address.type'] = (string) $type; |
134
|
|
|
$this->setModified(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Copys all data from a given address item. |
143
|
|
|
* |
144
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $item New address |
145
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls |
146
|
|
|
*/ |
147
|
|
|
public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item ) |
148
|
|
|
{ |
149
|
|
|
parent::copyFrom( $item ); |
150
|
|
|
|
151
|
|
|
$this->setAddressId( $item->getId() ); |
152
|
|
|
$this->setModified(); |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/* |
159
|
|
|
* Sets the item values from the given array and removes that entries from the list |
160
|
|
|
* |
161
|
|
|
* @param array &$list Associative list of item keys and their values |
162
|
|
|
* @param boolean True to set private properties too, false for public only |
163
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order address item for chaining method calls |
164
|
|
|
*/ |
165
|
|
|
public function fromArray( array &$list, $private = false ) |
166
|
|
|
{ |
167
|
|
|
$item = parent::fromArray( $list, $private ); |
168
|
|
|
|
169
|
|
|
foreach( $list as $key => $value ) |
170
|
|
|
{ |
171
|
|
|
switch( $key ) |
172
|
|
|
{ |
173
|
|
|
case 'order.base.address.baseid': !$private ?: $item = $item->setBaseId( $value ); break; |
|
|
|
|
174
|
|
|
case 'order.base.address.addressid': !$private ?: $item = $item->setAddressId( $value ); break; |
|
|
|
|
175
|
|
|
case 'order.base.address.type': $item = $item->setType( $value ); break; |
|
|
|
|
176
|
|
|
default: continue 2; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
unset( $list[$key] ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $item; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns the item values as array. |
188
|
|
|
* |
189
|
|
|
* @param boolean True to return private properties, false for public only |
190
|
|
|
* @return array Associative list of item properties and their values |
191
|
|
|
*/ |
192
|
|
|
public function toArray( $private = false ) |
193
|
|
|
{ |
194
|
|
|
$list = parent::toArray( $private ); |
195
|
|
|
|
196
|
|
|
$list['order.base.address.type'] = $this->getType(); |
197
|
|
|
|
198
|
|
|
if( $private === true ) |
199
|
|
|
{ |
200
|
|
|
$list['order.base.address.baseid'] = $this->getBaseId(); |
201
|
|
|
$list['order.base.address.addressid'] = $this->getAddressId(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $list; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
} |
208
|
|
|
|