Standard::navigation()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 99
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 4
nop 3
dl 0
loc 99
rs 9.2222
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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-2025
7
 * @package Client
8
 * @subpackage Html
9
 */
10
11
12
namespace Aimeos\Client\Html\Checkout\Standard;
13
14
15
/**
16
 * Default implementation of standard checkout 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/name
26
	 * Class name of the used checkout standard client implementation
27
	 *
28
	 * Each default HTML client can be replace by an alternative imlementation.
29
	 * To use this implementation, you have to set the last part of the class
30
	 * name as configuration value so the client factory knows which class it
31
	 * has to instantiate.
32
	 *
33
	 * For example, if the name of the default class is
34
	 *
35
	 *  \Aimeos\Client\Html\Checkout\Standard\Standard
36
	 *
37
	 * and you want to replace it with your own version named
38
	 *
39
	 *  \Aimeos\Client\Html\Checkout\Standard\Mycheckout
40
	 *
41
	 * then you have to set the this configuration option:
42
	 *
43
	 *  client/html/checkout/standard/name = Mycheckout
44
	 *
45
	 * The value is the last part of your own class name and it's case sensitive,
46
	 * so take care that the configuration value is exactly named like the last
47
	 * part of the class name.
48
	 *
49
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
50
	 * characters are possible! You should always start the last part of the class
51
	 * name with an upper case character and continue only with lower case characters
52
	 * or numbers. Avoid chamel case names like "MyCheckout"!
53
	 *
54
	 * @param string Last part of the class name
55
	 */
56
57
58
	/** client/html/checkout/standard/subparts
59
	 * List of HTML sub-clients rendered within the checkout standard section
60
	 *
61
	 * The output of the frontend is composed of the code generated by the HTML
62
	 * clients. Each HTML client can consist of serveral (or none) sub-clients
63
	 * that are responsible for rendering certain sub-parts of the output. The
64
	 * sub-clients can contain HTML clients themselves and therefore a
65
	 * hierarchical tree of HTML clients is composed. Each HTML client creates
66
	 * the output that is placed inside the container of its parent.
67
	 *
68
	 * At first, always the HTML code generated by the parent is printed, then
69
	 * the HTML code of its sub-clients. The order of the HTML sub-clients
70
	 * determines the order of the output of these sub-clients inside the parent
71
	 * container. If the configured list of clients is
72
	 *
73
	 *  array( "subclient1", "subclient2" )
74
	 *
75
	 * you can easily change the order of the output by reordering the subparts:
76
	 *
77
	 *  client/html/<clients>/subparts = array( "subclient1", "subclient2" )
78
	 *
79
	 * You can also remove one or more parts if they shouldn't be rendered:
80
	 *
81
	 *  client/html/<clients>/subparts = array( "subclient1" )
82
	 *
83
	 * As the clients only generates structural HTML, the layout defined via CSS
84
	 * should support adding, removing or reordering content by a fluid like
85
	 * design.
86
	 *
87
	 * @param array List of sub-client names
88
	 */
89
	private string $subPartPath = 'client/html/checkout/standard/subparts';
90
91
	/** client/html/checkout/standard/address/name
92
	 * Name of the address part used by the checkout standard client implementation
93
	 *
94
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Checkout\Standard\Address\Myname".
95
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
96
	 *
97
	 * @param string Last part of the client class name
98
	 */
99
100
	/** client/html/checkout/standard/delivery/name
101
	 * Name of the delivery part used by the checkout standard client implementation
102
	 *
103
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Checkout\Standard\Delivery\Myname".
104
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
105
	 *
106
	 * @param string Last part of the client class name
107
	 */
108
109
	/** client/html/checkout/standard/payment/name
110
	 * Name of the payment part used by the checkout standard client implementation
111
	 *
112
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Checkout\Standard\Payment\Myname".
113
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
114
	 *
115
	 * @param string Last part of the client class name
116
	 */
117
118
	/** client/html/checkout/standard/summary/name
119
	 * Name of the summary part used by the checkout standard client implementation
120
	 *
121
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Checkout\Standard\Summary\Myname".
122
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
123
	 *
124
	 * @param string Last part of the client class name
125
	 */
126
127
	/** client/html/checkout/standard/process/name
128
	 * Name of the process part used by the checkout standard client implementation
129
	 *
130
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Checkout\Standard\Process\Myname".
131
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
132
	 *
133
	 * @param string Last part of the client class name
134
	 */
135
	private array $subPartNames = ['address', 'delivery', 'payment', 'summary', 'process'];
136
137
138
	/**
139
	 * Returns the sub-client given by its name.
140
	 *
141
	 * @param string $type Name of the client type
142
	 * @param string|null $name Name of the sub-client (Default if null)
143
	 * @return \Aimeos\Client\Html\Iface Sub-client object
144
	 */
