|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
|
5
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
|
7
|
|
|
* @package Client |
|
8
|
|
|
* @subpackage Html |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\Client\Html\Checkout\Standard\Address\Delivery; |
|
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/delivery/standard/subparts |
|
26
|
|
|
* List of HTML sub-clients rendered within the checkout standard address delivery 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/delivery/standard/subparts'; |
|
59
|
|
|
private $subPartNames = array(); |
|
60
|
|
|
private $cache; |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
private $mandatory = array( |
|
63
|
|
|
'order.base.address.salutation', |
|
64
|
|
|
'order.base.address.firstname', |
|
65
|
|
|
'order.base.address.lastname', |
|
66
|
|
|
'order.base.address.address1', |
|
67
|
|
|
'order.base.address.postal', |
|
68
|
|
|
'order.base.address.city', |
|
69
|
|
|
'order.base.address.languageid', |
|
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
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
86
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
87
|
|
|
* @return string HTML code |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getBody( $uid = '', array &$tags = array(), &$expire = null ) |
|
90
|
|
|
{ |
|
91
|
|
|
$view = $this->setViewParams( $this->getView(), $tags, $expire ); |
|
92
|
|
|
|
|
93
|
|
|
$html = ''; |
|
94
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
|
95
|
|
|
$html .= $subclient->setView( $view )->getBody( $uid, $tags, $expire ); |
|
96
|
|
|
} |
|
97
|
|
|
$view->deliveryBody = $html; |
|
98
|
|
|
|
|
99
|
|
|
/** client/html/checkout/standard/address/delivery/standard/template-body |
|
100
|
|
|
* Relative path to the HTML body template of the checkout standard address delivery client. |
|
101
|
|
|
* |
|
102
|
|
|
* The template file contains the HTML code and processing instructions |
|
103
|
|
|
* to generate the result shown in the body of the frontend. The |
|
104
|
|
|
* configuration string is the path to the template file relative |
|
105
|
|
|
* to the templates directory (usually in client/html/templates). |
|
106
|
|
|
* |
|
107
|
|
|
* You can overwrite the template file configuration in extensions and |
|
108
|
|
|
* provide alternative templates. These alternative templates should be |
|
109
|
|
|
* named like the default one but with the string "standard" replaced by |
|
110
|
|
|
* an unique name. You may use the name of your project for this. If |
|
111
|
|
|
* you've implemented an alternative client class as well, "standard" |
|
112
|
|
|
* should be replaced by the name of the new class. |
|
113
|
|
|
* |
|
114
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
|
115
|
|
|
* @since 2014.03 |
|
116
|
|
|
* @category Developer |
|
117
|
|
|
* @see client/html/checkout/standard/address/delivery/standard/template-header |
|
118
|
|
|
*/ |
|
119
|
|
|
$tplconf = 'client/html/checkout/standard/address/delivery/standard/template-body'; |
|
120
|
|
|
$default = 'checkout/standard/address-delivery-body-default.php'; |
|
121
|
|
|
|
|
122
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Returns the HTML string for insertion into the header. |
|
128
|
|
|
* |
|
129
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
130
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
131
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
132
|
|
|
* @return string|null String including HTML tags for the header on error |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getHeader( $uid = '', array &$tags = array(), &$expire = null ) |
|
135
|
|
|
{ |
|
136
|
|
|
$view = $this->setViewParams( $this->getView(), $tags, $expire ); |
|
137
|
|
|
|
|
138
|
|
|
$html = ''; |
|
139
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
|
140
|
|
|
$html .= $subclient->setView( $view )->getHeader( $uid, $tags, $expire ); |
|
141
|
|
|
} |
|
142
|
|
|
$view->deliveryHeader = $html; |
|
143
|
|
|
|
|
144
|
|
|
/** client/html/checkout/standard/address/delivery/standard/template-header |
|
145
|
|
|
* Relative path to the HTML header template of the checkout standard address delivery client. |
|
146
|
|
|
* |
|
147
|
|
|
* The template file contains the HTML code and processing instructions |
|
148
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
|
149
|
|
|
* of the rendered page in the frontend. The configuration string is the |
|
150
|
|
|
* path to the template file relative to the templates directory (usually |
|
151
|
|
|
* in client/html/templates). |
|
152
|
|
|
* |
|
153
|
|
|
* You can overwrite the template file configuration in extensions and |
|
154
|
|
|
* provide alternative templates. These alternative templates should be |
|
155
|
|
|
* named like the default one but with the string "standard" replaced by |
|
156
|
|
|
* an unique name. You may use the name of your project for this. If |
|
157
|
|
|
* you've implemented an alternative client class as well, "standard" |
|
158
|
|
|
* should be replaced by the name of the new class. |
|
159
|
|
|
* |
|
160
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
|
161
|
|
|
* @since 2014.03 |
|
162
|
|
|
* @category Developer |
|
163
|
|
|
* @see client/html/checkout/standard/address/delivery/standard/template-body |
|
164
|
|
|
*/ |
|
165
|
|
|
$tplconf = 'client/html/checkout/standard/address/delivery/standard/template-header'; |
|
166
|
|
|
$default = 'checkout/standard/address-delivery-header-default.php'; |
|
167
|
|
|
|
|
168
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Returns the sub-client given by its name. |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $type Name of the client type |
|
176
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
|
177
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getSubClient( $type, $name = null ) |
|
180
|
|
|
{ |
|
181
|
|
|
/** client/html/checkout/standard/address/delivery/decorators/excludes |
|
182
|
|
|
* Excludes decorators added by the "common" option from the checkout standard address delivery html client |
|
183
|
|
|
* |
|
184
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
185
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
186
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
187
|
|
|
* modify what is returned to the caller. |
|
188
|
|
|
* |
|
189
|
|
|
* This option allows you to remove a decorator added via |
|
190
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
|
191
|
|
|
* around the html client. |
|
192
|
|
|
* |
|
193
|
|
|
* client/html/checkout/standard/address/delivery/decorators/excludes = array( 'decorator1' ) |
|
194
|
|
|
* |
|
195
|
|
|
* This would remove the decorator named "decorator1" from the list of |
|
196
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
|
197
|
|
|
* "client/html/common/decorators/default" 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/delivery/decorators/global |
|
204
|
|
|
* @see client/html/checkout/standard/address/delivery/decorators/local |
|
205
|
|
|
*/ |
|
206
|
|
|
|
|
207
|
|
|
/** client/html/checkout/standard/address/delivery/decorators/global |
|
208
|
|
|
* Adds a list of globally available decorators only to the checkout standard address delivery html client |
|
209
|
|
|
* |
|
210
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
211
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
212
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
213
|
|
|
* modify what is returned to the caller. |
|
214
|
|
|
* |
|
215
|
|
|
* This option allows you to wrap global decorators |
|
216
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
|
217
|
|
|
* |
|
218
|
|
|
* client/html/checkout/standard/address/delivery/decorators/global = array( 'decorator1' ) |
|
219
|
|
|
* |
|
220
|
|
|
* This would add the decorator named "decorator1" defined by |
|
221
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
|
222
|
|
|
* |
|
223
|
|
|
* @param array List of decorator names |
|
224
|
|
|
* @since 2015.08 |
|
225
|
|
|
* @category Developer |
|
226
|
|
|
* @see client/html/common/decorators/default |
|
227
|
|
|
* @see client/html/checkout/standard/address/delivery/decorators/excludes |
|
228
|
|
|
* @see client/html/checkout/standard/address/delivery/decorators/local |
|
229
|
|
|
*/ |
|
230
|
|
|
|
|
231
|
|
|
/** client/html/checkout/standard/address/delivery/decorators/local |
|
232
|
|
|
* Adds a list of local decorators only to the checkout standard address delivery html client |
|
233
|
|
|
* |
|
234
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
235
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
236
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
237
|
|
|
* modify what is returned to the caller. |
|
238
|
|
|
* |
|
239
|
|
|
* This option allows you to wrap local decorators |
|
240
|
|
|
* ("\Aimeos\Client\Html\Checkout\Decorator\*") around the html client. |
|
241
|
|
|
* |
|
242
|
|
|
* client/html/checkout/standard/address/delivery/decorators/local = array( 'decorator2' ) |
|
243
|
|
|
* |
|
244
|
|
|
* This would add the decorator named "decorator2" defined by |
|
245
|
|
|
* "\Aimeos\Client\Html\Checkout\Decorator\Decorator2" only to the html client. |
|
246
|
|
|
* |
|
247
|
|
|
* @param array List of decorator names |
|
248
|
|
|
* @since 2015.08 |
|
249
|
|
|
* @category Developer |
|
250
|
|
|
* @see client/html/common/decorators/default |
|
251
|
|
|
* @see client/html/checkout/standard/address/delivery/decorators/excludes |
|
252
|
|
|
* @see client/html/checkout/standard/address/delivery/decorators/global |
|
253
|
|
|
*/ |
|
254
|
|
|
|
|
255
|
|
|
return $this->createSubClient( 'checkout/standard/address/delivery/' . $type, $name ); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Stores the given or fetched billing address in the basket. |
|
261
|
|
|
*/ |
|
262
|
|
|
public function process() |
|
263
|
|
|
{ |
|
264
|
|
|
$context = $this->getContext(); |
|
265
|
|
|
$view = $this->getView(); |
|
266
|
|
|
|
|
267
|
|
|
try |
|
268
|
|
|
{ |
|
269
|
|
|
if( ( $id = $view->param( 'ca_delivery_delete', null ) ) !== null ) |
|
270
|
|
|
{ |
|
271
|
|
|
$customerAddressManager = \Aimeos\MShop\Factory::createManager( $context, 'customer/address' ); |
|
272
|
|
|
$address = $customerAddressManager->getItem( $id ); |
|
273
|
|
|
|
|
274
|
|
|
if( $address->getParentId() != $context->getUserId() ) { |
|
275
|
|
|
throw new \Aimeos\Client\Html\Exception( sprintf( 'Address with ID "%1$s" not found', $id ) ); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
$customerAddressManager->deleteItem( $id ); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
// only start if there's something to do |
|
282
|
|
|
if( $view->param( 'ca_deliveryoption', null ) === null ) { |
|
283
|
|
|
return; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
$this->setAddress( $view ); |
|
287
|
|
|
|
|
288
|
|
|
parent::process(); |
|
289
|
|
|
} |
|
290
|
|
|
catch( \Aimeos\Controller\Frontend\Exception $e ) |
|
291
|
|
|
{ |
|
292
|
|
|
$view->deliveryError = $e->getErrorList(); |
|
293
|
|
|
throw $e; |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Checks the address fields for missing data and sanitizes the given parameter list. |
|
300
|
|
|
* |
|
301
|
|
|
* @param array &$params Associative list of address keys (order.base.address.* or customer.address.*) and their values |
|
302
|
|
|
* @return array List of missing field names |
|
303
|
|
|
*/ |
|
304
|
|
|
protected function checkFields( array &$params ) |
|
305
|
|
|
{ |
|
306
|
|
|
$view = $this->getView(); |
|
307
|
|
|
|
|
308
|
|
|
/** client/html/checkout/standard/address/delivery/mandatory |
|
309
|
|
|
* List of delivery address input fields that are required |
|
310
|
|
|
* |
|
311
|
|
|
* You can configure the list of delivery address fields that are |
|
312
|
|
|
* necessary and must be filled by the customer before he can |
|
313
|
|
|
* continue the checkout process. Available field keys are: |
|
314
|
|
|
* * order.base.address.company |
|
315
|
|
|
* * order.base.address.vatid |
|
316
|
|
|
* * order.base.address.salutation |
|
317
|
|
|
* * order.base.address.firstname |
|
318
|
|
|
* * order.base.address.lastname |
|
319
|
|
|
* * order.base.address.address1 |
|
320
|
|
|
* * order.base.address.address2 |
|
321
|
|
|
* * order.base.address.address3 |
|
322
|
|
|
* * order.base.address.postal |
|
323
|
|
|
* * order.base.address.city |
|
324
|
|
|
* * order.base.address.state |
|
325
|
|
|
* * order.base.address.languageid |
|
326
|
|
|
* * order.base.address.countryid |
|
327
|
|
|
* * order.base.address.telephone |
|
328
|
|
|
* * order.base.address.telefax |
|
329
|
|
|
* * order.base.address.email |
|
330
|
|
|
* * order.base.address.website |
|
331
|
|
|
* |
|
332
|
|
|
* Until 2015-02, the configuration option was available as |
|
333
|
|
|
* "client/html/common/address/delivery/mandatory" starting from 2014-03. |
|
334
|
|
|
* |
|
335
|
|
|
* @param array List of field keys |
|
336
|
|
|
* @since 2015.02 |
|
337
|
|
|
* @category User |
|
338
|
|
|
* @category Developer |
|
339
|
|
|
* @see client/html/checkout/standard/address/delivery/disable-new |
|
340
|
|
|
* @see client/html/checkout/standard/address/delivery/salutations |
|
341
|
|
|
* @see client/html/checkout/standard/address/delivery/optional |
|
342
|
|
|
* @see client/html/checkout/standard/address/delivery/hidden |
|
343
|
|
|
* @see client/html/checkout/standard/address/countries |
|
344
|
|
|
* @see client/html/checkout/standard/address/validate |
|
345
|
|
|
*/ |
|
346
|
|
|
$mandatory = $view->config( 'client/html/checkout/standard/address/delivery/mandatory', $this->mandatory ); |
|
347
|
|
|
|
|
348
|
|
|
/** client/html/checkout/standard/address/delivery/optional |
|
349
|
|
|
* List of delivery address input fields that are optional |
|
350
|
|
|
* |
|
351
|
|
|
* You can configure the list of delivery address fields that |
|
352
|
|
|
* customers can fill but don't have to before they can |
|
353
|
|
|
* continue the checkout process. Available field keys are: |
|
354
|
|
|
* * order.base.address.company |
|
355
|
|
|
* * order.base.address.vatid |
|
356
|
|
|
* * order.base.address.salutation |
|
357
|
|
|
* * order.base.address.firstname |
|
358
|
|
|
* * order.base.address.lastname |
|
359
|
|
|
* * order.base.address.address1 |
|
360
|
|
|
* * order.base.address.address2 |
|
361
|
|
|
* * order.base.address.address3 |
|
362
|
|
|
* * order.base.address.postal |
|
363
|
|
|
* * order.base.address.city |
|
364
|
|
|
* * order.base.address.state |
|
365
|
|
|
* * order.base.address.languageid |
|
366
|
|
|
* * order.base.address.countryid |
|
367
|
|
|
* * order.base.address.telephone |
|
368
|
|
|
* * order.base.address.telefax |
|
369
|
|
|
* * order.base.address.email |
|
370
|
|
|
* * order.base.address.website |
|
371
|
|
|
* |
|
372
|
|
|
* Until 2015-02, the configuration option was available as |
|
373
|
|
|
* "client/html/common/address/delivery/optional" starting from 2014-03. |
|
374
|
|
|
* |
|
375
|
|
|
* @param array List of field keys |
|
376
|
|
|
* @since 2015.02 |
|
377
|
|
|
* @category User |
|
378
|
|
|
* @category Developer |
|
379
|
|
|
* @see client/html/checkout/standard/address/delivery/disable-new |
|
380
|
|
|
* @see client/html/checkout/standard/address/delivery/salutations |
|
381
|
|
|
* @see client/html/checkout/standard/address/delivery/mandatory |
|
382
|
|
|
* @see client/html/checkout/standard/address/delivery/hidden |
|
383
|
|
|
* @see client/html/checkout/standard/address/countries |
|
384
|
|
|
* @see client/html/checkout/standard/address/validate |
|
385
|
|
|
*/ |
|
386
|
|
|
$optional = $view->config( 'client/html/checkout/standard/address/delivery/optional', $this->optional ); |
|
387
|
|
|
|
|
388
|
|
|
/** client/html/checkout/standard/address/validate |
|
389
|
|
|
* |
|
390
|
|
|
* @see client/html/checkout/standard/address/delivery/mandatory |
|
391
|
|
|
* @see client/html/checkout/standard/address/delivery/optional |
|
392
|
|
|
*/ |
|
393
|
|
|
|
|
394
|
|
|
$allFields = array_flip( array_merge( $mandatory, $optional ) ); |
|
395
|
|
|
$invalid = $this->validateFields( $params, $allFields ); |
|
396
|
|
|
$this->checkSalutation( $params, $mandatory ); |
|
397
|
|
|
|
|
398
|
|
|
foreach( $invalid as $key => $name ) |
|
399
|
|
|
{ |
|
400
|
|
|
$msg = $view->translate( 'client', 'Delivery address part "%1$s" is invalid' ); |
|
401
|
|
|
$invalid[$key] = sprintf( $msg, $name ); |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
foreach( $mandatory as $key ) |
|
405
|
|
|
{ |
|
406
|
|
|
if( !isset( $params[$key] ) || $params[$key] == '' ) |
|
407
|
|
|
{ |
|
408
|
|
|
$msg = $view->translate( 'client', 'Delivery address part "%1$s" is missing' ); |
|
409
|
|
|
$invalid[$key] = sprintf( $msg, substr( $key, 19 ) ); |
|
410
|
|
|
unset( $params[$key] ); |
|
411
|
|
|
} |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
return $invalid; |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* Additional checks for the salutation |
|
420
|
|
|
* |
|
421
|
|
|
* @param array &$params Associative list of address keys (order.base.address.* or customer.address.*) and their values |
|
422
|
|
|
* @param array &$mandatory List of mandatory field names |
|
423
|
|
|
* @return array Additional mandatory address keys |
|
424
|
|
|
* @since 2016.05 |
|
425
|
|
|
*/ |
|
426
|
|
|
protected function checkSalutation( array &$params, array &$mandatory ) |
|
427
|
|
|
{ |
|
428
|
|
|
if( isset( $params['order.base.address.salutation'] ) |
|
429
|
|
|
&& $params['order.base.address.salutation'] === \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY |
|
430
|
|
|
&& in_array( 'order.base.address.company', $mandatory ) === false |
|
431
|
|
|
) { |
|
432
|
|
|
$mandatory[] = 'order.base.address.company'; |
|
433
|
|
|
} else { |
|
434
|
|
|
$params['order.base.address.company'] = $params['order.base.address.vatid'] = ''; |
|
435
|
|
|
} |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
|
|
439
|
|
|
/** |
|
440
|
|
|
* Returns the list of sub-client names configured for the client. |
|
441
|
|
|
* |
|
442
|
|
|
* @return array List of HTML client names |
|
443
|
|
|
*/ |
|
444
|
|
|
protected function getSubClientNames() |
|
445
|
|
|
{ |
|
446
|
|
|
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Sets the new address |
|
452
|
|
|
* |
|
453
|
|
|
* @param \Aimeos\MW\View\Iface $view View object |
|
454
|
|
|
* @throws \Aimeos\Client\Html\Exception If an error occurs |
|
455
|
|
|
* @since 2016.05 |
|
456
|
|
|
*/ |
|
457
|
|
|
protected function setAddress( \Aimeos\MW\View\Iface $view ) |
|
458
|
|
|
{ |
|
459
|
|
|
$context = $this->getContext(); |
|
460
|
|
|
$basketCtrl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'basket' ); |
|
461
|
|
|
|
|
462
|
|
|
/** client/html/checkout/standard/address/delivery/disable-new |
|
463
|
|
|
* Disables the option to enter a different delivery address for an order |
|
464
|
|
|
* |
|
465
|
|
|
* Besides the billing address, customers can usually enter a different |
|
466
|
|
|
* delivery address as well. To suppress displaying the form fields for |
|
467
|
|
|
* a delivery address, you can set this configuration option to "1". |
|
468
|
|
|
* |
|
469
|
|
|
* Until 2015-02, the configuration option was available as |
|
470
|
|
|
* "client/html/common/address/delivery/disable-new" starting from 2014-03. |
|
471
|
|
|
* |
|
472
|
|
|
* @param boolean A value of "1" to disable, "0" enables the delivery address form |
|
473
|
|
|
* @since 2015.02 |
|
474
|
|
|
* @category User |
|
475
|
|
|
* @category Developer |
|
476
|
|
|
* @see client/html/checkout/standard/address/delivery/salutations |
|
477
|
|
|
* @see client/html/checkout/standard/address/delivery/mandatory |
|
478
|
|
|
* @see client/html/checkout/standard/address/delivery/optional |
|
479
|
|
|
* @see client/html/checkout/standard/address/delivery/hidden |
|
480
|
|
|
*/ |
|
481
|
|
|
$disable = $view->config( 'client/html/checkout/standard/address/delivery/disable-new', false ); |
|
482
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY; |
|
483
|
|
|
|
|
484
|
|
|
if( ( $option = $view->param( 'ca_deliveryoption', 'null' ) ) === 'null' && $disable === false ) // new address |
|
485
|
|
|
{ |
|
486
|
|
|
$params = $view->param( 'ca_delivery', array() ); |
|
487
|
|
|
$invalid = $this->checkFields( $params ); |
|
488
|
|
|
|
|
489
|
|
|
if( count( $invalid ) > 0 ) |
|
490
|
|
|
{ |
|
491
|
|
|
$view->deliveryError = $invalid; |
|
492
|
|
|
throw new \Aimeos\Client\Html\Exception( sprintf( 'At least one delivery address part is missing or invalid' ) ); |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
$basketCtrl->setAddress( $type, $params ); |
|
496
|
|
|
} |
|
497
|
|
|
else if( ( $option = $view->param( 'ca_deliveryoption', 'null' ) ) !== '-1' ) // existing address |
|
498
|
|
|
{ |
|
499
|
|
|
$customerAddressManager = \Aimeos\MShop\Factory::createManager( $context, 'customer/address' ); |
|
500
|
|
|
$address = $customerAddressManager->getItem( $option ); |
|
501
|
|
|
|
|
502
|
|
|
if( $address->getParentId() != $context->getUserId() ) { |
|
503
|
|
|
throw new \Aimeos\Client\Html\Exception( sprintf( 'Address with ID "%1$s" not found', $option ) ); |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
$invalid = array(); |
|
507
|
|
|
$params = $view->param( 'ca_delivery_' . $option, array() ); |
|
508
|
|
|
|
|
509
|
|
|
if( !empty( $params ) ) |
|
510
|
|
|
{ |
|
511
|
|
|
$list = array(); |
|
512
|
|
|
$invalid = $this->checkFields( $params ); |
|
513
|
|
|
|
|
514
|
|
|
foreach( $params as $key => $value ) { |
|
515
|
|
|
$list[str_replace( 'order.base', 'customer', $key )] = $value; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
$address->fromArray( $list ); |
|
519
|
|
|
$customerAddressManager->saveItem( $address ); |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
if( count( $invalid ) > 0 ) |
|
523
|
|
|
{ |
|
524
|
|
|
$view->deliveryError = $invalid; |
|
525
|
|
|
throw new \Aimeos\Client\Html\Exception( sprintf( 'At least one delivery address part is missing or invalid' ) ); |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
$basketCtrl->setAddress( $type, $address ); |
|
529
|
|
|
} |
|
530
|
|
|
else |
|
531
|
|
|
{ |
|
532
|
|
|
$basketCtrl->setAddress( $type, null ); |
|
533
|
|
|
} |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
|
|
537
|
|
|
/** |
|
538
|
|
|
* Sets the necessary parameter values in the view. |
|
539
|
|
|
* |
|
540
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
|
541
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
542
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
543
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
|
544
|
|
|
*/ |
|
545
|
|
|
protected function setViewParams( \Aimeos\MW\View\Iface $view, array &$tags = array(), &$expire = null ) |
|
546
|
|
|
{ |
|
547
|
|
|
if( !isset( $this->cache ) ) |
|
548
|
|
|
{ |
|
549
|
|
|
$context = $this->getContext(); |
|
550
|
|
|
$basketCntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'basket' ); |
|
551
|
|
|
|
|
552
|
|
|
try { |
|
553
|
|
|
$langid = $basketCntl->get()->getAddress( 'delivery' )->getLanguageId(); |
|
554
|
|
|
} catch( \Exception $e ) { |
|
555
|
|
|
$langid = $view->param( 'ca_delivery/order.base.address.languageid', $context->getLocale()->getLanguageId() ); |
|
556
|
|
|
} |
|
557
|
|
|
$view->deliveryLanguage = $langid; |
|
558
|
|
|
|
|
559
|
|
|
/** client/html/checkout/standard/address/delivery/hidden |
|
560
|
|
|
* List of delivery address input fields that are optional |
|
561
|
|
|
* |
|
562
|
|
|
* You can configure the list of delivery address fields that |
|
563
|
|
|
* are hidden when a customer enters his delivery address. |
|
564
|
|
|
* Available field keys are: |
|
565
|
|
|
* * order.base.address.company |
|
566
|
|
|
* * order.base.address.vatid |
|
567
|
|
|
* * order.base.address.salutation |
|
568
|
|
|
* * order.base.address.firstname |
|
569
|
|
|
* * order.base.address.lastname |
|
570
|
|
|
* * order.base.address.address1 |
|
571
|
|
|
* * order.base.address.address2 |
|
572
|
|
|
* * order.base.address.address3 |
|
573
|
|
|
* * order.base.address.postal |
|
574
|
|
|
* * order.base.address.city |
|
575
|
|
|
* * order.base.address.state |
|
576
|
|
|
* * order.base.address.languageid |
|
577
|
|
|
* * order.base.address.countryid |
|
578
|
|
|
* * order.base.address.telephone |
|
579
|
|
|
* * order.base.address.telefax |
|
580
|
|
|
* * order.base.address.email |
|
581
|
|
|
* * order.base.address.website |
|
582
|
|
|
* |
|
583
|
|
|
* Caution: Only hide fields that don't require any input |
|
584
|
|
|
* |
|
585
|
|
|
* Until 2015-02, the configuration option was available as |
|
586
|
|
|
* "client/html/common/address/delivery/hidden" starting from 2014-03. |
|
587
|
|
|
* |
|
588
|
|
|
* @param array List of field keys |
|
589
|
|
|
* @since 2015.02 |
|
590
|
|
|
* @category User |
|
591
|
|
|
* @category Developer |
|
592
|
|
|
* @see client/html/checkout/standard/address/delivery/disable-new |
|
593
|
|
|
* @see client/html/checkout/standard/address/delivery/salutations |
|
594
|
|
|
* @see client/html/checkout/standard/address/delivery/mandatory |
|
595
|
|
|
* @see client/html/checkout/standard/address/delivery/optional |
|
596
|
|
|
* @see client/html/checkout/standard/address/countries |
|
597
|
|
|
*/ |
|
598
|
|
|
$hidden = $view->config( 'client/html/checkout/standard/address/delivery/hidden', array() ); |
|
599
|
|
|
|
|
600
|
|
|
if( count( $view->get( 'addressLanguages', array() ) ) === 1 ) { |
|
601
|
|
|
$hidden[] = 'order.base.address.languageid'; |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
$salutations = array( 'company', 'mr', 'mrs' ); |
|
605
|
|
|
|
|
606
|
|
|
/** client/html/checkout/standard/address/delivery/salutations |
|
607
|
|
|
* List of salutions the customer can select from for the delivery address |
|
608
|
|
|
* |
|
609
|
|
|
* The following salutations are available: |
|
610
|
|
|
* * empty string for "unknown" |
|
611
|
|
|
* * company |
|
612
|
|
|
* * mr |
|
613
|
|
|
* * mrs |
|
614
|
|
|
* * miss |
|
615
|
|
|
* |
|
616
|
|
|
* You can modify the list of salutation codes and remove the ones |
|
617
|
|
|
* which shouldn't be used. Adding new salutations is a little bit |
|
618
|
|
|
* more difficult because you have to adapt a few areas in the source |
|
619
|
|
|
* code. |
|
620
|
|
|
* |
|
621
|
|
|
* Until 2015-02, the configuration option was available as |
|
622
|
|
|
* "client/html/common/address/delivery/salutations" starting from 2014-03. |
|
623
|
|
|
* |
|
624
|
|
|
* @param array List of available salutation codes |
|
625
|
|
|
* @since 2015.02 |
|
626
|
|
|
* @category User |
|
627
|
|
|
* @category Developer |
|
628
|
|
|
* @see client/html/checkout/standard/address/delivery/disable-new |
|
629
|
|
|
* @see client/html/checkout/standard/address/delivery/mandatory |
|
630
|
|
|
* @see client/html/checkout/standard/address/delivery/optional |
|
631
|
|
|
* @see client/html/checkout/standard/address/delivery/hidden |
|
632
|
|
|
* @see client/html/checkout/standard/address/countries |
|
633
|
|
|
*/ |
|
634
|
|
|
$view->deliverySalutations = $view->config( 'client/html/checkout/standard/address/delivery/salutations', $salutations ); |
|
635
|
|
|
|
|
636
|
|
|
$view->deliveryMandatory = $view->config( 'client/html/checkout/standard/address/delivery/mandatory', $this->mandatory ); |
|
637
|
|
|
$view->deliveryOptional = $view->config( 'client/html/checkout/standard/address/delivery/optional', $this->optional ); |
|
638
|
|
|
$view->deliveryHidden = $hidden; |
|
639
|
|
|
|
|
640
|
|
|
|
|
641
|
|
|
$this->cache = $view; |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
return $this->cache; |
|
645
|
|
|
} |
|
646
|
|
|
|
|
647
|
|
|
|
|
648
|
|
|
/** |
|
649
|
|
|
* Validate the address key/value pairs using regular expressions |
|
650
|
|
|
* |
|
651
|
|
|
* @param array &$params Associative list of address keys (order.base.address.* or customer.address.*) and their values |
|
652
|
|
|
* @param array $fields List of field names to validate |
|
653
|
|
|
* @return array List of invalid address keys |
|
654
|
|
|
* @since 2016.05 |
|
655
|
|
|
*/ |
|
656
|
|
|
protected function validateFields( array &$params, array $fields ) |
|
657
|
|
|
{ |
|
658
|
|
|
$config = $this->getContext()->getConfig(); |
|
659
|
|
|
|
|
660
|
|
|
/** client/html/checkout/standard/address/validate/company |
|
661
|
|
|
* Regular expression to check the "company" address value |
|
662
|
|
|
* |
|
663
|
|
|
* @see client/html/checkout/standard/address/validate |
|
664
|
|
|
*/ |
|
665
|
|
|
|
|
666
|
|
|
/** client/html/checkout/standard/address/validate/vatid |
|
667
|
|
|
* Regular expression to check the "vatid" address value |
|
668
|
|
|
* |
|
669
|
|
|
* @see client/html/checkout/standard/address/validate |
|
670
|
|
|
*/ |
|
671
|
|
|
|
|
672
|
|
|
/** client/html/checkout/standard/address/validate/salutation |
|
673
|
|
|
* Regular expression to check the "salutation" address value |
|
674
|
|
|
* |
|
675
|
|
|
* @see client/html/checkout/standard/address/validate |
|
676
|
|
|
*/ |
|
677
|
|
|
|
|
678
|
|
|
/** client/html/checkout/standard/address/validate/firstname |
|
679
|
|
|
* Regular expression to check the "firstname" address value |
|
680
|
|
|
* |
|
681
|
|
|
* @see client/html/checkout/standard/address/validate |
|
682
|
|
|
*/ |
|
683
|
|
|
|
|
684
|
|
|
/** client/html/checkout/standard/address/validate/lastname |
|
685
|
|
|
* Regular expression to check the "lastname" address value |
|
686
|
|
|
* |
|
687
|
|
|
* @see client/html/checkout/standard/address/validate |
|
688
|
|
|
*/ |
|
689
|
|
|
|
|
690
|
|
|
/** client/html/checkout/standard/address/validate/address1 |
|
691
|
|
|
* Regular expression to check the "address1" address value |
|
692
|
|
|
* |
|
693
|
|
|
* @see client/html/checkout/standard/address/validate |
|
694
|
|
|
*/ |
|
695
|
|
|
|
|
696
|
|
|
/** client/html/checkout/standard/address/validate/address2 |
|
697
|
|
|
* Regular expression to check the "address2" address value |
|
698
|
|
|
* |
|
699
|
|
|
* @see client/html/checkout/standard/address/validate |
|
700
|
|
|
*/ |
|
701
|
|
|
|
|
702
|
|
|
/** client/html/checkout/standard/address/validate/address3 |
|
703
|
|
|
* Regular expression to check the "address3" address value |
|
704
|
|
|
* |
|
705
|
|
|
* @see client/html/checkout/standard/address/validate |
|
706
|
|
|
*/ |
|
707
|
|
|
|
|
708
|
|
|
/** client/html/checkout/standard/address/validate/postal |
|
709
|
|
|
* Regular expression to check the "postal" address value |
|
710
|
|
|
* |
|
711
|
|
|
* @see client/html/checkout/standard/address/validate |
|
712
|
|
|
*/ |
|
713
|
|
|
|
|
714
|
|
|
/** client/html/checkout/standard/address/validate/city |
|
715
|
|
|
* Regular expression to check the "city" address value |
|
716
|
|
|
* |
|
717
|
|
|
* @see client/html/checkout/standard/address/validate |
|
718
|
|
|
*/ |
|
719
|
|
|
|
|
720
|
|
|
/** client/html/checkout/standard/address/validate/state |
|
721
|
|
|
* Regular expression to check the "state" address value |
|
722
|
|
|
* |
|
723
|
|
|
* @see client/html/checkout/standard/address/validate |
|
724
|
|
|
*/ |
|
725
|
|
|
|
|
726
|
|
|
/** client/html/checkout/standard/address/validate/languageid |
|
727
|
|
|
* Regular expression to check the "languageid" address value |
|
728
|
|
|
* |
|
729
|
|
|
* @see client/html/checkout/standard/address/validate |
|
730
|
|
|
*/ |
|
731
|
|
|
|
|
732
|
|
|
/** client/html/checkout/standard/address/validate/countryid |
|
733
|
|
|
* Regular expression to check the "countryid" address value |
|
734
|
|
|
* |
|
735
|
|
|
* @see client/html/checkout/standard/address/validate |
|
736
|
|
|
*/ |
|
737
|
|
|
|
|
738
|
|
|
/** client/html/checkout/standard/address/validate/telephone |
|
739
|
|
|
* Regular expression to check the "telephone" address value |
|
740
|
|
|
* |
|
741
|
|
|
* @see client/html/checkout/standard/address/validate |
|
742
|
|
|
*/ |
|
743
|
|
|
|
|
744
|
|
|
/** client/html/checkout/standard/address/validate/telefax |
|
745
|
|
|
* Regular expression to check the "telefax" address value |
|
746
|
|
|
* |
|
747
|
|
|
* @see client/html/checkout/standard/address/validate |
|
748
|
|
|
*/ |
|
749
|
|
|
|
|
750
|
|
|
/** client/html/checkout/standard/address/validate/email |
|
751
|
|
|
* Regular expression to check the "email" address value |
|
752
|
|
|
* |
|
753
|
|
|
* @see client/html/checkout/standard/address/validate |
|
754
|
|
|
*/ |
|
755
|
|
|
|
|
756
|
|
|
/** client/html/checkout/standard/address/validate/website |
|
757
|
|
|
* Regular expression to check the "website" address value |
|
758
|
|
|
* |
|
759
|
|
|
* @see client/html/checkout/standard/address/validate |
|
760
|
|
|
*/ |
|
761
|
|
|
|
|
762
|
|
|
$invalid = array(); |
|
763
|
|
|
|
|
764
|
|
|
foreach( $params as $key => $value ) |
|
765
|
|
|
{ |
|
766
|
|
|
if( isset( $fields[$key] ) ) |
|
767
|
|
|
{ |
|
768
|
|
|
$name = substr( $key, 19 ); |
|
769
|
|
|
$regex = $config->get( 'client/html/checkout/standard/address/validate/' . $name ); |
|
770
|
|
|
|
|
771
|
|
|
if( $regex && preg_match( '/' . $regex . '/', $value ) !== 1 ) |
|
772
|
|
|
{ |
|
773
|
|
|
$invalid[$key] = $name; |
|
774
|
|
|
unset( $params[$key] ); |
|
775
|
|
|
} |
|
776
|
|
|
} |
|
777
|
|
|
else |
|
778
|
|
|
{ |
|
779
|
|
|
unset( $params[$key] ); |
|
780
|
|
|
} |
|
781
|
|
|
} |
|
782
|
|
|
|
|
783
|
|
|
return $invalid; |
|
784
|
|
|
} |
|
785
|
|
|
} |