|
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 Common |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Common\Item\Address; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Abstract class for address items. |
|
17
|
|
|
* |
|
18
|
|
|
* @package MShop |
|
19
|
|
|
* @subpackage Common |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class Base |
|
22
|
|
|
extends \Aimeos\MShop\Common\Item\Base |
|
23
|
|
|
implements \Aimeos\MShop\Common\Item\Address\Iface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Saluation is not known. |
|
27
|
|
|
* The customer didn't choose a valid salutation. |
|
28
|
|
|
*/ |
|
29
|
|
|
const SALUTATION_UNKNOWN = ''; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Saluation for a company. |
|
33
|
|
|
*/ |
|
34
|
|
|
const SALUTATION_COMPANY = 'company'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Saluation for a female customer. |
|
38
|
|
|
*/ |
|
39
|
|
|
const SALUTATION_MS = 'ms'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Saluation for a male customer. |
|
43
|
|
|
*/ |
|
44
|
|
|
const SALUTATION_MR = 'mr'; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
private $prefix; |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Initializes the address item. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $prefix Key prefix that should be used for toArray()/fromArray() like "customer.address." |
|
54
|
|
|
* @param array $values Associative list of key/value pairs containing address data |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct( string $prefix, array $values = [] ) |
|
57
|
|
|
{ |
|
58
|
|
|
parent::__construct( $prefix, $values ); |
|
59
|
|
|
|
|
60
|
|
|
$this->prefix = $prefix; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns the company name. |
|
66
|
|
|
* |
|
67
|
|
|
* @return string Company name |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getCompany() : string |
|
70
|
|
|
{ |
|
71
|
|
|
return (string) $this->get( $this->prefix . 'company', '' ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Sets a new company name. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $company New company name |
|
79
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setCompany( ?string $company ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->set( $this->prefix . 'company', (string) $company ); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the vatid. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string vatid |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getVatID() : string |
|
93
|
|
|
{ |
|
94
|
|
|
return (string) $this->get( $this->prefix . 'vatid', '' ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Sets a new vatid. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $vatid New vatid |
|
102
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setVatID( ?string $vatid ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->set( $this->prefix . 'vatid', (string) $vatid ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Returns the salutation constant for the person described by the address. |
|
112
|
|
|
* |
|
113
|
|
|
* @return string Saluatation constant defined in \Aimeos\MShop\Common\Item\Address\Base |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getSalutation() : string |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->get( $this->prefix . 'salutation', \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_UNKNOWN ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Sets the new salutation for the person described by the address. |
|
123
|
|
|
* |
|
124
|
|
|
* @param string $salutation Salutation constant defined in \Aimeos\MShop\Common\Item\Address\Base |
|
125
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
126
|
|
|
*/ |
|
127
|
|
|
public function setSalutation( ?string $salutation ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->set( $this->prefix . 'salutation', $this->checkSalutation( (string) $salutation ) ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Returns the title of the person. |
|
135
|
|
|
* |
|
136
|
|
|
* @return string Title of the person |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getTitle() : string |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->get( $this->prefix . 'title', '' ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Sets a new title of the person. |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $title New title of the person |
|
148
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setTitle( ?string $title ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->set( $this->prefix . 'title', (string) $title ); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Returns the first name of the person. |
|
158
|
|
|
* |
|
159
|
|
|
* @return string First name of the person |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getFirstname() : string |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->get( $this->prefix . 'firstname', '' ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Sets a new first name of the person. |
|
169
|
|
|
* |
|
170
|
|
|
* @param string $firstname New first name of the person |
|
171
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
172
|
|
|
*/ |
|
173
|
|
|
public function setFirstname( ?string $firstname ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->set( $this->prefix . 'firstname', (string) $firstname ); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Returns the last name of the person. |
|
181
|
|
|
* |
|
182
|
|
|
* @return string Last name of the person |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getLastname() : string |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->get( $this->prefix . 'lastname', '' ); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Sets a new last name of the person. |
|
192
|
|
|
* |
|
193
|
|
|
* @param string $lastname New last name of the person |
|
194
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
195
|
|
|
*/ |
|
196
|
|
|
public function setLastname( ?string $lastname ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
197
|
|
|
{ |
|
198
|
|
|
return $this->set( $this->prefix . 'lastname', (string) $lastname ); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Returns the first address part, e.g. the street name. |
|
204
|
|
|
* |
|
205
|
|
|
* @return string First address part |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getAddress1() : string |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->get( $this->prefix . 'address1', '' ); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Sets a new first address part, e.g. the street name. |
|
215
|
|
|
* |
|
216
|
|
|
* @param string $address1 New first address part |
|
217
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
218
|
|
|
*/ |
|
219
|
|
|
public function setAddress1( ?string $address1 ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->set( $this->prefix . 'address1', (string) $address1 ); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Returns the second address part, e.g. the house number. |
|
227
|
|
|
* |
|
228
|
|
|
* @return string Second address part |
|
229
|
|
|
*/ |
|
230
|
|
|
public function getAddress2() : string |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->get( $this->prefix . 'address2', '' ); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Sets a new second address part, e.g. the house number. |
|
238
|
|
|
* |
|
239
|
|
|
* @param string $address2 New second address part |
|
240
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
241
|
|
|
*/ |
|
242
|
|
|
public function setAddress2( ?string $address2 ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->set( $this->prefix . 'address2', (string) $address2 ); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Returns the third address part, e.g. the house name or floor number. |
|
250
|
|
|
* |
|
251
|
|
|
* @return string third address part |
|
252
|
|
|
*/ |
|
253
|
|
|
public function getAddress3() : string |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->get( $this->prefix . 'address3', '' ); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Sets a new third address part, e.g. the house name or floor number. |
|
261
|
|
|
* |
|
262
|
|
|
* @param string $address3 New third address part |
|
263
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
264
|
|
|
*/ |
|
265
|
|
|
public function setAddress3( ?string $address3 ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
266
|
|
|
{ |
|
267
|
|
|
return $this->set( $this->prefix . 'address3', (string) $address3 ); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Returns the postal code. |
|
273
|
|
|
* |
|
274
|
|
|
* @return string Postal code |
|
275
|
|
|
*/ |
|
276
|
|
|
public function getPostal() : string |
|
277
|
|
|
{ |
|
278
|
|
|
return $this->get( $this->prefix . 'postal', '' ); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Sets a new postal code. |
|
284
|
|
|
* |
|
285
|
|
|
* @param string $postal New postal code |
|
286
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
287
|
|
|
*/ |
|
288
|
|
|
public function setPostal( ?string $postal ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
289
|
|
|
{ |
|
290
|
|
|
return $this->set( $this->prefix . 'postal', (string) $postal ); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Returns the city name. |
|
296
|
|
|
* |
|
297
|
|
|
* @return string City name |
|
298
|
|
|
*/ |
|
299
|
|
|
public function getCity() : string |
|
300
|
|
|
{ |
|
301
|
|
|
return $this->get( $this->prefix . 'city', '' ); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Sets a new city name. |
|
307
|
|
|
* |
|
308
|
|
|
* @param string $city New city name |
|
309
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
310
|
|
|
*/ |
|
311
|
|
|
public function setCity( ?string $city ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
312
|
|
|
{ |
|
313
|
|
|
return $this->set( $this->prefix . 'city', (string) $city ); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Returns the state name. |
|
319
|
|
|
* |
|
320
|
|
|
* @return string State name |
|
321
|
|
|
*/ |
|
322
|
|
|
public function getState() : string |
|
323
|
|
|
{ |
|
324
|
|
|
return $this->get( $this->prefix . 'state', '' ); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* Sets a new state name. |
|
330
|
|
|
* |
|
331
|
|
|
* @param string $state New state name |
|
332
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
333
|
|
|
*/ |
|
334
|
|
|
public function setState( ?string $state ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
335
|
|
|
{ |
|
336
|
|
|
return $this->set( $this->prefix . 'state', (string) $state ); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Returns the unique ID of the country the address belongs to. |
|
342
|
|
|
* |
|
343
|
|
|
* @return string|null Unique ID of the country |
|
344
|
|
|
*/ |
|
345
|
|
|
public function getCountryId() : ?string |
|
346
|
|
|
{ |
|
347
|
|
|
return $this->get( $this->prefix . 'countryid' ); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* Sets the ID of the country the address is in. |
|
353
|
|
|
* |
|
354
|
|
|
* @param string|null $countryid Unique ID of the country |
|
355
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
356
|
|
|
*/ |
|
357
|
|
|
public function setCountryId( ?string $countryid ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
358
|
|
|
{ |
|
359
|
|
|
return $this->set( $this->prefix . 'countryid', $this->checkCountryId( $countryid ) ); |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Returns the unique ID of the language. |
|
365
|
|
|
* |
|
366
|
|
|
* @return string|null Unique ID of the language |
|
367
|
|
|
*/ |
|
368
|
|
|
public function getLanguageId() : ?string |
|
369
|
|
|
{ |
|
370
|
|
|
return $this->get( $this->prefix . 'languageid' ); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Sets the ID of the language. |
|
376
|
|
|
* |
|
377
|
|
|
* @param string|null $langid Unique ID of the language |
|
378
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
379
|
|
|
*/ |
|
380
|
|
|
public function setLanguageId( ?string $langid ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
381
|
|
|
{ |
|
382
|
|
|
return $this->set( $this->prefix . 'languageid', $this->checkLanguageId( $langid ) ); |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* Returns the telephone number. |
|
388
|
|
|
* |
|
389
|
|
|
* @return string Telephone number |
|
390
|
|
|
*/ |
|
391
|
|
|
public function getTelephone() : string |
|
392
|
|
|
{ |
|
393
|
|
|
return $this->get( $this->prefix . 'telephone', '' ); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
|
|
397
|
|
|
/** |
|
398
|
|
|
* Sets a new telephone number. |
|
399
|
|
|
* |
|
400
|
|
|
* @param string $telephone New telephone number |
|
401
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
402
|
|
|
*/ |
|
403
|
|
|
public function setTelephone( ?string $telephone ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
404
|
|
|
{ |
|
405
|
|
|
return $this->set( $this->prefix . 'telephone', (string) $telephone ); |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* Returns the email address. |
|
411
|
|
|
* |
|
412
|
|
|
* @return string Email address |
|
413
|
|
|
*/ |
|
414
|
|
|
public function getEmail() : string |
|
415
|
|
|
{ |
|
416
|
|
|
return $this->get( $this->prefix . 'email', '' ); |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* Sets a new email address. |
|
422
|
|
|
* |
|
423
|
|
|
* @param string $email New email address |
|
424
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
425
|
|
|
*/ |
|
426
|
|
|
public function setEmail( ?string $email ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
427
|
|
|
{ |
|
428
|
|
|
$regex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD'; |
|
429
|
|
|
|
|
430
|
|
|
if( $email != '' && preg_match( $regex, $email ) !== 1 ) { |
|
|
|
|
|
|
431
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Invalid characters in email address: "%1$s"', $email ) ); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
return $this->set( $this->prefix . 'email', (string) $email ); |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Returns the telefax number. |
|
440
|
|
|
* |
|
441
|
|
|
* @return string Telefax number |
|
442
|
|
|
*/ |
|
443
|
|
|
public function getTelefax() : string |
|
444
|
|
|
{ |
|
445
|
|
|
return $this->get( $this->prefix . 'telefax', '' ); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* Sets a new telefax number. |
|
451
|
|
|
* |
|
452
|
|
|
* @param string $telefax New telefax number |
|
453
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
454
|
|
|
*/ |
|
455
|
|
|
public function setTelefax( ?string $telefax ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
456
|
|
|
{ |
|
457
|
|
|
return $this->set( $this->prefix . 'telefax', (string) $telefax ); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
|
|
461
|
|
|
/** |
|
462
|
|
|
* Returns the website URL. |
|
463
|
|
|
* |
|
464
|
|
|
* @return string Website URL |
|
465
|
|
|
*/ |
|
466
|
|
|
public function getWebsite() : string |
|
467
|
|
|
{ |
|
468
|
|
|
return $this->get( $this->prefix . 'website', '' ); |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
|
|
472
|
|
|
/** |
|
473
|
|
|
* Sets a new website URL. |
|
474
|
|
|
* |
|
475
|
|
|
* @param string|null $website New website URL |
|
476
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
477
|
|
|
*/ |
|
478
|
|
|
public function setWebsite( ?string $website ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
479
|
|
|
{ |
|
480
|
|
|
$pattern = '#^([a-z]+://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?(/.*)?$#'; |
|
481
|
|
|
|
|
482
|
|
|
if( $website != '' && preg_match( $pattern, $website ) !== 1 ) { |
|
|
|
|
|
|
483
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Invalid web site URL "%1$s"', $website ) ); |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
return $this->set( $this->prefix . 'website', (string) $website ); |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
|
|
490
|
|
|
/** |
|
491
|
|
|
* Returns the longitude coordinate of the customer address |
|
492
|
|
|
* |
|
493
|
|
|
* @return float|null Longitude coordinate as decimal value or null |
|
494
|
|
|
*/ |
|
495
|
|
|
public function getLongitude() : ?float |
|
496
|
|
|
{ |
|
497
|
|
|
if( ( $result = $this->get( $this->prefix . 'longitude' ) ) !== null ) { |
|
498
|
|
|
return (float) $result; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
return null; |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
|
|
505
|
|
|
/** |
|
506
|
|
|
* Sets the longitude coordinate of the customer address |
|
507
|
|
|
* |
|
508
|
|
|
* @param string|null $value Longitude coordinate as decimal value or null |
|
509
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface Customer address item for chaining method calls |
|
510
|
|
|
*/ |
|
511
|
|
|
public function setLongitude( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
512
|
|
|
{ |
|
513
|
|
|
return $this->set( $this->prefix . 'longitude', $value !== '' && $value !== null ? $value : null ); |
|
514
|
|
|
} |
|
515
|
|
|
|
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* Returns the latitude coordinate of the customer address |
|
519
|
|
|
* |
|
520
|
|
|
* @return float|null Latitude coordinate as decimal value or null |
|
521
|
|
|
*/ |
|
522
|
|
|
public function getLatitude() : ?float |
|
523
|
|
|
{ |
|
524
|
|
|
if( ( $result = $this->get( $this->prefix . 'latitude' ) ) !== null ) { |
|
525
|
|
|
return (float) $result; |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
return null; |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
|
|
532
|
|
|
/** |
|
533
|
|
|
* Sets the latitude coordinate of the customer address |
|
534
|
|
|
* |
|
535
|
|
|
* @param string|null $value Latitude coordinate as decimal value or null |
|
536
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface Customer address item for chaining method calls |
|
537
|
|
|
*/ |
|
538
|
|
|
public function setLatitude( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
539
|
|
|
{ |
|
540
|
|
|
return $this->set( $this->prefix . 'latitude', $value !== '' && $value !== null ? $value : null ); |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
|
|
544
|
|
|
/** |
|
545
|
|
|
* Returns the birthday of the customer item. |
|
546
|
|
|
* |
|
547
|
|
|
* @return string|null Birthday in YYYY-MM-DD format |
|
548
|
|
|
*/ |
|
549
|
|
|
public function getBirthday() : ?string |
|
550
|
|
|
{ |
|
551
|
|
|
return $this->get( $this->prefix . 'birthday' ); |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
|
|
555
|
|
|
/** |
|
556
|
|
|
* Sets the birthday of the customer item. |
|
557
|
|
|
* |
|
558
|
|
|
* @param string|null $value Birthday of the customer item |
|
559
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Customer address item for chaining method calls |
|
560
|
|
|
*/ |
|
561
|
|
|
public function setBirthday( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
562
|
|
|
{ |
|
563
|
|
|
return $this->set( $this->prefix . 'birthday', $this->checkDateOnlyFormat( $value ) ); |
|
564
|
|
|
} |
|
565
|
|
|
|
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* Returns the customer ID this address belongs to |
|
569
|
|
|
* |
|
570
|
|
|
* @return string|null Customer ID of the address |
|
571
|
|
|
*/ |
|
572
|
|
|
public function getParentId() : ?string |
|
573
|
|
|
{ |
|
574
|
|
|
return $this->get( $this->prefix . 'parentid' ); |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* Sets the new customer ID this address belongs to |
|
580
|
|
|
* |
|
581
|
|
|
* @param string|null $parentid New customer ID of the address |
|
582
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
583
|
|
|
*/ |
|
584
|
|
|
public function setParentId( ?string $parentid ) : \Aimeos\MShop\Common\Item\Iface |
|
585
|
|
|
{ |
|
586
|
|
|
return $this->set( $this->prefix . 'parentid', $parentid ); |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
|
|
590
|
|
|
/** |
|
591
|
|
|
* Returns the position of the address item. |
|
592
|
|
|
* |
|
593
|
|
|
* @return int Position of the address item |
|
594
|
|
|
*/ |
|
595
|
|
|
public function getPosition() : int |
|
596
|
|
|
{ |
|
597
|
|
|
return $this->get( $this->prefix . 'position', 0 ); |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
|
|
601
|
|
|
/** |
|
602
|
|
|
* Sets the Position of the address item. |
|
603
|
|
|
* |
|
604
|
|
|
* @param int $position Position of the address item |
|
605
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
606
|
|
|
*/ |
|
607
|
|
|
public function setPosition( int $position ) : \Aimeos\MShop\Common\Item\Iface |
|
608
|
|
|
{ |
|
609
|
|
|
return $this->set( $this->prefix . 'position', $position ); |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
|
|
613
|
|
|
/** |
|
614
|
|
|
* Returns the item type |
|
615
|
|
|
* |
|
616
|
|
|
* @return string Item type, subtypes are separated by slashes |
|
617
|
|
|
*/ |
|
618
|
|
|
public function getResourceType() : string |
|
619
|
|
|
{ |
|
620
|
|
|
return str_replace( '.', '/', rtrim( $this->prefix, '.' ) ); |
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
|
|
624
|
|
|
/** |
|
625
|
|
|
* Copies the values of the address item into another one. |
|
626
|
|
|
* |
|
627
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $item Address item |
|
628
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
|
629
|
|
|
*/ |
|
630
|
|
|
public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item ) : \Aimeos\MShop\Common\Item\Address\Iface |
|
631
|
|
|
{ |
|
632
|
|
|
$values = $item->toArray(); |
|
633
|
|
|
$this->fromArray( $values ); |
|
634
|
|
|
|
|
635
|
|
|
$this->setCompany( $item->getCompany() ); |
|
636
|
|
|
$this->setVatID( $item->getVatID() ); |
|
637
|
|
|
$this->setSalutation( $item->getSalutation() ); |
|
638
|
|
|
$this->setTitle( $item->getTitle() ); |
|
639
|
|
|
$this->setFirstname( $item->getFirstname() ); |
|
640
|
|
|
$this->setLastname( $item->getLastname() ); |
|
641
|
|
|
$this->setAddress1( $item->getAddress1() ); |
|
642
|
|
|
$this->setAddress2( $item->getAddress2() ); |
|
643
|
|
|
$this->setAddress3( $item->getAddress3() ); |
|
644
|
|
|
$this->setPostal( $item->getPostal() ); |
|
645
|
|
|
$this->setCity( $item->getCity() ); |
|
646
|
|
|
$this->setState( $item->getState() ); |
|
647
|
|
|
$this->setCountryId( $item->getCountryId() ); |
|
648
|
|
|
$this->setLanguageId( $item->getLanguageId() ); |
|
649
|
|
|
$this->setTelephone( $item->getTelephone() ); |
|
650
|
|
|
$this->setTelefax( $item->getTelefax() ); |
|
651
|
|
|
$this->setEmail( $item->getEmail() ); |
|
652
|
|
|
$this->setWebsite( $item->getWebsite() ); |
|
653
|
|
|
$this->setLongitude( $item->getLongitude() ); |
|
654
|
|
|
$this->setLatitude( $item->getLatitude() ); |
|
655
|
|
|
$this->setBirthday( $item->getBirthday() ); |
|
656
|
|
|
|
|
657
|
|
|
return $this; |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
|
|
661
|
|
|
/* |
|
662
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
663
|
|
|
* |
|
664
|
|
|
* @param array &$list Associative list of item keys and their values |
|
665
|
|
|
* @param bool True to set private properties too, false for public only |
|
666
|
|
|
* @return \Aimeos\MShop\Common\Item\Address\Iface Address item for chaining method calls |
|
667
|
|
|
*/ |
|
668
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
669
|
|
|
{ |
|
670
|
|
|
$item = parent::fromArray( $list, $private ); |
|
671
|
|
|
|
|
672
|
|
|
foreach( $list as $idx => $value ) |
|
673
|
|
|
{ |
|
674
|
|
|
$pos = strrpos( $idx, '.' ); |
|
675
|
|
|
$key = $pos ? substr( $idx, $pos + 1 ) : $idx; |
|
676
|
|
|
|
|
677
|
|
|
switch( $key ) |
|
678
|
|
|
{ |
|
679
|
|
|
case 'parentid': !$private ?: $item = $item->setParentId( $value ); break; |
|
680
|
|
|
case 'salutation': $item = $item->setSalutation( $value ); break; |
|
681
|
|
|
case 'company': $item = $item->setCompany( $value ); break; |
|
682
|
|
|
case 'vatid': $item = $item->setVatID( $value ); break; |
|
683
|
|
|
case 'title': $item = $item->setTitle( $value ); break; |
|
684
|
|
|
case 'firstname': $item = $item->setFirstname( $value ); break; |
|
685
|
|
|
case 'lastname': $item = $item->setLastname( $value ); break; |
|
686
|
|
|
case 'address1': $item = $item->setAddress1( $value ); break; |
|
687
|
|
|
case 'address2': $item = $item->setAddress2( $value ); break; |
|
688
|
|
|
case 'address3': $item = $item->setAddress3( $value ); break; |
|
689
|
|
|
case 'postal': $item = $item->setPostal( $value ); break; |
|
690
|
|
|
case 'city': $item = $item->setCity( $value ); break; |
|
691
|
|
|
case 'state': $item = $item->setState( $value ); break; |
|
692
|
|
|
case 'countryid': $item = $item->setCountryId( $value ); break; |
|
693
|
|
|
case 'languageid': $item = $item->setLanguageId( $value ); break; |
|
694
|
|
|
case 'telephone': $item = $item->setTelephone( $value ); break; |
|
695
|
|
|
case 'telefax': $item = $item->setTelefax( $value ); break; |
|
696
|
|
|
case 'email': $item = $item->setEmail( $value ); break; |
|
697
|
|
|
case 'website': $item = $item->setWebsite( $value ); break; |
|
698
|
|
|
case 'longitude': $item = $item->setLongitude( $value ); break; |
|
699
|
|
|
case 'latitude': $item = $item->setLatitude( $value ); break; |
|
700
|
|
|
case 'birthday': $item = $item->setBirthday( $value ); break; |
|
701
|
|
|
case 'position': $item = $item->setPosition( $value ); break; |
|
702
|
|
|
default: continue 2; |
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
unset( $list[$idx] ); |
|
706
|
|
|
} |
|
707
|
|
|
|
|
708
|
|
|
return $item; |
|
709
|
|
|
} |
|
710
|
|
|
|
|
711
|
|
|
|
|
712
|
|
|
/** |
|
713
|
|
|
* Returns the item values as array. |
|
714
|
|
|
* |
|
715
|
|
|
* @param bool True to return private properties, false for public only |
|
716
|
|
|
* @return array Associative list of item properties and their values |
|
717
|
|
|
*/ |
|
718
|
|
|
public function toArray( bool $private = false ) : array |
|
719
|
|
|
{ |
|
720
|
|
|
$list = parent::toArray( $private ); |
|
721
|
|
|
|
|
722
|
|
|
$list[$this->prefix . 'salutation'] = $this->getSalutation(); |
|
723
|
|
|
$list[$this->prefix . 'company'] = $this->getCompany(); |
|
724
|
|
|
$list[$this->prefix . 'vatid'] = $this->getVatID(); |
|
725
|
|
|
$list[$this->prefix . 'title'] = $this->getTitle(); |
|
726
|
|
|
$list[$this->prefix . 'firstname'] = $this->getFirstname(); |
|
727
|
|
|
$list[$this->prefix . 'lastname'] = $this->getLastname(); |
|
728
|
|
|
$list[$this->prefix . 'address1'] = $this->getAddress1(); |
|
729
|
|
|
$list[$this->prefix . 'address2'] = $this->getAddress2(); |
|
730
|
|
|
$list[$this->prefix . 'address3'] = $this->getAddress3(); |
|
731
|
|
|
$list[$this->prefix . 'postal'] = $this->getPostal(); |
|
732
|
|
|
$list[$this->prefix . 'city'] = $this->getCity(); |
|
733
|
|
|
$list[$this->prefix . 'state'] = $this->getState(); |
|
734
|
|
|
$list[$this->prefix . 'countryid'] = $this->getCountryId(); |
|
735
|
|
|
$list[$this->prefix . 'languageid'] = $this->getLanguageId(); |
|
736
|
|
|
$list[$this->prefix . 'telephone'] = $this->getTelephone(); |
|
737
|
|
|
$list[$this->prefix . 'telefax'] = $this->getTelefax(); |
|
738
|
|
|
$list[$this->prefix . 'email'] = $this->getEmail(); |
|
739
|
|
|
$list[$this->prefix . 'website'] = $this->getWebsite(); |
|
740
|
|
|
$list[$this->prefix . 'longitude'] = $this->getLongitude(); |
|
741
|
|
|
$list[$this->prefix . 'latitude'] = $this->getLatitude(); |
|
742
|
|
|
$list[$this->prefix . 'birthday'] = $this->getBirthday(); |
|
743
|
|
|
$list[$this->prefix . 'position'] = $this->getPosition(); |
|
744
|
|
|
|
|
745
|
|
|
if( $private === true ) { |
|
746
|
|
|
$list[$this->prefix . 'parentid'] = $this->getParentId(); |
|
747
|
|
|
} |
|
748
|
|
|
|
|
749
|
|
|
return $list; |
|
750
|
|
|
} |
|
751
|
|
|
|
|
752
|
|
|
|
|
753
|
|
|
/** |
|
754
|
|
|
* Checks the given address salutation is valid |
|
755
|
|
|
* |
|
756
|
|
|
* @param string $value Address salutation defined in \Aimeos\MShop\Common\Item\Address\Base |
|
757
|
|
|
* @throws \Aimeos\MShop\Exception If salutation is invalid |
|
758
|
|
|
*/ |
|
759
|
|
|
protected function checkSalutation( string $value ) |
|
760
|
|
|
{ |
|
761
|
|
|
if( strlen( $value ) > 8 ) { |
|
762
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Address salutation "%1$s" not within allowed range', $value ) ); |
|
763
|
|
|
} |
|
764
|
|
|
|
|
765
|
|
|
return $value; |
|
766
|
|
|
} |
|
767
|
|
|
} |
|
768
|
|
|
|