145
	public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Client\Html\Iface
146
	{
147
		return $this->createSubClient( 'checkout/standard/' . $type, $name );
148
	}
149
150
151
	/**
152
	 * Returns the list of sub-client names configured for the client.
153
	 *
154
	 * @return array List of HTML client names
155
	 */
156
	protected function getSubClientNames() : array
157
	{
158
		return $this->context()->config()->get( $this->subPartPath, $this->subPartNames );
159
	}
160
161
162
	/**
163
	 * Sets the necessary parameter values in the view.
164
	 *
165
	 * @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output
166
	 * @param array &$tags Result array for the list of tags that are associated to the output
167
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
168
	 * @return \Aimeos\Base\View\Iface Modified view object
169
	 */
170
	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface
171
	{
172
		$context = $this->context();
173
174
		$basketCntl = \Aimeos\Controller\Frontend::create( $context, 'basket' );
175
		$view->standardBasket = $basketCntl->get();
176
177
178
		/** client/html/checkout/standard/url/step-active
179
		 * Name of the checkout process step to jump to if no previous step requires attention
180
		 *
181
		 * The checkout process consists of several steps which are usually
182
		 * displayed one by another to the customer. If the data of a step
183
		 * is already available, then that step is skipped. The active step
184
		 * is the one that is displayed if all other steps are skipped.
185
		 *
186
		 * If one of the previous steps misses some data the customer has
187
		 * to enter, then this step is displayed first. After providing
188
		 * the missing data, the whole series of steps are tested again
189
		 * and if no other step requests attention, the configured active
190
		 * step will be displayed.
191
		 *
192
		 * The order of the steps is determined by the order of sub-parts
193
		 * that are configured for the checkout client.
194
		 *
195
		 * @param string Name of the confirm standard HTML client
196
		 * @see client/html/checkout/subparts
197
		 */
198
		$default = $view->config( 'client/html/checkout/standard/url/step-active', 'summary' );
199
200
		/** client/html/checkout/standard/onepage
201
		 * Shows all named checkout subparts at once for a one page checkout
202
		 *
203
		 * Normally, the checkout process is divided into several steps for entering
204
		 * addresses, select delivery and payment options as well as showing the
205
		 * summary page. This enables dependencies between two steps like showing
206
		 * delivery options based on the address entered by the customer. Furthermore,
207
		 * this is good way to limit the amount of information displayed which is
208
		 * preferred by mobile users.
209
		 *
210
		 * Contrary to that, a one page checkout displays all information on only
211
		 * one page and customers get an immediate overview of which information
212
		 * they have to enter and what options they can select from. This is an
213
		 * advantage if only a very limited amount of information must be entered
214
		 * or if there are almost no options to choose from and no dependencies
215
		 * between exist.
216
		 *
217
		 * Using this config options, shop developers are able to define which
218
		 * checkout subparts are combined to a one page view. Simply add the names
219
		 * of all checkout subparts to the list. Available checkout subparts for
220
		 * a one page checkout are:
221
		 *
222
		 * * address
223
		 * * delivery
224
		 * * payment
225
		 * * summary
226
		 *
227
		 * @param array List of checkout subparts name
228
		 */
229
		$onepage = $view->config( 'client/html/checkout/standard/onepage', [] );
230
		$onestep = ( !empty( $onepage ) ? array_shift( $onepage ) : $default ); // keep the first one page step
231
232
		$steps = (array) $context->config()->get( $this->subPartPath, $this->subPartNames );
233
		$steps = array_values( array_diff( $steps, $onepage ) ); // remove all remaining steps in $onepage and reindex
234
235
		// use first step if default step isn't available
236
		$default = ( !in_array( $default, $steps ) ? reset( $steps ) : $default );
237
		$current = $view->param( 'c_step', $default );
238
239
		// use $onestep if the current step isn't available due to one page layout
240
		if( !in_array( $current, $steps ) ) {
241
			$current = $onestep;
242
		}
243
244
		// use $onestep if the active step isn't available due to one page layout
245
		if( isset( $view->standardStepActive ) && in_array( $view->standardStepActive, $onepage ) ) {
246
			$view->standardStepActive = $onestep;
247
		}
248
249
		$cpos = array_search( $current, $steps );
250
251
		if( !isset( $view->standardStepActive )
252
			|| ( ( $apos = array_search( $view->standardStepActive, $steps ) ) !== false
253
			&& $cpos !== false && $cpos < $apos )
254
		) {
255
			$view->standardStepActive = $current;
256
		}
257
258
		$cpos = (int) array_search( $view->standardStepActive, array_values( $steps ) );
259
260
		$view->standardStepsBefore = array_slice( $steps, 0, $cpos );
261
		$view->standardStepsAfter = array_slice( $steps, $cpos + 1 );
262
263
		$view = $this->navigation( $view, $steps, $view->standardStepActive );
264
		$view->standardSteps = $steps;
265
266
		return parent::data( $view, $tags, $expire );
267
	}
