1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2020 |
7
|
|
|
* @package Client |
8
|
|
|
* @subpackage Html |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Client\Html\Checkout\Standard\Address\Billing; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation of checkout billing address HTML client. |
17
|
|
|
* |
18
|
|
|
* @package Client |
19
|
|
|
* @subpackage Html |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\Client\Html\Common\Client\Factory\Base |
23
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
24
|
|
|
{ |
25
|
|
|
/** client/html/checkout/standard/address/billing/standard/subparts |
26
|
|
|
* List of HTML sub-clients rendered within the checkout standard address billing section |
27
|
|
|
* |
28
|
|
|
* The output of the frontend is composed of the code generated by the HTML |
29
|
|
|
* clients. Each HTML client can consist of serveral (or none) sub-clients |
30
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
31
|
|
|
* sub-clients can contain HTML clients themselves and therefore a |
32
|
|
|
* hierarchical tree of HTML clients is composed. Each HTML client creates |
33
|
|
|
* the output that is placed inside the container of its parent. |
34
|
|
|
* |
35
|
|
|
* At first, always the HTML code generated by the parent is printed, then |
36
|
|
|
* the HTML code of its sub-clients. The order of the HTML sub-clients |
37
|
|
|
* determines the order of the output of these sub-clients inside the parent |
38
|
|
|
* container. If the configured list of clients is |
39
|
|
|
* |
40
|
|
|
* array( "subclient1", "subclient2" ) |
41
|
|
|
* |
42
|
|
|
* you can easily change the order of the output by reordering the subparts: |
43
|
|
|
* |
44
|
|
|
* client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
45
|
|
|
* |
46
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
47
|
|
|
* |
48
|
|
|
* client/html/<clients>/subparts = array( "subclient1" ) |
49
|
|
|
* |
50
|
|
|
* As the clients only generates structural HTML, the layout defined via CSS |
51
|
|
|
* should support adding, removing or reordering content by a fluid like |
52
|
|
|
* design. |
53
|
|
|
* |
54
|
|
|
* @param array List of sub-client names |
55
|
|
|
* @since 2014.03 |
56
|
|
|
* @category Developer |
57
|
|
|
*/ |
58
|
|
|
private $subPartPath = 'client/html/checkout/standard/address/billing/standard/subparts'; |
59
|
|
|
private $subPartNames = []; |
60
|
|
|
|
61
|
|
|
private $mandatory = array( |
62
|
|
|
'order.base.address.salutation', |
63
|
|
|
'order.base.address.firstname', |
64
|
|
|
'order.base.address.lastname', |
65
|
|
|
'order.base.address.address1', |
66
|
|
|
'order.base.address.postal', |
67
|
|
|
'order.base.address.city', |
68
|
|
|
'order.base.address.languageid', |
69
|
|
|
'order.base.address.email' |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
private $optional = array( |
73
|
|
|
'order.base.address.company', |
74
|
|
|
'order.base.address.vatid', |
75
|
|
|
'order.base.address.address2', |
76
|
|
|
'order.base.address.countryid', |
77
|
|
|
'order.base.address.state', |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the HTML code for insertion into the body. |
83
|
|
|
* |
84
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
85
|
|
|
* @return string HTML code |
86
|
|
|
*/ |
87
|
|
|
public function getBody( string $uid = '' ) : string |
88
|
|
|
{ |
89
|
|
|
$view = $this->getView(); |
90
|
|
|
|
91
|
|
|
$html = ''; |
92
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
93
|
|
|
$html .= $subclient->setView( $view )->getBody( $uid ); |
94
|
|
|
} |
95
|
|
|
$view->billingBody = $html; |
96
|
|
|
|
97
|
|
|
/** client/html/checkout/standard/address/billing/standard/template-body |
98
|
|
|
* Relative path to the HTML body template of the checkout standard address billing client. |
99
|
|
|
* |
100
|
|
|
* The template file contains the HTML code and processing instructions |
101
|
|
|
* to generate the result shown in the body of the frontend. The |
102
|
|
|
* configuration string is the path to the template file relative |
103
|
|
|
* to the templates directory (usually in client/html/templates). |
104
|
|
|
* |
105
|
|
|
* You can overwrite the template file configuration in extensions and |
106
|
|
|
* provide alternative templates. These alternative templates should be |
107
|
|
|
* named like the default one but with the string "standard" replaced by |
108
|
|
|
* an unique name. You may use the name of your project for this. If |
109
|
|
|
* you've implemented an alternative client class as well, "standard" |
110
|
|
|
* should be replaced by the name of the new class. |
111
|
|
|
* |
112
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
113
|
|
|
* @since 2014.03 |
114
|
|
|
* @category Developer |
115
|
|
|
* @see client/html/checkout/standard/address/billing/standard/template-header |
116
|
|
|
*/ |
117
|
|
|
$tplconf = 'client/html/checkout/standard/address/billing/standard/template-body'; |
118
|
|
|
$default = 'checkout/standard/address-billing-body-standard'; |
119
|
|
|
|
120
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the sub-client given by its name. |
126
|
|
|
* |
127
|
|
|
* @param string $type Name of the client type |
128
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
129
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
130
|
|
|
*/ |
131
|
|
|
public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface |
132
|
|
|
{ |
133
|
|
|
/** client/html/checkout/standard/address/billing/decorators/excludes |
134
|
|
|
* Excludes decorators added by the "common" option from the checkout standard address billing html client |
135
|
|
|
* |
136
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
137
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
138
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
139
|
|
|
* modify what is returned to the caller. |
140
|
|
|
* |
141
|
|
|
* This option allows you to remove a decorator added via |
142
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
143
|
|
|
* around the html client. |
144
|
|
|
* |
145
|
|
|
* client/html/checkout/standard/address/billing/decorators/excludes = array( 'decorator1' ) |
146
|
|
|
* |
147
|
|
|
* This would remove the decorator named "decorator1" from the list of |
148
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
149
|
|
|
* "client/html/common/decorators/default" to the html client. |
150
|
|
|
* |
151
|
|
|
* @param array List of decorator names |
152
|
|
|
* @since 2015.08 |
153
|
|
|
* @category Developer |
154
|
|
|
* @see client/html/common/decorators/default |
155
|
|
|
* @see client/html/checkout/standard/address/billing/decorators/global |
156
|
|
|
* @see client/html/checkout/standard/address/billing/decorators/local |
157
|
|
|
*/ |
158
|
|
|
|
159
|
|
|
/** client/html/checkout/standard/address/billing/decorators/global |
160
|
|
|
* Adds a list of globally available decorators only to the checkout standard address billing html client |
161
|
|
|
* |
162
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
163
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
164
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
165
|
|
|
* modify what is returned to the caller. |
166
|
|
|
* |
167
|
|
|
* This option allows you to wrap global decorators |
168
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
169
|
|
|
* |
170
|
|
|
* client/html/checkout/standard/address/billing/decorators/global = array( 'decorator1' ) |
171
|
|
|
* |
172
|
|
|
* This would add the decorator named "decorator1" defined by |
173
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
174
|
|
|
* |
175
|
|
|
* @param array List of decorator names |
176
|
|
|
* @since 2015.08 |
177
|
|
|
* @category Developer |
178
|
|
|
* @see client/html/common/decorators/default |
179
|
|
|
* @see client/html/checkout/standard/address/billing/decorators/excludes |
180
|
|
|
* @see client/html/checkout/standard/address/billing/decorators/local |
181
|
|
|
*/ |
182
|
|
|
|
183
|
|
|
/** client/html/checkout/standard/address/billing/decorators/local |
184
|
|
|
* Adds a list of local decorators only to the checkout standard address billing html client |
185
|
|
|
* |
186
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
187
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
188
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
189
|
|
|
* modify what is returned to the caller. |
190
|
|
|
* |
191
|
|
|
* This option allows you to wrap local decorators |
192
|
|
|
* ("\Aimeos\Client\Html\Checkout\Decorator\*") around the html client. |
193
|
|
|
* |
194
|
|
|
* client/html/checkout/standard/address/billing/decorators/local = array( 'decorator2' ) |
195
|
|
|
* |
196
|
|
|
* This would add the decorator named "decorator2" defined by |
197
|
|
|
* "\Aimeos\Client\Html\Checkout\Decorator\Decorator2" only to the html client. |
198
|
|
|
* |
199
|
|
|
* @param array List of decorator names |
200
|
|
|
* @since 2015.08 |
201
|
|
|
* @category Developer |
202
|
|
|
* @see client/html/common/decorators/default |
203
|
|
|
* @see client/html/checkout/standard/address/billing/decorators/excludes |
204
|
|
|
* @see client/html/checkout/standard/address/billing/decorators/global |
205
|
|
|
*/ |
206
|
|
|
|
207
|
|
|
return $this->createSubClient( 'checkout/standard/address/billing/' . $type, $name ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Stores the given or fetched billing address in the basket. |
213
|
|
|
* |
214
|
|
|
* A view must be available and this method doesn't generate any output |
215
|
|
|
* besides setting view variables if necessary. |
216
|
|
|
*/ |
217
|
|
|
public function process() |
218
|
|
|
{ |
219
|
|
|
$view = $this->getView(); |
220
|
|
|
|
221
|
|
|
try |
222
|
|
|
{ |
223
|
|
|
// only start if there's something to do |
224
|
|
|
if( $view->param( 'ca_billingoption', null ) === null ) { |
225
|
|
|
return; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$this->setAddress( $view ); |
229
|
|
|
|
230
|
|
|
parent::process(); |
231
|
|
|
} |
232
|
|
|
catch( \Aimeos\Controller\Frontend\Exception $e ) |
233
|
|
|
{ |
234
|
|
|
$view->billingError = $e->getErrorList(); |
235
|
|
|
throw $e; |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Sets the necessary parameter values in the view. |
242
|
|
|
* |
243
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
244
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
245
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
246
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
247
|
|
|
*/ |
248
|
|
|
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
249
|
|
|
{ |
250
|
|
|
$context = $this->getContext(); |
251
|
|
|
$basketCntl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); |
252
|
|
|
|
253
|
|
|
$addr = current( $basketCntl->get()->getAddress( 'payment' ) ); |
254
|
|
|
|
255
|
|
|
$values = $addr ? $addr->toArray() : []; |
256
|
|
|
$id = $view->get( 'addressCustomerItem' ) ? $view->addressCustomerItem->getId() : 'null'; |
257
|
|
|
$id = $values['order.base.address.addressid'] ?? $id; |
258
|
|
|
|
259
|
|
|
$view->billingAddressString = $addr ? $this->getAddressString( $view, $addr ) : ''; |
260
|
|
|
$view->billingValuesNew = array_merge( $values, $view->param( 'ca_billing', [] ) ); |
261
|
|
|
$view->billingValues = array_merge( $values, $view->param( 'ca_billing_' . $id, [] ) ); |
262
|
|
|
$view->billingOption = $view->param( 'ca_billingoption', $id ); |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/** client/html/checkout/standard/address/billing/salutations |
266
|
|
|
* List of salutions the customer can select from for the billing address |
267
|
|
|
* |
268
|
|
|
* The following salutations are available: |
269
|
|
|
* * empty string for "unknown" |
270
|
|
|
* * company |
271
|
|
|
* * mr |
272
|
|
|
* * mrs |
273
|
|
|
* * miss |
274
|
|
|
* |
275
|
|
|
* You can modify the list of salutation codes and remove the ones |
276
|
|
|
* which shouldn't be used. Adding new salutations is a little bit |
277
|
|
|
* more difficult because you have to adapt a few areas in the source |
278
|
|
|
* code. |
279
|
|
|
* |
280
|
|
|
* Until 2015-02, the configuration option was available as |
281
|
|
|
* "client/html/common/address/billing/salutations" starting from 2014-03. |
282
|
|
|
* |
283
|
|
|
* @param array List of available salutation codes |
284
|
|
|
* @since 2015.02 |
285
|
|
|
* @category User |
286
|
|
|
* @category Developer |
287
|
|
|
* @see client/html/checkout/standard/address/billing/disable-new |
288
|
|
|
* @see client/html/checkout/standard/address/billing/mandatory |
289
|
|
|
* @see client/html/checkout/standard/address/billing/optional |
290
|
|
|
* @see client/html/checkout/standard/address/billing/hidden |
291
|
|
|
* @see client/html/checkout/standard/address/countries |
292
|
|
|
*/ |
293
|
|
|
$salutations = array( 'company', 'mr', 'mrs' ); |
294
|
|
|
$view->billingSalutations = $view->config( 'client/html/checkout/standard/address/billing/salutations', $salutations ); |
295
|
|
|
|
296
|
|
|
$mandatory = $view->config( 'client/html/checkout/standard/address/billing/mandatory', $this->mandatory ); |
297
|
|
|
$optional = $view->config( 'client/html/checkout/standard/address/billing/optional', $this->optional ); |
298
|
|
|
$hidden = $view->config( 'client/html/checkout/standard/address/billing/hidden', [] ); |
299
|
|
|
|
300
|
|
|
foreach( $mandatory as $name ) { |
301
|
|
|
$css[$name][] = 'mandatory'; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
foreach( $optional as $name ) { |
305
|
|
|
$css[$name][] = 'optional'; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
foreach( $hidden as $name ) { |
309
|
|
|
$css[$name][] = 'hidden'; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
$view->billingMandatory = $mandatory; |
313
|
|
|
$view->billingOptional = $optional; |
314
|
|
|
$view->billingHidden = $hidden; |
315
|
|
|
$view->billingCss = $css; |
|
|
|
|
316
|
|
|
|
317
|
|
|
return parent::addData( $view, $tags, $expire ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Checks the address fields for missing data and sanitizes the given parameter list. |
323
|
|
|
* |
324
|
|
|
* @param array &$params Associative list of address keys (order.base.address.* or customer.address.*) and their values |
325
|
|
|
* @return array List of missing field names |
326
|
|
|
*/ |
327
|
|
|
protected function checkFields( array &$params ) : array |
328
|
|
|
{ |
329
|
|
|
$view = $this->getView(); |
330
|
|
|
|
331
|
|
|
/** client/html/checkout/standard/address/billing/mandatory |
332
|
|
|
* List of billing address input fields that are required |
333
|
|
|
* |
334
|
|
|
* You can configure the list of billing address fields that are |
335
|
|
|
* necessary and must be filled by the customer before he can |
336
|
|
|
* continue the checkout process. Available field keys are: |
337
|
|
|
* * order.base.address.company |
338
|
|
|
* * order.base.address.vatid |
339
|
|
|
* * order.base.address.salutation |
340
|
|
|
* * order.base.address.firstname |
341
|
|
|
* * order.base.address.lastname |
342
|
|
|
* * order.base.address.address1 |
343
|
|
|
* * order.base.address.address2 |
344
|
|
|
* * order.base.address.address3 |
345
|
|
|
* * order.base.address.postal |
346
|
|
|
* * order.base.address.city |
347
|
|
|
* * order.base.address.state |
348
|
|
|
* * order.base.address.languageid |
349
|
|
|
* * order.base.address.countryid |
350
|
|
|
* * order.base.address.telephone |
351
|
|
|
* * order.base.address.telefax |
352
|
|
|
* * order.base.address.email |
353
|
|
|
* * order.base.address.website |
354
|
|
|
* |
355
|
|
|
* Until 2015-02, the configuration option was available as |
356
|
|
|
* "client/html/common/address/billing/mandatory" starting from 2014-03. |
357
|
|
|
* |
358
|
|
|
* @param array List of field keys |
359
|
|
|
* @since 2015.02 |
360
|
|
|
* @category User |
361
|
|
|
* @category Developer |
362
|
|
|
* @see client/html/checkout/standard/address/billing/disable-new |
363
|
|
|
* @see client/html/checkout/standard/address/billing/salutations |
364
|
|
|
* @see client/html/checkout/standard/address/billing/optional |
365
|
|
|
* @see client/html/checkout/standard/address/billing/hidden |
366
|
|
|
* @see client/html/checkout/standard/address/countries |
367
|
|
|
* @see client/html/checkout/standard/address/validate |
368
|
|
|
*/ |
369
|
|
|
$mandatory = $view->config( 'client/html/checkout/standard/address/billing/mandatory', $this->mandatory ); |
370
|
|
|
|
371
|
|
|
/** client/html/checkout/standard/address/billing/optional |
372
|
|
|
* List of billing address input fields that are optional |
373
|
|
|
* |
374
|
|
|
* You can configure the list of billing address fields that |
375
|
|
|
* customers can fill but don't have to before they can |
376
|
|
|
* continue the checkout process. Available field keys are: |
377
|
|
|
* * order.base.address.company |
378
|
|
|
* * order.base.address.vatid |
379
|
|
|
* * order.base.address.salutation |
380
|
|
|
* * order.base.address.firstname |
381
|
|
|
* * order.base.address.lastname |
382
|
|
|
* * order.base.address.address1 |
383
|
|
|
* * order.base.address.address2 |
384
|
|
|
* * order.base.address.address3 |
385
|
|
|
* * order.base.address.postal |
386
|
|
|
* * order.base.address.city |
387
|
|
|
* * order.base.address.state |
388
|
|
|
* * order.base.address.languageid |
389
|
|
|
* * order.base.address.countryid |
390
|
|
|
* * order.base.address.telephone |
391
|
|
|
* * order.base.address.telefax |
392
|
|
|
* * order.base.address.email |
393
|
|
|
* * order.base.address.website |
394
|
|
|
* |
395
|
|
|
* Until 2015-02, the configuration option was available as |
396
|
|
|
* "client/html/common/address/billing/optional" starting from 2014-03. |
397
|
|
|
* |
398
|
|
|
* @param array List of field keys |
399
|
|
|
* @since 2015.02 |
400
|
|
|
* @category User |
401
|
|
|
* @category Developer |
402
|
|
|
* @see client/html/checkout/standard/address/billing/disable-new |
403
|
|
|
* @see client/html/checkout/standard/address/billing/salutations |
404
|
|
|
* @see client/html/checkout/standard/address/billing/mandatory |
405
|
|
|
* @see client/html/checkout/standard/address/billing/hidden |
406
|
|
|
* @see client/html/checkout/standard/address/countries |
407
|
|
|
* @see client/html/checkout/standard/address/validate |
408
|
|
|
*/ |
409
|
|
|
$optional = $view->config( 'client/html/checkout/standard/address/billing/optional', $this->optional ); |
410
|
|
|
|
411
|
|
|
/** client/html/checkout/standard/address/billing/hidden |
412
|
|
|
* List of billing address input fields that are optional and should be hidden |
413
|
|
|
* |
414
|
|
|
* You can configure the list of billing address fields that |
415
|
|
|
* are hidden when a customer enters his new billing address. |
416
|
|
|
* Available field keys are: |
417
|
|
|
* * order.base.address.company |
418
|
|
|
* * order.base.address.vatid |
419
|
|
|
* * order.base.address.salutation |
420
|
|
|
* * order.base.address.firstname |
421
|
|
|
* * order.base.address.lastname |
422
|
|
|
* * order.base.address.address1 |
423
|
|
|
* * order.base.address.address2 |
424
|
|
|
* * order.base.address.address3 |
425
|
|
|
* * order.base.address.postal |
426
|
|
|
* * order.base.address.city |
427
|
|
|
* * order.base.address.state |
428
|
|
|
* * order.base.address.languageid |
429
|
|
|
* * order.base.address.countryid |
430
|
|
|
* * order.base.address.telephone |
431
|
|
|
* * order.base.address.telefax |
432
|
|
|
* * order.base.address.email |
433
|
|
|
* * order.base.address.website |
434
|
|
|
* |
435
|
|
|
* Caution: Only hide fields that don't require any input |
436
|
|
|
* |
437
|
|
|
* Until 2015-02, the configuration option was available as |
438
|
|
|
* "client/html/common/address/billing/hidden" starting from 2014-03. |
439
|
|
|
* |
440
|
|
|
* @param array List of field keys |
441
|
|
|
* @since 2015.02 |
442
|
|
|
* @category User |
443
|
|
|
* @category Developer |
444
|
|
|
* @see client/html/checkout/standard/address/billing/disable-new |
445
|
|
|
* @see client/html/checkout/standard/address/billing/salutations |
446
|
|
|
* @see client/html/checkout/standard/address/billing/mandatory |
447
|
|
|
* @see client/html/checkout/standard/address/billing/optional |
448
|
|
|
* @see client/html/checkout/standard/address/countries |
449
|
|
|
*/ |
450
|
|
|
$hidden = $view->config( 'client/html/checkout/standard/address/billing/hidden', [] ); |
451
|
|
|
|
452
|
|
|
/** client/html/checkout/standard/address/validate |
453
|
|
|
* List of regular expressions to validate the data of the address fields |
454
|
|
|
* |
455
|
|
|
* To validate the address input data of the customer, an individual |
456
|
|
|
* {@link http://php.net/manual/en/pcre.pattern.php Perl compatible regular expression} |
457
|
|
|
* can be applied to each field. Available fields are: |
458
|
|
|
* * company |
459
|
|
|
* * vatid |
460
|
|
|
* * salutation |
461
|
|
|
* * firstname |
462
|
|
|
* * lastname |
463
|
|
|
* * address1 |
464
|
|
|
* * address2 |
465
|
|
|
* * address3 |
466
|
|
|
* * postal |
467
|
|
|
* * city |
468
|
|
|
* * state |
469
|
|
|
* * languageid |
470
|
|
|
* * countryid |
471
|
|
|
* * telephone |
472
|
|
|
* * telefax |
473
|
|
|
* * email |
474
|
|
|
* * website |
475
|
|
|
* |
476
|
|
|
* Some fields are validated automatically because they are not |
477
|
|
|
* dependent on a country specific rule. These fields are: |
478
|
|
|
* * salutation |
479
|
|
|
* * email |
480
|
|
|
* * website |
481
|
|
|
* |
482
|
|
|
* To validate e.g the postal/zip code, you can define a regular |
483
|
|
|
* expression like this if you want to allow only digits: |
484
|
|
|
* |
485
|
|
|
* client/html/checkout/standard/address/validate/postal = '^[0-9]+$' |
486
|
|
|
* |
487
|
|
|
* Several regular expressions can be defined line this: |
488
|
|
|
* |
489
|
|
|
* client/html/checkout/standard/address/validate = array( |
490
|
|
|
* 'postal' = '^[0-9]+$', |
491
|
|
|
* 'vatid' = '^[A-Z]{2}[0-9]{8}$', |
492
|
|
|
* ) |
493
|
|
|
* |
494
|
|
|
* Don't add any delimiting characters like slashes (/) to the beginning |
495
|
|
|
* or the end of the regular expression. They will be added automatically. |
496
|
|
|
* Any slashes inside the expression must be escaped by backlashes, |
497
|
|
|
* i.e. "\/". |
498
|
|
|
* |
499
|
|
|
* Until 2015-02, the configuration option was available as |
500
|
|
|
* "client/html/common/address/billing/validate" starting from 2014-09. |
501
|
|
|
* |
502
|
|
|
* @param array Associative list of field names and regular expressions |
503
|
|
|
* @since 2014.09 |
504
|
|
|
* @category Developer |
505
|
|
|
* @see client/html/checkout/standard/address/billing/mandatory |
506
|
|
|
* @see client/html/checkout/standard/address/billing/optional |
507
|
|
|
*/ |
508
|
|
|
|
509
|
|
|
$allFields = array_flip( array_merge( $mandatory, $optional, $hidden ) ); |
510
|
|
|
$invalid = $this->validateFields( $params, $allFields ); |
511
|
|
|
$this->checkSalutation( $params, $mandatory ); |
512
|
|
|
|
513
|
|
|
foreach( $invalid as $key => $name ) |
514
|
|
|
{ |
515
|
|
|
$msg = $view->translate( 'client', 'Billing address part "%1$s" is invalid' ); |
516
|
|
|
$invalid[$key] = sprintf( $msg, $name ); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
foreach( $mandatory as $key ) |
520
|
|
|
{ |
521
|
|
|
if( !isset( $params[$key] ) || $params[$key] == '' ) |
522
|
|
|
{ |
523
|
|
|
$msg = $view->translate( 'client', 'Billing address part "%1$s" is missing' ); |
524
|
|
|
$invalid[$key] = sprintf( $msg, substr( $key, 19 ) ); |
525
|
|
|
unset( $params[$key] ); |
526
|
|
|
} |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
return $invalid; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Additional checks for the salutation |
535
|
|
|
* |
536
|
|
|
* @param array &$params Associative list of address keys (order.base.address.* or customer.address.*) and their values |
537
|
|
|
* @param array &$mandatory List of mandatory field names |
538
|
|
|
* @since 2016.05 |
539
|
|
|
*/ |
540
|
|
|
protected function checkSalutation( array &$params, array &$mandatory ) |
541
|
|
|
{ |
542
|
|
|
if( isset( $params['order.base.address.salutation'] ) |
543
|
|
|
&& $params['order.base.address.salutation'] === \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY |
544
|
|
|
&& in_array( 'order.base.address.company', $mandatory ) === false |
545
|
|
|
) { |
546
|
|
|
$mandatory[] = 'order.base.address.company'; |
547
|
|
|
} |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
|
551
|
|
|
/** |
552
|
|
|
* Returns the address as string |
553
|
|
|
* |
554
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
555
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Address\Iface $addr Order address item |
556
|
|
|
* @return string Address as string |
557
|
|
|
*/ |
558
|
|
|
protected function getAddressString( \Aimeos\MW\View\Iface $view, \Aimeos\MShop\Order\Item\Base\Address\Iface $addr ) |
559
|
|
|
{ |
560
|
|
|
return preg_replace( "/\n+/m", "\n", trim( sprintf( |
561
|
|
|
/// Address format with company (%1$s), salutation (%2$s), title (%3$s), first name (%4$s), last name (%5$s), |
562
|
|
|
/// address part one (%6$s, e.g street), address part two (%7$s, e.g house number), address part three (%8$s, e.g additional information), |
563
|
|
|
/// postal/zip code (%9$s), city (%10$s), state (%11$s), country (%12$s), language (%13$s), |
564
|
|
|
/// e-mail (%14$s), phone (%15$s), facsimile/telefax (%16$s), web site (%17$s), vatid (%18$s) |
565
|
|
|
$view->translate( 'client', '%1$s |
566
|
|
|
%2$s %3$s %4$s %5$s |
567
|
|
|
%6$s %7$s |
568
|
|
|
%8$s |
569
|
|
|
%9$s %10$s |
570
|
|
|
%11$s |
571
|
|
|
%12$s |
572
|
|
|
%13$s |
573
|
|
|
%14$s |
574
|
|
|
%15$s |
575
|
|
|
%16$s |
576
|
|
|
%17$s |
577
|
|
|
%18$s |
578
|
|
|
' |
579
|
|
|
), |
580
|
|
|
$addr->getCompany(), |
581
|
|
|
$view->translate( 'mshop/code', (string) $addr->getSalutation() ), |
582
|
|
|
$addr->getTitle(), |
583
|
|
|
$addr->getFirstName(), |
584
|
|
|
$addr->getLastName(), |
585
|
|
|
$addr->getAddress1(), |
586
|
|
|
$addr->getAddress2(), |
587
|
|
|
$addr->getAddress3(), |
588
|
|
|
$addr->getPostal(), |
589
|
|
|
$addr->getCity(), |
590
|
|
|
$addr->getState(), |
591
|
|
|
$view->translate( 'country', (string) $addr->getCountryId() ), |
592
|
|
|
$view->translate( 'language', (string) $addr->getLanguageId() ), |
593
|
|
|
$addr->getEmail(), |
594
|
|
|
$addr->getTelephone(), |
595
|
|
|
$addr->getTelefax(), |
596
|
|
|
$addr->getWebsite(), |
597
|
|
|
$addr->getVatID() |
598
|
|
|
) ) ); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* Returns the list of sub-client names configured for the client. |
604
|
|
|
* |
605
|
|
|
* @return array List of HTML client names |
606
|
|
|
*/ |
607
|
|
|
protected function getSubClientNames() : array |
608
|
|
|
{ |
609
|
|
|
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Sets the new address |
615
|
|
|
* |
616
|
|
|
* @param \Aimeos\MW\View\Iface $view View object |
617
|
|
|
* @throws \Aimeos\Client\Html\Exception If an error occurs |
618
|
|
|
* @since 2016.05 |
619
|
|
|
*/ |
620
|
|
|
protected function setAddress( \Aimeos\MW\View\Iface $view ) |
621
|
|
|
{ |
622
|
|
|
$context = $this->getContext(); |
623
|
|
|
$basketCtrl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); |
624
|
|
|
|
625
|
|
|
|
626
|
|
|
/** client/html/checkout/standard/address/billing/disable-new |
627
|
|
|
* Disables the option to enter a new billing address for an order |
628
|
|
|
* |
629
|
|
|
* Besides the main billing address, customers can usually enter a new |
630
|
|
|
* billing address as well. To suppress displaying the form fields for |
631
|
|
|
* a billing address, you can set this configuration option to "1". |
632
|
|
|
* |
633
|
|
|
* Until 2015-02, the configuration option was available as |
634
|
|
|
* "client/html/common/address/billing/disable-new" starting from 2014-03. |
635
|
|
|
* |
636
|
|
|
* @param boolean A value of "1" to disable, "0" enables the billing address form |
637
|
|
|
* @since 2015.02 |
638
|
|
|
* @category User |
639
|
|
|
* @category Developer |
640
|
|
|
* @see client/html/checkout/standard/address/billing/salutations |
641
|
|
|
* @see client/html/checkout/standard/address/billing/mandatory |
642
|
|
|
* @see client/html/checkout/standard/address/billing/optional |
643
|
|
|
* @see client/html/checkout/standard/address/billing/hidden |
644
|
|
|
*/ |
645
|
|
|
$disable = $view->config( 'client/html/checkout/standard/address/billing/disable-new', false ); |
646
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT; |
647
|
|
|
|
648
|
|
|
if( ( $option = $view->param( 'ca_billingoption', 'null' ) ) === 'null' && $disable === false ) // new address |
649
|
|
|
{ |
650
|
|
|
$params = $view->param( 'ca_billing', [] ); |
651
|
|
|
|
652
|
|
|
if( ( $view->billingError = $this->checkFields( $params ) ) !== [] ) { |
653
|
|
|
throw new \Aimeos\Client\Html\Exception( sprintf( 'At least one billing address part is missing or invalid' ) ); |
654
|
|
|
} |
655
|
|
|
} |
656
|
|
|
else // existing address |
657
|
|
|
{ |
658
|
|
|
$params = $view->param( 'ca_billing_' . $option, [] ) + $view->param( 'ca_extra', [] ); |
659
|
|
|
|
660
|
|
|
if( !empty( $params ) && ( $view->billingError = $this->checkFields( $params ) ) !== [] ) { |
661
|
|
|
throw new \Aimeos\Client\Html\Exception( sprintf( 'At least one billing address part is missing or invalid' ) ); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' )->uses( [] ); |
665
|
|
|
$params = $cntl->add( $params )->store()->get()->getPaymentAddress()->toArray(); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
$basketCtrl->addAddress( $type, $params, 0 ); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* Validate the address key/value pairs using regular expressions |
674
|
|
|
* |
675
|
|
|
* @param array &$params Associative list of address keys (order.base.address.* or customer.address.*) and their values |
676
|
|
|
* @param array $fields List of field names to validate |
677
|
|
|
* @return array List of invalid address keys |
678
|
|
|
* @since 2016.05 |
679
|
|
|
*/ |
680
|
|
|
protected function validateFields( array &$params, array $fields ) : array |
681
|
|
|
{ |
682
|
|
|
$config = $this->getContext()->getConfig(); |
683
|
|
|
|
684
|
|
|
/** client/html/checkout/standard/address/validate/company |
685
|
|
|
* Regular expression to check the "company" address value |
686
|
|
|
* |
687
|
|
|
* @see client/html/checkout/standard/address/validate |
688
|
|
|
*/ |
689
|
|
|
|
690
|
|
|
/** client/html/checkout/standard/address/validate/vatid |
691
|
|
|
* Regular expression to check the "vatid" address value |
692
|
|
|
* |
693
|
|
|
* @see client/html/checkout/standard/address/validate |
694
|
|
|
*/ |
695
|
|
|
|
696
|
|
|
/** client/html/checkout/standard/address/validate/salutation |
697
|
|
|
* Regular expression to check the "salutation" address value |
698
|
|
|
* |
699
|
|
|
* @see client/html/checkout/standard/address/validate |
700
|
|
|
*/ |
701
|
|
|
|
702
|
|
|
/** client/html/checkout/standard/address/validate/firstname |
703
|
|
|
* Regular expression to check the "firstname" address value |
704
|
|
|
* |
705
|
|
|
* @see client/html/checkout/standard/address/validate |
706
|
|
|
*/ |
707
|
|
|
|
708
|
|
|
/** client/html/checkout/standard/address/validate/lastname |
709
|
|
|
* Regular expression to check the "lastname" address value |
710
|
|
|
* |
711
|
|
|
* @see client/html/checkout/standard/address/validate |
712
|
|
|
*/ |
713
|
|
|
|
714
|
|
|
/** client/html/checkout/standard/address/validate/address1 |
715
|
|
|
* Regular expression to check the "address1" address value |
716
|
|
|
* |
717
|
|
|
* @see client/html/checkout/standard/address/validate |
718
|
|
|
*/ |
719
|
|
|
|
720
|
|
|
/** client/html/checkout/standard/address/validate/address2 |
721
|
|
|
* Regular expression to check the "address2" address value |
722
|
|
|
* |
723
|
|
|
* @see client/html/checkout/standard/address/validate |
724
|
|
|
*/ |
725
|
|
|
|
726
|
|
|
/** client/html/checkout/standard/address/validate/address3 |
727
|
|
|
* Regular expression to check the "address3" address value |
728
|
|
|
* |
729
|
|
|
* @see client/html/checkout/standard/address/validate |
730
|
|
|
*/ |
731
|
|
|
|
732
|
|
|
/** client/html/checkout/standard/address/validate/postal |
733
|
|
|
* Regular expression to check the "postal" address value |
734
|
|
|
* |
735
|
|
|
* @see client/html/checkout/standard/address/validate |
736
|
|
|
*/ |
737
|
|
|
|
738
|
|
|
/** client/html/checkout/standard/address/validate/city |
739
|
|
|
* Regular expression to check the "city" address value |
740
|
|
|
* |
741
|
|
|
* @see client/html/checkout/standard/address/validate |
742
|
|
|
*/ |
743
|
|
|
|
744
|
|
|
/** client/html/checkout/standard/address/validate/state |
745
|
|
|
* Regular expression to check the "state" address value |
746
|
|
|
* |
747
|
|
|
* @see client/html/checkout/standard/address/validate |
748
|
|
|
*/ |
749
|
|
|
|
750
|
|
|
/** client/html/checkout/standard/address/validate/languageid |
751
|
|
|
* Regular expression to check the "languageid" address value |
752
|
|
|
* |
753
|
|
|
* @see client/html/checkout/standard/address/validate |
754
|
|
|
*/ |
755
|
|
|
|
756
|
|
|
/** client/html/checkout/standard/address/validate/countryid |
757
|
|
|
* Regular expression to check the "countryid" address value |
758
|
|
|
* |
759
|
|
|
* @see client/html/checkout/standard/address/validate |
760
|
|
|
*/ |
761
|
|
|
|
762
|
|
|
/** client/html/checkout/standard/address/validate/telephone |
763
|
|
|
* Regular expression to check the "telephone" address value |
764
|
|
|
* |
765
|
|
|
* @see client/html/checkout/standard/address/validate |
766
|
|
|
*/ |
767
|
|
|
|
768
|
|
|
/** client/html/checkout/standard/address/validate/telefax |
769
|
|
|
* Regular expression to check the "telefax" address value |
770
|
|
|
* |
771
|
|
|
* @see client/html/checkout/standard/address/validate |
772
|
|
|
*/ |
773
|
|
|
|
774
|
|
|
/** client/html/checkout/standard/address/validate/email |
775
|
|
|
* Regular expression to check the "email" address value |
776
|
|
|
* |
777
|
|
|
* @see client/html/checkout/standard/address/validate |
778
|
|
|
*/ |
779
|
|
|
|
780
|
|
|
/** client/html/checkout/standard/address/validate/website |
781
|
|
|
* Regular expression to check the "website" address value |
782
|
|
|
* |
783
|
|
|
* @see client/html/checkout/standard/address/validate |
784
|
|
|
*/ |
785
|
|
|
|
786
|
|
|
$invalid = []; |
787
|
|
|
|
788
|
|
|
foreach( $params as $key => $value ) |
789
|
|
|
{ |
790
|
|
|
if( isset( $fields[$key] ) ) |
791
|
|
|
{ |
792
|
|
|
$name = substr( $key, 19 ); |
793
|
|
|
$regex = $config->get( 'client/html/checkout/standard/address/validate/' . $name ); |
794
|
|
|
|
795
|
|
|
if( $regex && preg_match( '/' . $regex . '/', $value ) !== 1 ) |
796
|
|
|
{ |
797
|
|
|
$invalid[$key] = $name; |
798
|
|
|
unset( $params[$key] ); |
799
|
|
|
} |
800
|
|
|
} |
801
|
|
|
else |
802
|
|
|
{ |
803
|
|
|
unset( $params[$key] ); |
804
|
|
|
} |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
return $invalid; |
808
|
|
|
} |
809
|
|
|
} |
810
|
|
|
|