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 Customer |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Customer\Item; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Interface for customer DTO objects used by the shop. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Customer |
20
|
|
|
*/ |
21
|
|
|
abstract class Base |
22
|
|
|
extends \Aimeos\MShop\Common\Item\Base |
23
|
|
|
implements \Aimeos\MShop\Customer\Item\Iface |
24
|
|
|
{ |
25
|
|
|
use \Aimeos\MShop\Common\Item\ListRef\Traits { |
26
|
|
|
__clone as __cloneList; |
27
|
|
|
} |
28
|
|
|
use \Aimeos\MShop\Common\Item\PropertyRef\Traits { |
29
|
|
|
__clone as __cloneProperty; |
30
|
|
|
} |
31
|
|
|
use \Aimeos\MShop\Common\Item\AddressRef\Traits { |
32
|
|
|
__clone as __cloneAddress; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
private $billingaddress; |
37
|
|
|
private $data; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Initializes the customer item object |
42
|
|
|
* |
43
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $address Payment address item object |
44
|
|
|
* @param array $values List of attributes that belong to the customer item |
45
|
|
|
* @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items |
46
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items |
47
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface[] $addresses List of referenced address items |
48
|
|
|
* @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items |
49
|
|
|
*/ |
50
|
|
|
public function __construct( \Aimeos\MShop\Common\Item\Address\Iface $address, array $values = [], |
51
|
|
|
array $listItems = [], array $refItems = [], $addresses = [], array $propItems = [] ) |
52
|
|
|
{ |
53
|
|
|
parent::__construct( 'customer.', $values ); |
54
|
|
|
|
55
|
|
|
$this->initAddressItems( $addresses ); |
56
|
|
|
$this->initPropertyItems( $propItems ); |
57
|
|
|
$this->initListItems( $listItems, $refItems ); |
58
|
|
|
|
59
|
|
|
// set modified flag to false |
60
|
|
|
$address->setId( $this->getId() ); |
61
|
|
|
|
62
|
|
|
$this->billingaddress = $address; |
63
|
|
|
$this->data = $values; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Creates a deep clone of all objects |
69
|
|
|
*/ |
70
|
|
|
public function __clone() |
71
|
|
|
{ |
72
|
|
|
$this->billingaddress = clone $this->billingaddress; |
73
|
|
|
|
74
|
|
|
parent::__clone(); |
75
|
|
|
$this->__cloneList(); |
76
|
|
|
$this->__cloneAddress(); |
77
|
|
|
$this->__cloneProperty(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the billingaddress of the customer item. |
83
|
|
|
* |
84
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface |
85
|
|
|
*/ |
86
|
|
|
public function getPaymentAddress() |
87
|
|
|
{ |
88
|
|
|
return $this->billingaddress; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Sets the billingaddress of the customer item. |
94
|
|
|
* |
95
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $address Billingaddress of the customer item |
96
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface Customer item for chaining method calls |
97
|
|
|
*/ |
98
|
|
|
public function setPaymentAddress( \Aimeos\MShop\Common\Item\Address\Iface $address ) |
99
|
|
|
{ |
100
|
|
|
if( $address === $this->billingaddress && $address->isModified() === false ) { return $this; } |
101
|
|
|
|
102
|
|
|
$this->billingaddress = $address; |
103
|
|
|
$this->setModified(); |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns the item type |
111
|
|
|
* |
112
|
|
|
* @return string Item type, subtypes are separated by slashes |
113
|
|
|
*/ |
114
|
|
|
public function getResourceType() |
115
|
|
|
{ |
116
|
|
|
return 'customer'; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Tests if this item object was modified |
122
|
|
|
* |
123
|
|
|
* @return boolean True if modified, false if not |
124
|
|
|
*/ |
125
|
|
|
public function isModified() |
126
|
|
|
{ |
127
|
|
|
return parent::isModified() || $this->getPaymentAddress()->isModified(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Sets the item values from the given array. |
133
|
|
|
* |
134
|
|
|
* @param array $list Associative list of item keys and their values |
135
|
|
|
* @return array Associative list of keys and their values that are unknown |
136
|
|
|
*/ |
137
|
|
|
public function fromArray( array $list ) |
138
|
|
|
{ |
139
|
|
|
$unknown = []; |
140
|
|
|
$list = parent::fromArray( $list ); |
141
|
|
|
$addr = $this->getPaymentAddress(); |
142
|
|
|
|
143
|
|
|
foreach( $list as $key => $value ) |
144
|
|
|
{ |
145
|
|
|
switch( $key ) |
146
|
|
|
{ |
147
|
|
|
case 'customer.salutation': $addr->setSalutation( $value ); break; |
148
|
|
|
case 'customer.company': $addr->setCompany( $value ); break; |
149
|
|
|
case 'customer.vatid': $addr->setVatID( $value ); break; |
150
|
|
|
case 'customer.title': $addr->setTitle( $value ); break; |
151
|
|
|
case 'customer.firstname': $addr->setFirstname( $value ); break; |
152
|
|
|
case 'customer.lastname': $addr->setLastname( $value ); break; |
153
|
|
|
case 'customer.address1': $addr->setAddress1( $value ); break; |
154
|
|
|
case 'customer.address2': $addr->setAddress2( $value ); break; |
155
|
|
|
case 'customer.address3': $addr->setAddress3( $value ); break; |
156
|
|
|
case 'customer.postal': $addr->setPostal( $value ); break; |
157
|
|
|
case 'customer.city': $addr->setCity( $value ); break; |
158
|
|
|
case 'customer.state': $addr->setState( $value ); break; |
159
|
|
|
case 'customer.languageid': $addr->setLanguageId( $value ); break; |
160
|
|
|
case 'customer.countryid': $addr->setCountryId( $value ); break; |
161
|
|
|
case 'customer.telephone': $addr->setTelephone( $value ); break; |
162
|
|
|
case 'customer.email': $addr->setEmail( $value ); break; |
163
|
|
|
case 'customer.telefax': $addr->setTelefax( $value ); break; |
164
|
|
|
case 'customer.website': $addr->setWebsite( $value ); break; |
165
|
|
|
case 'customer.longitude': $addr->setLongitude( $value ); break; |
166
|
|
|
case 'customer.latitude': $addr->setLatitude( $value ); break; |
167
|
|
|
default: $unknown[$key] = $value; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
return $unknown; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Returns the item values as array. |
177
|
|
|
* |
178
|
|
|
* @param boolean True to return private properties, false for public only |
179
|
|
|
* @return array Associative list of item properties and their values |
180
|
|
|
*/ |
181
|
|
|
public function toArray( $private = false ) |
182
|
|
|
{ |
183
|
|
|
$list = parent::toArray( $private ); |
184
|
|
|
|
185
|
|
|
$list['customer.salutation'] = $this->getPaymentAddress()->getSalutation(); |
186
|
|
|
$list['customer.company'] = $this->getPaymentAddress()->getCompany(); |
187
|
|
|
$list['customer.vatid'] = $this->getPaymentAddress()->getVatID(); |
188
|
|
|
$list['customer.title'] = $this->getPaymentAddress()->getTitle(); |
189
|
|
|
$list['customer.firstname'] = $this->getPaymentAddress()->getFirstname(); |
190
|
|
|
$list['customer.lastname'] = $this->getPaymentAddress()->getLastname(); |
191
|
|
|
$list['customer.address1'] = $this->getPaymentAddress()->getAddress1(); |
192
|
|
|
$list['customer.address2'] = $this->getPaymentAddress()->getAddress2(); |
193
|
|
|
$list['customer.address3'] = $this->getPaymentAddress()->getAddress3(); |
194
|
|
|
$list['customer.postal'] = $this->getPaymentAddress()->getPostal(); |
195
|
|
|
$list['customer.city'] = $this->getPaymentAddress()->getCity(); |
196
|
|
|
$list['customer.state'] = $this->getPaymentAddress()->getState(); |
197
|
|
|
$list['customer.languageid'] = $this->getPaymentAddress()->getLanguageId(); |
198
|
|
|
$list['customer.countryid'] = $this->getPaymentAddress()->getCountryId(); |
199
|
|
|
$list['customer.telephone'] = $this->getPaymentAddress()->getTelephone(); |
200
|
|
|
$list['customer.email'] = $this->getPaymentAddress()->getEmail(); |
201
|
|
|
$list['customer.telefax'] = $this->getPaymentAddress()->getTelefax(); |
202
|
|
|
$list['customer.website'] = $this->getPaymentAddress()->getWebsite(); |
203
|
|
|
$list['customer.longitude'] = $this->getPaymentAddress()->getLongitude(); |
204
|
|
|
$list['customer.latitude'] = $this->getPaymentAddress()->getLatitude(); |
205
|
|
|
|
206
|
|
|
return $list; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|