268
269
270
	/**
271
	 * Adds the "back" and "next" URLs to the view
272
	 *
273
	 * @param \Aimeos\Base\View\Iface $view View object
274
	 * @param array $steps List of checkout step names
275
	 * @param string $activeStep Name of the active step
276
	 * @return \Aimeos\Base\View\Iface Enhanced view object
277
	 */
278
	protected function navigation( \Aimeos\Base\View\Iface $view, array $steps, string $activeStep ) : \Aimeos\Base\View\Iface
279
	{
280
		/** client/html/checkout/standard/url/target
281
		 * Destination of the URL where the controller specified in the URL is known
282
		 *
283
		 * The destination can be a page ID like in a content management system or the
284
		 * module of a software development framework. This "target" must contain or know
285
		 * the controller that should be called by the generated URL.
286
		 *
287
		 * @param string Destination of the URL
288
		 * @see client/html/checkout/standard/url/controller
289
		 * @see client/html/checkout/standard/url/action
290
		 * @see client/html/checkout/standard/url/config
291
		 * @see client/html/checkout/standard/url/filter
292
		 */
293
294
		/** client/html/checkout/standard/url/controller
295
		 * Name of the controller whose action should be called
296
		 *
297
		 * In Model-View-Controller (MVC) applications, the controller contains the methods
298
		 * that create parts of the output displayed in the generated HTML page. Controller
299
		 * names are usually alpha-numeric.
300
		 *
301
		 * @param string Name of the controller
302
		 * @see client/html/checkout/standard/url/target
303
		 * @see client/html/checkout/standard/url/action
304
		 * @see client/html/checkout/standard/url/config
305
		 * @see client/html/checkout/standard/url/filter
306
		 */
307
308
		/** client/html/checkout/standard/url/action
309
		 * Name of the action that should create the output
310
		 *
311
		 * In Model-View-Controller (MVC) applications, actions are the methods of a
312
		 * controller that create parts of the output displayed in the generated HTML page.
313
		 * Action names are usually alpha-numeric.
314
		 *
315
		 * @param string Name of the action
316
		 * @see client/html/checkout/standard/url/target
317
		 * @see client/html/checkout/standard/url/controller
318
		 * @see client/html/checkout/standard/url/config
319
		 * @see client/html/checkout/standard/url/filter
320
		 */
321
322
		/** client/html/checkout/standard/url/config
323
		 * Associative list of configuration options used for generating the URL
324
		 *
325
		 * You can specify additional options as key/value pairs used when generating
326
		 * the URLs, like
327
		 *
328
		 *  client/html/<clientname>/url/config = array( 'absoluteUri' => true )
329
		 *
330
		 * The available key/value pairs depend on the application that embeds the e-commerce
331
		 * framework. This is because the infrastructure of the application is used for
332
		 * generating the URLs. The full list of available config options is referenced
333
		 * in the "see also" section of this page.
334
		 *
335
		 * @param string Associative list of configuration options
336
		 * @see client/html/checkout/standard/url/target
337
		 * @see client/html/checkout/standard/url/controller
338
		 * @see client/html/checkout/standard/url/action
339
		 * @see client/html/checkout/standard/url/filter
340
		 */
341
342
		/** client/html/checkout/standard/url/filter
343
		 * Removes parameters for the detail page before generating the URL
344
		 *
345
		 * This setting removes the listed parameters from the URLs. Keep care to
346
		 * remove no required parameters!
347
		 *
348
		 * @param array List of parameter names to remove
349
		 * @since 2022.10
350
		 * @see client/html/checkout/standard/url/target
351
		 * @see client/html/checkout/standard/url/controller
352
		 * @see client/html/checkout/standard/url/action
353
		 * @see client/html/checkout/standard/url/config
354
		 */
355
356
		$step = null;
357
		do {
358
			$lastStep = $step;
359
		}
360
		while( ( $step = array_shift( $steps ) ) !== null && $step !== $activeStep );
361
362
363
		if( $lastStep !== null ) {
0 ignored issues
show
introduced by
The condition $lastStep !== null is always false.
Loading history...
364
			$param = array( 'c_step' => $lastStep );
365
			$view->standardUrlBack = $view->link( 'client/html/checkout/standard/url', $param );
366
		} else {
367
			$view->standardUrlBack = $view->link( 'client/html/basket/standard/url' );
368
		}
369
370
		if( !isset( $view->standardUrlNext ) && ( $nextStep = array_shift( $steps ) ) !== null ) {
371
			$param = array( 'c_step' => $nextStep );
372
			$view->standardUrlNext = $view->link( 'client/html/checkout/standard/url', $param );
373
		}
374
		// don't overwrite $view->standardUrlNext so process step URL is used
375
376
		return $view;
377
	}
