|
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 Customer |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Customer\Item\Address; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Interface for provider common address DTO objects used by the shop. |
|
16
|
|
|
* @package MShop |
|
17
|
|
|
* @subpackage Customer |
|
18
|
|
|
*/ |
|
19
|
|
|
class Standard |
|
20
|
|
|
extends \Aimeos\MShop\Common\Item\Address\Standard |
|
21
|
|
|
implements \Aimeos\MShop\Customer\Item\Address\Iface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Returns the type of the address item. |
|
25
|
|
|
* |
|
26
|
|
|
* @return string Address type |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getType() : string |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->get( 'customer.address.type', 'delivery' ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Sets the type of the address item. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $type Address type |
|
38
|
|
|
* @return \Aimeos\MShop\Customer\Item\Address\Iface Address item for chaining method calls |
|
39
|
|
|
*/ |
|
40
|
|
|
public function setType( string $type ) : \Aimeos\MShop\Customer\Item\Address\Iface |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->set( 'customer.address.type', $type ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/* |
|
47
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
48
|
|
|
* |
|
49
|
|
|
* @param array &$list Associative list of item keys and their values |
|
50
|
|
|
* @param bool True to set private properties too, false for public only |
|
51
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Address item for chaining method calls |
|
52
|
|
|
*/ |
|
53
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
54
|
|
|
{ |
|
55
|
|
|
$item = parent::fromArray( $list, $private ); |
|
56
|
|
|
|
|
57
|
|
|
foreach( $list as $idx => $value ) |
|
58
|
|
|
{ |
|
59
|
|
|
$pos = strrpos( $idx, '.' ); |
|
60
|
|
|
$key = $pos ? substr( $idx, $pos + 1 ) : $idx; |
|
61
|
|
|
|
|
62
|
|
|
switch( $key ) |
|
63
|
|
|
{ |
|
64
|
|
|
case 'type': $item = $item->setType( $value ); break; |
|
|
|
|
|
|
65
|
|
|
default: continue 2; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
unset( $list[$idx] ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $item; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the item values as array. |
|
77
|
|
|
* |
|
78
|
|
|
* @param bool True to return private properties, false for public only |
|
79
|
|
|
* @return array Associative list of item properties and their values |
|
80
|
|
|
*/ |
|
81
|
|
|
public function toArray( bool $private = false ) : array |
|
82
|
|
|
{ |
|
83
|
|
|
$list = parent::toArray( $private ); |
|
84
|
|
|
|
|
85
|
|
|
$list[$this->getPrefix() . 'type'] = $this->getType(); |
|
86
|
|
|
|
|
87
|
|
|
return $list; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|