Standard::body()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 80
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 3
nop 1
dl 0
loc 80
rs 9.5222
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 Aimeos (aimeos.org), 2015-2025
6
 * @package Client
7
 * @subpackage Html
8
 */
9
10
11
namespace Aimeos\Client\Html\Catalog\Lists;
12
13
14
/**
15
 * Default implementation of catalog list section HTML clients.
16
 *
17
 * @package Client
18
 * @subpackage Html
19
 */
20
class Standard
21
	extends \Aimeos\Client\Html\Catalog\Base
22
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
23
{
24
	/** client/html/catalog/lists/name
25
	 * Class name of the used catalog list client implementation
26
	 *
27
	 * Each default HTML client can be replace by an alternative imlementation.
28
	 * To use this implementation, you have to set the last part of the class
29
	 * name as configuration value so the client factory knows which class it
30
	 * has to instantiate.
31
	 *
32
	 * For example, if the name of the default class is
33
	 *
34
	 *  \Aimeos\Client\Html\Catalog\Lists\Standard
35
	 *
36
	 * and you want to replace it with your own version named
37
	 *
38
	 *  \Aimeos\Client\Html\Catalog\Lists\Mylist
39
	 *
40
	 * then you have to set the this configuration option:
41
	 *
42
	 *  client/html/catalog/lists/name = Mylist
43
	 *
44
	 * The value is the last part of your own class name and it's case sensitive,
45
	 * so take care that the configuration value is exactly named like the last
46
	 * part of the class name.
47
	 *
48
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
49
	 * characters are possible! You should always start the last part of the class
50
	 * name with an upper case character and continue only with lower case characters
51
	 * or numbers. Avoid chamel case names like "MyList"!
52
	 *
53
	 * @param string Last part of the class name
54
	 * @since 2014.03
55
	 */
56
57
58
	private array $tags = [];
59
	private ?string $expire = null;
60
	private ?\Aimeos\Base\View\Iface $view = null;
61
62
63
	/**
64
	 * Returns the HTML code for insertion into the body.
65
	 *
66
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
67
	 * @return string HTML code
68
	 */
69
	public function body( string $uid = '' ) : string
70
	{
71
		$view = $this->view();
72
		$prefixes = ['f_catid', 'f_supid', 'f_sort', 'l_page', 'l_type'];
73
74
		/** client/html/catalog/lists/cache
75
		 * Enables or disables caching only for the catalog lists component
76
		 *
77
		 * Disable caching for components can be useful if you would have too much
78
		 * entries to cache or if the component contains non-cacheable parts that
79
		 * can't be replaced using the modify() method.
80
		 *
81
		 * @param boolean True to enable caching, false to disable
82
		 * @see client/html/catalog/detail/cache
83
		 * @see client/html/catalog/filter/cache
84
		 * @see client/html/catalog/stage/cache
85
		 */
86
87
		/** client/html/catalog/lists
88
		 * All parameters defined for the catalog list component and its subparts
89
		 *
90
		 * This returns all settings related to the filter component.
91
		 * Please refer to the single settings for details.
92
		 *
93
		 * @param array Associative list of name/value settings
94
		 * @see client/html/catalog#list
95
		 */
96
		$confkey = 'client/html/catalog/lists';
97
98
		$args = map( $view->param() )->except( ['f_catid', 'f_name', 'f_supid', 's_name'] )->filter( function( $val, $key ) {
99
			return !strncmp( $key, 'f_', 2 ) || !strncmp( $key, 'l_', 2 );
100
		} );
101
102
		if( $args->isEmpty() && ( $html = $this->cached( 'body', $uid, $prefixes, $confkey ) ) !== null ) {
103
			return $this->modify( $html, $uid );
104
		}
105
106
		/** client/html/catalog/lists/template-body
107
		 * Relative path to the HTML body template of the catalog list client.
108
		 *
109
		 * The template file contains the HTML code and processing instructions
110
		 * to generate the result shown in the body of the frontend. The
111
		 * configuration string is the path to the template file relative
112
		 * to the templates directory (usually in templates/client/html).
113
		 *
114
		 * You can overwrite the template file configuration in extensions and
115
		 * provide alternative templates. These alternative templates should be
116
		 * named like the default one but suffixed by
117
		 * an unique name. You may use the name of your project for this. If
118
		 * you've implemented an alternative client class as well, it
119
		 * should be suffixed by the name of the new class.
120
		 *
121
		 * It's also possible to create a specific template for each type, e.g.
122
		 * for the grid, list or whatever view you want to offer your users. In
123
		 * that case, you can configure the template by adding "-<type>" to the
124
		 * configuration key. To configure an alternative list view template for
125
		 * example, use the key
126
		 *
127
		 * client/html/catalog/lists/template-body-list = catalog/lists/body-list.php
128
		 *
129
		 * The argument is the relative path to the new template file. The type of
130
		 * the view is determined by the "l_type" parameter (allowed characters for
131
		 * the types are a-z and 0-9). The catalog list type subpart
132
		 * contains the template for switching between list types.
133
		 *
134
		 * @param string Relative path to the template creating code for the HTML page body
135
		 * @since 2014.03
136
		 * @see client/html/catalog/lists/template-header
137
		 * @see client/html/catalog/lists/type/template-body
138
		 */
139
		$template = $this->context()->config()->get( 'client/html/catalog/lists/template-body', 'catalog/lists/body' );
140
141
		$view = $this->view = $this->view ?? $this->object()->data( $view, $this->tags, $this->expire );
142
		$html = $this->modify( $view->render( $template ), $uid );
143
144
		if( $args->isEmpty() ) {
145
			return $this->cache( 'body', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire );
146
		}
147
148
		return $html;
149
	}
150
151
152
	/**
153
	 * Returns the HTML string for insertion into the header.
154
	 *
155
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
156
	 * @return string|null String including HTML tags for the header on error
157
	 */
158
	public function header( string $uid = '' ) : ?string
159
	{
160
		$view = $this->view();
161
		$confkey = 'client/html/catalog/lists';
162
		$prefixes = ['f_catid', 'f_supid', 'f_sort', 'l_page', 'l_type'];
163
164
		$args = map( $view->param() )->except( ['f_catid', 'f_name', 'f_supid', 's_name'] )->filter( function( $val, $key ) {
165
			return !strncmp( $key, 'f_', 2 ) || !strncmp( $key, 'l_', 2 );
166
		} );
167
168
		if( $args->isEmpty() && ( $html = $this->cached( 'header', $uid, $prefixes, $confkey ) ) !== null ) {
169
			return $this->modify( $html, $uid );
170
		}
171
172
		/** client/html/catalog/lists/template-header
173
		 * Relative path to the HTML header template of the catalog list client.
174
		 *
175
		 * The template file contains the HTML code and processing instructions
176
		 * to generate the HTML code that is inserted into the HTML page header
177
		 * of the rendered page in the frontend. The configuration string is the
178
		 * path to the template file relative to the templates directory (usually
179
		 * in templates/client/html).
180
		 *
181
		 * You can overwrite the template file configuration in extensions and
182
		 * provide alternative templates. These alternative templates should be
183
		 * named like the default one but suffixed by
184
		 * an unique name. You may use the name of your project for this. If
185
		 * you've implemented an alternative client class as well, it
186
		 * should be suffixed by the name of the new class.
187
		 *
188
		 * It's also possible to create a specific template for each type, e.g.
189
		 * for the grid, list or whatever view you want to offer your users. In
190
		 * that case, you can configure the template by adding "-<type>" to the
191
		 * configuration key. To configure an alternative list view template for
192
		 * example, use the key
193
		 *
194
		 * client/html/catalog/lists/template-header-list = catalog/lists/header-list.php
195
		 *
196
		 * The argument is the relative path to the new template file. The type of
197
		 * the view is determined by the "l_type" parameter (allowed characters for
198
		 * the types are a-z and 0-9). The catalog list type subpart
199
		 * contains the template for switching between list types.
200
		 *
201
		 * @param string Relative path to the template creating code for the HTML page head
202
		 * @since 2014.03
203
		 * @see client/html/catalog/lists/template-body
204
		 * @see client/html/catalog/lists/type/template-body
205
		 */
206
		$template = $this->context()->config()->get( 'client/html/catalog/lists/template-header', 'catalog/lists/header' );
207
208
		$view = $this->view = $this->view ?? $this->object()->data( $view, $this->tags, $this->expire );
209
		$html = $this->modify( $view->render( $template ), $uid );
210
211
		if( $args->isEmpty() ) {
212
			return $this->cache( 'header', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire );
213
		}
214
215
		return $html;
216
	}
217
218
219
	/**
220
	 * Processes the input, e.g. store given values.
221
	 *
222
	 * A view must be available and this method doesn't generate any output
223
	 * besides setting view variables if necessary.
224
	 */
225
	public function init()
226
	{
227
		$view = $this->view();
228
		$context = $this->context();
229
		$session = $context->session();
230
231
		$params = $view->param();
232
		$site = $context->locale()->getSiteItem()->getCode();
233
		$key = $view->param( 'f_catid' ) ? 'client/html/catalog/tree/url' : 'client/html/catalog/lists/url';
234
235
		$session->set( 'aimeos/catalog/last/' . $site, $view->link( $key, $params ) );
236
		$session->set( 'aimeos/catalog/lists/params/last/' . $site, $params );
237
	}
238
239
240
	/**
241
	 * Sets the necessary parameter values in the view.
242
	 *
243
	 * @param \Aimeos\Base\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\Base\View\Iface Modified view object
247
	 */
248
	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface
249
	{
250
		$total = 0;
251
		$sort = $this->sort();
252
		$size = $this->size();
253
		$pages = $this->pages();
254
		$context = $this->context();
255
		$page = min( max( $view->param( 'l_page', 1 ), 1 ), $pages );
256
257
		if( !empty( $catIds = $this->categories() ) )
258
		{
259
			$listCatPath = \Aimeos\Controller\Frontend::create( $context, 'catalog' )
260
				->uses( ['media', 'media/property', 'text'] )
261
				->getPath( current( $catIds ) );
262
263
			$view->listCatPath = $this->addMetaItems( $listCatPath, $expire, $tags );
264
		}
265
266
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )
267
			->sort( $sort ) // prioritize user sorting over the sorting through relevance and category
268
			->text( $view->param( 'f_search' ) )
269
			->price( $view->param( 'f_price' ) )
270
			->category( $catIds, 'default', $this->level() )
271
			->radius( $view->param( 'f_point', [] ), $view->param( 'f_dist' ) )
272
			->supplier( $this->suppliers() )
273
			->allOf( $this->attributes() )
274
			->allOf( $view->param( 'f_attrid', [] ) )
275
			->oneOf( $view->param( 'f_optid', [] ) )
276
			->oneOf( $view->param( 'f_oneid', [] ) )
277
			->slice( ( $page - 1 ) * $size, $size )
278
			->uses( $this->domains() );
279
280
		$this->call( 'conditions', $cntl, $view );
281
282
		$products = $cntl->search( $total );
283
		$articles = $products->getRefItems( 'product', 'default', 'default' )->flat( 1 )->union( $products );
284
285
		$attrMap = $articles->getRefItems( 'attribute' )->flat( 1 )->groupBy( 'attribute.type' );
286
		$attrTypes = $this->attributeTypes( $attrMap->keys() );
287
288
		$this->addMetaItems( $products, $expire, $tags, ['product'] );
289
290
291
		$view->listProductItems = $products;
292
		$view->listProductSort = $sort;
293
		$view->listProductTotal = $total;
294
295
		$view->listPageSize = $size;
296
		$view->listPageCurr = $page;
297
		$view->listPagePrev = ( $page > 1 ? $page - 1 : 1 );
298
		$view->listPageLast = ( $total != 0 ? min( ceil( $total / $size ), $pages ) : 1 );
0 ignored issues
show
introduced by
The condition $total != 0 is always false.
Loading history...
299
		$view->listPageNext = ( $page < $view->listPageLast ? $page + 1 : $view->listPageLast );
300
301
		$view->listAttributeTypes = $attrTypes->col( null, 'attribute.type.code' );
302
		$view->listParams = $this->getClientParams( map( $view->param() )->toArray() );
303
		$view->listStockUrl = $this->stockUrl( $articles );
304
		$view->listPosition = ( $page - 1 ) * $size;
305
306
		if( !empty( $type = $view->param( 'l_type' ) ) && ctype_alnum( $type ) ) {
307
			return $view->set( 'listPartial', 'catalog/lists/items-' . $type );
308
		}
309
310
		return parent::data( $view, $tags, $expire );
311
	}
