|
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\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\Address\Base |
|
23
|
|
|
implements \Aimeos\MShop\Order\Item\Address\Iface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Initializes the objects with the given array of values. |
|
27
|
|
|
* |
|
28
|
|
|
* @param array $values List of address elements |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( array $values = [] ) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct( 'order.address.', $values ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns the original customer address ID. |
|
38
|
|
|
* |
|
39
|
|
|
* @return string Customer address ID |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getAddressId() : string |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->get( 'order.address.addressid', '' ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Sets the original customer address ID. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $addrid New customer address ID |
|
51
|
|
|
* @return \Aimeos\MShop\Order\Item\Address\Iface Order base address item for chaining method calls |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setAddressId( string $addrid ) : \Aimeos\MShop\Order\Item\Address\Iface |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->set( 'order.address.addressid', $addrid ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the address type which can be billing or delivery. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string Address type |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getType() : string |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->get( 'order.address.type', \Aimeos\MShop\Order\Item\Address\Base::TYPE_PAYMENT ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Sets the new type of the address which can be billing or delivery. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $type New type of the address |
|
74
|
|
|
* @return \Aimeos\MShop\Order\Item\Address\Iface Order base address item for chaining method calls |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->set( 'order.address.type', $this->checkType( $type ) ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Copys all data from a given address item. |
|
84
|
|
|
* |
|
85
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $item New address |
|
86
|
|
|
* @return \Aimeos\MShop\Order\Item\Address\Iface Order base address item for chaining method calls |
|
87
|
|
|
*/ |
|
88
|
|
|
public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
89
|
|
|
{ |
|
90
|
|
|
parent::copyFrom( $item ); |
|
91
|
|
|
|
|
92
|
|
|
$this->setAddressId( (string) $item->getId() ); |
|
93
|
|
|
$this->setModified(); |
|
94
|
|
|
|
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
/* |
|
100
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
101
|
|
|
* |
|
102
|
|
|
* @param array &$list Associative list of item keys and their values |
|
103
|
|
|
* @param bool True to set private properties too, false for public only |
|
104
|
|
|
* @return \Aimeos\MShop\Order\Item\Address\Iface Order address item for chaining method calls |
|
105
|
|
|
*/ |
|
106
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
107
|
|
|
{ |
|
108
|
|
|
$item = parent::fromArray( $list, $private ); |
|
109
|
|
|
|
|
110
|
|
|
foreach( $list as $key => $value ) |
|
111
|
|
|
{ |
|
112
|
|
|
switch( $key ) |
|
113
|
|
|
{ |
|
114
|
|
|
case 'order.address.addressid': $item = $item->setAddressId( $value ); break; |
|
|
|
|
|
|
115
|
|
|
case 'order.address.type': $item = $item->setType( $value ); break; |
|
|
|
|
|
|
116
|
|
|
default: continue 2; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
unset( $list[$key] ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return $item; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Returns the item values as array. |
|
128
|
|
|
* |
|
129
|
|
|
* @param bool True to return private properties, false for public only |
|
130
|
|
|
* @return array Associative list of item properties and their values |
|
131
|
|
|
*/ |
|
132
|
|
|
public function toArray( bool $private = false ) : array |
|
133
|
|
|
{ |
|
134
|
|
|
$list = parent::toArray( $private ); |
|
135
|
|
|
|
|
136
|
|
|
$list['order.address.type'] = $this->getType(); |
|
137
|
|
|
$list['order.address.addressid'] = $this->getAddressId(); |
|
138
|
|
|
|
|
139
|
|
|
return $list; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|