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