312
313
314
	/**
315
	 * Modifies the cached content to replace content based on sessions or cookies.
316
	 *
317
	 * @param string $content Cached content
318
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
319
	 * @return string Modified content
320
	 */
321
	public function modify( string $content, string $uid ) : string
322
	{
323
		return $this->replaceSection( $content, $this->view()->csrf()->formfield(), 'catalog.lists.items.csrf' );
324
	}
325
326
327
	/**
328
	 * Returns the attribute IDs used for filtering products
329
	 *
330
	 * @return array List of attribute IDs
331
	 */
332
	protected function attributes() : array
333
	{
334
		/** client/html/catalog/lists/attrid-default
335
		 * Additional attribute IDs used to limit search results
336
		 *
337
		 * Using this setting, products result lists can be limited by additional
338
		 * attributes. Then, only products which have associated the configured
339
		 * attribute IDs will be returned and shown in the frontend. The value
340
		 * can be either a single attribute ID or a list of attribute IDs.
341
		 *
342
		 * @param array|string Attribute ID or IDs
343
		 * @since 2021.10
344
		 * @see client/html/catalog/lists/sort
345
		 * @see client/html/catalog/lists/size
346
		 * @see client/html/catalog/lists/domains
347
		 * @see client/html/catalog/lists/levels
348
		 * @see client/html/catalog/lists/catid-default
349
		 * @see client/html/catalog/lists/supid-default
350
		 * @see client/html/catalog/detail/prodid-default
351
		 * @see client/html/catalog/instock
352
		 */
353
		$attrids = $this->context()->config()->get( 'client/html/catalog/lists/attrid-default' );
354
		$attrids = $attrids != null && is_scalar( $attrids ) ? explode( ',', $attrids ) : $attrids; // workaround for TYPO3
355
356
		return (array) $attrids;
357
	}