378
379
380
	/** client/html/checkout/standard/template-body
381
	 * Relative path to the HTML body template of the checkout standard client.
382
	 *
383
	 * The template file contains the HTML code and processing instructions
384
	 * to generate the result shown in the body of the frontend. The
385
	 * configuration string is the path to the template file relative
386
	 * to the templates directory (usually in templates/client/html).
387
	 *
388
	 * You can overwrite the template file configuration in extensions and
389
	 * provide alternative templates. These alternative templates should be
390
	 * named like the default one but suffixed by
391
	 * an unique name. You may use the name of your project for this. If
392
	 * you've implemented an alternative client class as well, it
393
	 * should be suffixed by the name of the new class.
394
	 *
395
	 * @param string Relative path to the template creating code for the HTML page body
396
	 * @see client/html/checkout/template-header
397
	 */
398
399
	/** client/html/checkout/standard/template-header
400
	 * Relative path to the HTML header template of the checkout standard client.
401
	 *
402
	 * The template file contains the HTML code and processing instructions
403
	 * to generate the HTML code that is inserted into the HTML page header
404
	 * of the rendered page in the frontend. The configuration string is the
405
	 * path to the template file relative to the templates directory (usually
406
	 * in templates/client/html).
407
	 *
408
	 * You can overwrite the template file configuration in extensions and
409
	 * provide alternative templates. These alternative templates should be
410
	 * named like the default one but suffixed by
411
	 * an unique name. You may use the name of your project for this. If
412
	 * you've implemented an alternative client class as well, it
413
	 * should be suffixed by the name of the new class.
414
	 *
415
	 * @param string Relative path to the template creating code for the HTML page head
416
	 * @see client/html/checkout/template-body
417
	 */
418
419
	/** client/html/checkout/standard/decorators/excludes
420
	 * Excludes decorators added by the "common" option from the checkout standard html client
421
	 *
422
	 * Decorators extend the functionality of a class by adding new aspects
423
	 * (e.g. log what is currently done), executing the methods of the underlying
424
	 * class only in certain conditions (e.g. only for logged in users) or
425
	 * modify what is returned to the caller.
426
	 *
427
	 * This option allows you to remove a decorator added via
428
	 * "client/html/common/decorators/default" before they are wrapped
429
	 * around the html client.
430
	 *
431
	 *  client/html/checkout/standard/decorators/excludes = array( 'decorator1' )
432
	 *
433
	 * This would remove the decorator named "decorator1" from the list of
434
	 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
435
	 * "client/html/common/decorators/default" to the html client.
436
	 *
437
	 * @param array List of decorator names
438
	 * @see client/html/common/decorators/default
439
	 * @see client/html/checkout/standard/decorators/global
440
	 * @see client/html/checkout/standard/decorators/local
441
	 */
442
443
	/** client/html/checkout/standard/decorators/global
444
	 * Adds a list of globally available decorators only to the checkout standard html client
445
	 *
446
	 * Decorators extend the functionality of a class by adding new aspects
447
	 * (e.g. log what is currently done), executing the methods of the underlying
448
	 * class only in certain conditions (e.g. only for logged in users) or
449
	 * modify what is returned to the caller.
450
	 *
451
	 * This option allows you to wrap global decorators
452
	 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
453
	 *
454
	 *  client/html/checkout/standard/decorators/global = array( 'decorator1' )
455
	 *
456
	 * This would add the decorator named "decorator1" defined by
457
	 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
458
	 *
459
	 * @param array List of decorator names
460
	 * @see client/html/common/decorators/default
461
	 * @see client/html/checkout/standard/decorators/excludes
462
	 * @see client/html/checkout/standard/decorators/local
463
	 */
464
465
	/** client/html/checkout/standard/decorators/local
466
	 * Adds a list of local decorators only to the checkout standard html client
467
	 *
468
	 * Decorators extend the functionality of a class by adding new aspects
469
	 * (e.g. log what is currently done), executing the methods of the underlying
470
	 * class only in certain conditions (e.g. only for logged in users) or
471
	 * modify what is returned to the caller.
472
	 *
473
	 * This option allows you to wrap local decorators
474
	 * ("\Aimeos\Client\Html\Checkout\Decorator\*") around the html client.
475
	 *
476
	 *  client/html/checkout/standard/decorators/local = array( 'decorator2' )
477
	 *
478
	 * This would add the decorator named "decorator2" defined by
479
	 * "\Aimeos\Client\Html\Checkout\Decorator\Decorator2" only to the html client.
480
	 *
481
	 * @param array List of decorator names
482
	 * @see client/html/common/decorators/default
483
	 * @see client/html/checkout/standard/decorators/excludes
484
	 * @see client/html/checkout/standard/decorators/global
485
	 */
486
}
487