358
359
360
	/**
361
	 * Returns the attribute type items for the given codes
362
	 *
363
	 * @param \Aimeos\Map $codes List of attribute type codes
364
	 * @return \Aimeos\Map List of attribute type items
365
	 */
366
	protected function attributeTypes( \Aimeos\Map $codes ) : \Aimeos\Map
367
	{
368
		$manager = \Aimeos\MShop::create( $this->context(), 'attribute/type' );
369
370
		$filter = $manager->filter( true )
371
			->add( 'attribute.type.domain', '==', 'product' )
372
			->add( 'attribute.type.code', '==', $codes )
373
			->order( 'attribute.type.position' );
374
375
		return $manager->search( $filter->slice( 0, count( $codes ) ) );
376
	}
377
378
379
	/**
380
	 * Returns the category IDs used for filtering products
381
	 *
382
	 * @return array List of category IDs
383
	 */
384
	protected function categories() : array
385
	{
386
		/** client/html/catalog/lists/catid-default
387
		 * The default category ID used if none is given as parameter
388
		 *
389
		 * If users view a product list page without a category ID in the
390
		 * parameter list, the first found products are displayed with a
391
		 * random order. You can circumvent this by configuring a default
392
		 * category ID that should be used in this case (the ID of the root
393
		 * category is best for this). In most cases you can set this value
394
		 * via the administration interface of the shop application.
395
		 *
396
		 * @param array|string Category ID or IDs
397
		 * @since 2014.03
398
		 * @see client/html/catalog/lists/sort
399
		 * @see client/html/catalog/lists/size
400
		 * @see client/html/catalog/lists/domains
401
		 * @see client/html/catalog/lists/levels
402
		 * @see client/html/catalog/lists/attrid-default
403
		 * @see client/html/catalog/detail/prodid-default
404
		 * @see client/html/catalog/lists/supid-default
405
		 * @see client/html/catalog/instock
406
		 */
407
		$catids = $this->view()->param( 'f_catid', $this->context()->config()->get( 'client/html/catalog/lists/catid-default' ) );
408
		$catids = $catids != null && is_scalar( $catids ) ? explode( ',', $catids ) : $catids; // workaround for TYPO3
409
410
		return array_filter( (array) $catids );
411
	}
412
413
414
	/**
415
	 * Adds additional conditions for filtering
416
	 *
417
	 * @param \Aimeos\Controller\Frontend\Product\Iface $cntl Product controller
418
	 * @param \Aimeos\Base\View\Iface $view View object
419
	 */
420
	protected function conditions( \Aimeos\Controller\Frontend\Product\Iface $cntl, \Aimeos\Base\View\Iface $view )
421
	{
422
		/** client/html/catalog/instock
423
		 * Show only products which are in stock
424
		 *
425
		 * This configuration option overwrites the "client/html/catalog/domains"
426
		 * option that allows to configure the domain names of the items fetched
427
		 * for all catalog related data.
428
		 *
429
		 * @param int Zero to show all products, "1" to show only products with stock
430
		 * @since 2021.10
431
		 * @see client/html/catalog/domains
432
		 * @see client/html/catalog/lists/domains
433
		 * @see client/html/catalog/detail/domains
434
		 * @see client/html/catalog/stage/domains
435
		 * @see client/html/catalog/lists/attrid-default
436
		 * @see client/html/catalog/lists/catid-default
437
		 * @see client/html/catalog/lists/supid-default
438
		 * @see client/html/catalog/lists/size
439
		 * @see client/html/catalog/lists/levels
440
		 * @see client/html/catalog/lists/sort
441
		 * @see client/html/catalog/lists/pages
442
		 */
443
444
		if( $view->config( 'client/html/catalog/instock', false ) ) {
445
			$cntl->compare( '>', 'product.instock', 0 );
446
		}
447
	}
448
449
450
	/**
451
	 * Returns the data domains fetched along with the products
452
	 *
453
	 * @return array List of domain names
454
	 */
455
	protected function domains() : array
456
	{
457
		$config = $this->context()->config();
458
		$domains = ['catalog', 'media', 'media/property', 'price', 'supplier', 'text'];
459
460
		/** client/html/catalog/domains
461
		 * A list of domain names whose items should be available in the catalog view templates
462
		 *
463
		 * The templates rendering catalog related data usually add the images and
464
		 * texts associated to each item. If you want to display additional
465
		 * content like the attributes, you can configure your own list of
466
		 * domains (attribute, media, price, product, text, etc. are domains)
467
		 * whose items are fetched from the storage. Please keep in mind that
468
		 * the more domains you add to the configuration, the more time is required
469
		 * for fetching the content!
470
		 *
471
		 * This configuration option can be overwritten by the "client/html/catalog/lists/domains"
472
		 * configuration option that allows to configure the domain names of the
473
		 * items fetched specifically for all types of product listings.
474
		 *
475
		 * @param array List of domain names
476
		 * @since 2014.03
477
		 * @see client/html/catalog/lists/domains
478
		 * @see client/html/catalog/lists/size
479
		 * @see client/html/catalog/lists/levels
480
		 * @see client/html/catalog/lists/sort
481
		 * @see client/html/catalog/lists/pages
482
		 */
483
		$domains = $config->get( 'client/html/catalog/domains', $domains );
484
485
		/** client/html/catalog/lists/domains
486
		 * A list of domain names whose items should be available in the product list view template
487
		 *
488
		 * The templates rendering product lists usually add the images, prices
489
		 * and texts associated to each product item. If you want to display additional
490
		 * content like the product attributes, you can configure your own list of
491
		 * domains (attribute, media, price, product, text, etc. are domains)
492
		 * whose items are fetched from the storage. Please keep in mind that
493
		 * the more domains you add to the configuration, the more time is required
494
		 * for fetching the content!
495
		 *
496
		 * This configuration option overwrites the "client/html/catalog/domains"
497
		 * option that allows to configure the domain names of the items fetched
498
		 * for all catalog related data.
499
		 *
500
		 * @param array List of domain names
501
		 * @since 2014.03
502
		 * @see client/html/catalog/domains
503
		 * @see client/html/catalog/detail/domains
504
		 * @see client/html/catalog/stage/domains
505
		 * @see client/html/catalog/lists/attrid-default
506
		 * @see client/html/catalog/lists/catid-default
507
		 * @see client/html/catalog/lists/supid-default
508
		 * @see client/html/catalog/lists/size
509
		 * @see client/html/catalog/lists/levels
510
		 * @see client/html/catalog/lists/sort
511
		 * @see client/html/catalog/lists/pages
512
		 * @see client/html/catalog/instock
513
		 */
514
		$domains = $config->get( 'client/html/catalog/lists/domains', $domains );
515
516
		if( $config->get( 'client/html/catalog/lists/basket-add', false ) ) {
517
			$domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] );
518
		}
519
520
		return $domains;
521
	}
522
523
524
	/**
525
	 * Returns the category depth level
526
	 *
527
	 * @return int Category depth level
528
	 */
529
	protected function level() : int
530
	{
531
		/** client/html/catalog/lists/levels
532
		 * Include products of sub-categories in the product list of the current category
533
		 *
534
		 * Sometimes it may be useful to show products of sub-categories in the
535
		 * current category product list, e.g. if the current category contains
536
		 * no products at all or if there are only a few products in all categories.
537
		 *
538
		 * Possible constant values for this setting are:
539
		 *
540
		 * * 1 : Only products from the current category
541
		 * * 2 : Products from the current category and the direct child categories
542
		 * * 3 : Products from the current category and the whole category sub-tree
543
		 *
544
		 * Caution: Please keep in mind that displaying products of sub-categories
545
		 * can slow down your shop, especially if it contains more than a few
546
		 * products! You have no real control over the positions of the products
547
		 * in the result list too because all products from different categories
548
		 * with the same position value are placed randomly.
549
		 *
550
		 * Usually, a better way is to associate products to all categories they
551
		 * should be listed in. This can be done manually if there are only a few
552
		 * ones or during the product import automatically.
553
		 *
554
		 * @param integer Tree level constant
555
		 * @since 2015.11
556
		 * @see client/html/catalog/lists/attrid-default
557
		 * @see client/html/catalog/lists/catid-default
558
		 * @see client/html/catalog/lists/supid-default
559
		 * @see client/html/catalog/lists/domains
560
		 * @see client/html/catalog/lists/size
561
		 * @see client/html/catalog/lists/sort
562
		 * @see client/html/catalog/lists/pages
563
		 * @see client/html/catalog/instock
564
		 */
565
		return $this->context()->config()->get( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
566
	}
567
568
569
	/**
570
	 * Returns the number of allowed pages
571
	 *
572
	 * @return int Number of allowed pages
573
	 */
574
	protected function pages() : int
575
	{
576
		/** client/html/catalog/lists/pages
577
		 * Maximum number of product pages shown in pagination
578
		 *
579
		 * Limits the number of product pages that are shown in the navigation.
580
		 * The user is able to move to the next page (or previous one if it's not
581
		 * the first) to display the next (or previous) products.
582
		 *
583
		 * The value must be a positive integer number. Negative values are not
584
		 * allowed. The value can't be overwritten per request.
585
		 *
586
		 * @param integer Number of pages
587
		 * @since 2019.04
588
		 * @see client/html/catalog/lists/attrid-default
589
		 * @see client/html/catalog/lists/catid-default
590
		 * @see client/html/catalog/lists/supid-default
591
		 * @see client/html/catalog/lists/domains
592
		 * @see client/html/catalog/lists/levels
593
		 * @see client/html/catalog/lists/sort
594
		 * @see client/html/catalog/lists/size
595
		 * @see client/html/catalog/instock
596
		 */
597
		return $this->context()->config()->get( 'client/html/catalog/lists/pages', 100 );
598
	}
599
600
601
	/**
602
	 * Returns the maximum products per page
603
	 *
604
	 * @return int Maximum products per page
605
	 */
606
	protected function size() : int
607
	{
608
		/** client/html/catalog/lists/size
609
		 * The number of products shown in a list page
610
		 *
611
		 * Limits the number of products that are shown in the list pages to the
612
		 * given value. If more products are available, the products are split
613
		 * into bunches which will be shown on their own list page. The user is
614
		 * able to move to the next page (or previous one if it's not the first)
615
		 * to display the next (or previous) products.
616
		 *
617
		 * The value must be an integer number from 1 to 100. Negative values as
618
		 * well as values above 100 are not allowed. The value can be overwritten
619
		 * per request if the "l_size" parameter is part of the URL.
620
		 *
621
		 * @param integer Number of products
622
		 * @since 2014.03
623
		 * @see client/html/catalog/lists/attrid-default
624
		 * @see client/html/catalog/lists/catid-default
625
		 * @see client/html/catalog/lists/supid-default
626
		 * @see client/html/catalog/lists/domains
627
		 * @see client/html/catalog/lists/levels
628
		 * @see client/html/catalog/lists/sort
629
		 * @see client/html/catalog/lists/pages
630
		 * @see client/html/catalog/instock
631
		 */
632
		$size = $this->context()->config()->get( 'client/html/catalog/lists/size', 48 );
633
634
		return min( max( $this->view()->param( 'l_size', $size ), 1 ), 100 );
635
	}
636
637
638
	/**
639
	 * Returns the product sorting
640
	 *
641
	 * @return string Product sorting
642
	 */
643
	protected function sort() : string
644
	{
645
		/** client/html/catalog/lists/sort
646
		 * Default sorting of product list if no other sorting is given by parameter
647
		 *
648
		 * Configures the standard sorting of products in list views. This sorting is used
649
		 * as long as it's not overwritten by an URL parameter. Except "relevance", all
650
		 * other sort codes can be prefixed by a "-" (minus) sign to sort the products in
651
		 * a descending order. By default, the sorting is ascending.
652
		 *
653
		 * @param string Sort code "relevance", "name", "-name", "price", "-price", "ctime" or "-ctime"
654
		 * @since 2018.07
655
		 * @see client/html/catalog/lists/attrid-default
656
		 * @see client/html/catalog/lists/catid-default
657
		 * @see client/html/catalog/lists/supid-default
658
		 * @see client/html/catalog/lists/domains
659
		 * @see client/html/catalog/lists/levels
660
		 * @see client/html/catalog/lists/size
661
		 * @see client/html/catalog/instock
662
		 */
663
		return $this->view()->param( 'f_sort', $this->context()->config()->get( 'client/html/catalog/lists/sort', 'relevance' ) );
664
	}
665
666
667
	/**
668
	 * Returns the supplier IDs used for filtering products
669
	 *
670
	 * @return array List of supplier IDs
671
	 */
672
	protected function suppliers() : array
673
	{
674
		/** client/html/catalog/lists/supid-default
675
		 * The default supplier ID used if none is given as parameter
676
		 *
677
		 * Products in the list page can be limited to one or more suppliers.
678
		 * By default, the products are not limited to any supplier until one or
679
		 * more supplier IDs are passed in the URL using the f_supid parameter.
680
		 * You can also configure the default supplier IDs for limiting the
681
		 * products if no IDs are passed in the URL using this configuration.
682
		 *
683
		 * @param array|string Supplier ID or IDs
684
		 * @since 2021.01
685
		 * @see client/html/catalog/lists/sort
686
		 * @see client/html/catalog/lists/size
687
		 * @see client/html/catalog/lists/domains
688
		 * @see client/html/catalog/lists/levels
689
		 * @see client/html/catalog/lists/attrid-default
690
		 * @see client/html/catalog/lists/catid-default
691
		 * @see client/html/catalog/detail/prodid-default
692
		 * @see client/html/catalog/instock
693
		 */
694
		$supids = $this->view()->param( 'f_supid', $this->context()->config()->get( 'client/html/catalog/lists/supid-default' ) );
695
		$supids = $supids != null && is_scalar( $supids ) ? explode( ',', $supids ) : $supids; // workaround for TYPO3
696
697
		return (array) $supids;
698
	}
699
700
701
	/**
702
	 * Returns the URLs for fetching stock information
703
	 *
704
	 * @param \Aimeos\Map $products Products to fetch stock information for
705
	 * @return \Aimeos\Map List of stock URLs
706
	 */
707
	protected function stockUrl( \Aimeos\Map $products ) : \Aimeos\Map
708
	{
709
		/** client/html/catalog/lists/stock
710
		 * Enables or disables displaying product stock levels in product list views
711
		 *
712
		 * This configuration option allows shop owners to display product
713
		 * stock levels for each product in list views or to disable
714
		 * fetching product stock information.
715
		 *
716
		 * The stock information is fetched via AJAX and inserted via Javascript.
717
		 * This allows to cache product items by leaving out such highly
718
		 * dynamic content like stock levels which changes with each order.
719
		 *
720
		 * @param boolean Value of "1" to display stock levels, "0" to disable displaying them
721
		 * @since 2014.03
722
		 * @see client/html/catalog/detail/stock/enable
723
		 * @see client/html/catalog/stock/url/target
724
		 * @see client/html/catalog/stock/url/controller
725
		 * @see client/html/catalog/stock/url/action
726
		 * @see client/html/catalog/stock/url/config
727
		 */
728
		if( !$products->isEmpty() && $this->context()->config()->get( 'client/html/catalog/lists/stock', true ) ) {
729
			return $this->getStockUrl( $this->view(), $products );
730
		}
731
732
		return map();
733
	}
734
735
736
	/** client/html/catalog/lists/decorators/excludes
737
	 * Excludes decorators added by the "common" option from the catalog lists html client
738
	 *
739
	 * Decorators extend the functionality of a class by adding new aspects
740
	 * (e.g. log what is currently done), executing the methods of the underlying
741
	 * class only in certain conditions (e.g. only for logged in users) or
742
	 * modify what is returned to the caller.
743
	 *
744
	 * This option allows you to remove a decorator added via
745
	 * "client/html/common/decorators/default" before they are wrapped
746
	 * around the html client.
747
	 *
748
	 *  client/html/catalog/lists/decorators/excludes = array( 'decorator1' )
749
	 *
750
	 * This would remove the decorator named "decorator1" from the list of
751
	 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
752
	 * "client/html/common/decorators/default" to the html client.
753
	 *
754
	 * @param array List of decorator names
755
	 * @see client/html/common/decorators/default
756
	 * @see client/html/catalog/lists/decorators/global
757
	 * @see client/html/catalog/lists/decorators/local
758
	 */
759
760
	/** client/html/catalog/lists/decorators/global
761
	 * Adds a list of globally available decorators only to the catalog lists html client
762
	 *
763
	 * Decorators extend the functionality of a class by adding new aspects
764
	 * (e.g. log what is currently done), executing the methods of the underlying
765
	 * class only in certain conditions (e.g. only for logged in users) or
766
	 * modify what is returned to the caller.
767
	 *
768
	 * This option allows you to wrap global decorators
769
	 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
770
	 *
771
	 *  client/html/catalog/lists/decorators/global = array( 'decorator1' )
772
	 *
773
	 * This would add the decorator named "decorator1" defined by
774
	 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
775
	 *
776
	 * @param array List of decorator names
777
	 * @see client/html/common/decorators/default
778
	 * @see client/html/catalog/lists/decorators/excludes
779
	 * @see client/html/catalog/lists/decorators/local
780
	 */
781
782
	/** client/html/catalog/lists/decorators/local
783
	 * Adds a list of local decorators only to the catalog lists html client
784
	 *
785
	 * Decorators extend the functionality of a class by adding new aspects
786
	 * (e.g. log what is currently done), executing the methods of the underlying
787
	 * class only in certain conditions (e.g. only for logged in users) or
788
	 * modify what is returned to the caller.
789
	 *
790
	 * This option allows you to wrap local decorators
791
	 * ("\Aimeos\Client\Html\Catalog\Decorator\*") around the html client.
792
	 *
793
	 *  client/html/catalog/lists/decorators/local = array( 'decorator2' )
794
	 *
795
	 * This would add the decorator named "decorator2" defined by
796
	 * "\Aimeos\Client\Html\Catalog\Decorator\Decorator2" only to the html client.
797
	 *
798
	 * @param array List of decorator names
799
	 * @see client/html/common/decorators/default
800
	 * @see client/html/catalog/lists/decorators/excludes
801
	 * @see client/html/catalog/lists/decorators/global
802
	 */
803
}
804