Passed
Push — master ( 023332...bb13e9 )
by Aimeos
02:47
created

Standard::conditions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 26
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
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 $tags = [];
59
	private $expire;
60
	private $view;
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( $prefixes )->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 client/html/templates).
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( $prefixes )->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 client/html/templates).
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
230
		$site = $context->locale()->getSiteItem()->getCode();
231
		$params = $this->getClientParams( $view->param() );
232
233
		$catId = $context->config()->get( 'client/html/catalog/lists/catid-default' );
234
235
		if( ( $catId = $view->param( 'f_catid', $catId ) ) )
236
		{
237
			$params['f_name'] = $view->param( 'f_name' );
238
			$params['f_catid'] = $catId;
239
		}
240
241
		$context->session()->set( 'aimeos/catalog/lists/params/last/' . $site, $params );
242
	}
243
244
245
	/**
246
	 * Sets the necessary parameter values in the view.
247
	 *
248
	 * @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output
249
	 * @param array &$tags Result array for the list of tags that are associated to the output
250
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
251
	 * @return \Aimeos\Base\View\Iface Modified view object
252
	 */
253
	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
254
	{
255
		$total = 0;
256
		$sort = $this->sort();
257
		$size = $this->size();
258
		$pages = $this->pages();
259
		$context = $this->context();
260
		$page = min( max( $view->param( 'l_page', 1 ), 1 ), $pages );
261
262
		if( !empty( $catIds = $this->categories() ) )
263
		{
264
			$listCatPath = \Aimeos\Controller\Frontend::create( $context, 'catalog' )
265
				->uses( ['media', 'media/property', 'text'] )
266
				->getPath( current( $catIds ) );
267
268
			$view->listCatPath = $this->addMetaItems( $listCatPath, $expire, $tags );
269
		}
270
271
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )
272
			->sort( $sort ) // prioritize user sorting over the sorting through relevance and category
273
			->text( $view->param( 'f_search' ) )
274
			->price( $view->param( 'f_price' ) )
275
			->category( $catIds, 'default', $this->level() )
276
			->radius( $view->param( 'f_point', [] ), $view->param( 'f_dist' ) )
277
			->supplier( $this->suppliers() )
278
			->allOf( $this->attributes() )
279
			->allOf( $view->param( 'f_attrid', [] ) )
280
			->oneOf( $view->param( 'f_optid', [] ) )
281
			->oneOf( $view->param( 'f_oneid', [] ) )
282
			->slice( ( $page - 1 ) * $size, $size )
283
			->uses( $this->domains() );
284
285
		$this->call( 'conditions', $cntl, $view );
286
287
		$products = $cntl->search( $total );
288
		$articles = $products->getRefItems( 'product', 'default', 'default' )->flat( 1 )->union( $products );
289
290
		// Delete cache when products are added or deleted even when in "tag-all" mode
291
		$this->addMetaItems( $articles, $expire, $tags, ['product'] );
292
293
294
		$view->listProductItems = $products;
295
		$view->listProductSort = $sort;
296
		$view->listProductTotal = $total;
297
298
		$view->listPageSize = $size;
299
		$view->listPageCurr = $page;
300
		$view->listPagePrev = ( $page > 1 ? $page - 1 : 1 );
301
		$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...
302
		$view->listPageNext = ( $page < $view->listPageLast ? $page + 1 : $view->listPageLast );
303
304
		$view->listParams = $this->getClientParams( map( $view->param() )->toArray() );
305
		$view->listStockUrl = $this->stockUrl( $articles );
306
		$view->listPosition = ( $page - 1 ) * $size;
307
308
		if( !empty( $type = $view->param( 'l_type' ) ) && ctype_alnum( $type ) ) {
309
			return $view->set( 'listPartial', 'catalog/lists/items-' . $type );
310
		}
311
312
		return parent::data( $view, $tags, $expire );
313
	}
314
315
316
	/**
317
	 * Modifies the cached content to replace content based on sessions or cookies.
318
	 *
319
	 * @param string $content Cached content
320
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
321
	 * @return string Modified content
322
	 */
323
	public function modify( string $content, string $uid ) : string
324
	{
325
		return $this->replaceSection( $content, $this->view()->csrf()->formfield(), 'catalog.lists.csrf' );
326
	}
327
328
329
	/**
330
	 * Returns the attribute IDs used for filtering products
331
	 *
332
	 * @return array List of attribute IDs
333
	 */
334
	protected function attributes() : array
335
	{
336
		/** client/html/catalog/lists/attrid-default
337
		 * Additional attribute IDs used to limit search results
338
		 *
339
		 * Using this setting, products result lists can be limited by additional
340
		 * attributes. Then, only products which have associated the configured
341
		 * attribute IDs will be returned and shown in the frontend. The value
342
		 * can be either a single attribute ID or a list of attribute IDs.
343
		 *
344
		 * @param array|string Attribute ID or IDs
345
		 * @since 2021.10
346
		 * @see client/html/catalog/lists/sort
347
		 * @see client/html/catalog/lists/size
348
		 * @see client/html/catalog/lists/domains
349
		 * @see client/html/catalog/lists/levels
350
		 * @see client/html/catalog/lists/instock
351
		 * @see client/html/catalog/lists/catid-default
352
		 * @see client/html/catalog/lists/supid-default
353
		 * @see client/html/catalog/detail/prodid-default
354
		 */
355
		$attrids = $this->context()->config()->get( 'client/html/catalog/lists/attrid-default' );
356
		$attrids = $attrids != null && is_scalar( $attrids ) ? explode( ',', $attrids ) : $attrids; // workaround for TYPO3
357
358
		return (array) $attrids;
359
	}
360
361
362
	/**
363
	 * Returns the category IDs used for filtering products
364
	 *
365
	 * @return array List of category IDs
366
	 */
367
	protected function categories() : array
368
	{
369
		/** client/html/catalog/lists/catid-default
370
		 * The default category ID used if none is given as parameter
371
		 *
372
		 * If users view a product list page without a category ID in the
373
		 * parameter list, the first found products are displayed with a
374
		 * random order. You can circumvent this by configuring a default
375
		 * category ID that should be used in this case (the ID of the root
376
		 * category is best for this). In most cases you can set this value
377
		 * via the administration interface of the shop application.
378
		 *
379
		 * @param array|string Category ID or IDs
380
		 * @since 2014.03
381
		 * @see client/html/catalog/lists/sort
382
		 * @see client/html/catalog/lists/size
383
		 * @see client/html/catalog/lists/domains
384
		 * @see client/html/catalog/lists/levels
385
		 * @see client/html/catalog/lists/attrid-default
386
		 * @see client/html/catalog/detail/prodid-default
387
		 * @see client/html/catalog/lists/supid-default
388
		 * @see client/html/catalog/lists/instock
389
		 */
390
		$catids = $this->view()->param( 'f_catid', $this->context()->config()->get( 'client/html/catalog/lists/catid-default' ) );
391
		$catids = $catids != null && is_scalar( $catids ) ? explode( ',', $catids ) : $catids; // workaround for TYPO3
392
393
		return array_filter( (array) $catids );
394
	}
395
396
397
	/**
398
	 * If all shown products must be in stock
399
	 *
400
	 * @return bool TRUE if all products must be in stock, FALSE if not
401
	 */
402
	protected function conditions( \Aimeos\Controller\Frontend\Product\Iface $cntl, \Aimeos\Base\View\Iface $view )
403
	{
404
		/** client/html/catalog/lists/instock
405
		 * Show only products which are in stock
406
		 *
407
		 * This configuration option overwrites the "client/html/catalog/domains"
408
		 * option that allows to configure the domain names of the items fetched
409
		 * for all catalog related data.
410
		 *
411
		 * @param int Zero to show all products, "1" to show only products with stock
412
		 * @since 2021.10
413
		 * @see client/html/catalog/domains
414
		 * @see client/html/catalog/lists/domains
415
		 * @see client/html/catalog/detail/domains
416
		 * @see client/html/catalog/stage/domains
417
		 * @see client/html/catalog/lists/attrid-default
418
		 * @see client/html/catalog/lists/catid-default
419
		 * @see client/html/catalog/lists/supid-default
420
		 * @see client/html/catalog/lists/size
421
		 * @see client/html/catalog/lists/levels
422
		 * @see client/html/catalog/lists/sort
423
		 * @see client/html/catalog/lists/pages
424
		 */
425
426
		if( $view->config( 'client/html/catalog/lists/instock', false ) ) {
427
			$cntl->compare( '>', 'product.instock', 0 );
428
		}
429
	}
430
431
432
	/**
433
	 * Returns the data domains fetched along with the products
434
	 *
435
	 * @return array List of domain names
436
	 */
437
	protected function domains() : array
438
	{
439
		$config = $this->context()->config();
440
		$domains = ['catalog', 'media', 'media/property', 'price', 'supplier', 'text'];
441
442
		/** client/html/catalog/domains
443
		 * A list of domain names whose items should be available in the catalog view templates
444
		 *
445
		 * The templates rendering catalog related data usually add the images and
446
		 * texts associated to each item. If you want to display additional
447
		 * content like the attributes, you can configure your own list of
448
		 * domains (attribute, media, price, product, text, etc. are domains)
449
		 * whose items are fetched from the storage. Please keep in mind that
450
		 * the more domains you add to the configuration, the more time is required
451
		 * for fetching the content!
452
		 *
453
		 * This configuration option can be overwritten by the "client/html/catalog/lists/domains"
454
		 * configuration option that allows to configure the domain names of the
455
		 * items fetched specifically for all types of product listings.
456
		 *
457
		 * @param array List of domain names
458
		 * @since 2014.03
459
		 * @see client/html/catalog/lists/domains
460
		 * @see client/html/catalog/lists/size
461
		 * @see client/html/catalog/lists/levels
462
		 * @see client/html/catalog/lists/sort
463
		 * @see client/html/catalog/lists/pages
464
		 */
465
		$domains = $config->get( 'client/html/catalog/domains', $domains );
466
467
		/** client/html/catalog/lists/domains
468
		 * A list of domain names whose items should be available in the product list view template
469
		 *
470
		 * The templates rendering product lists usually add the images, prices
471
		 * and texts associated to each product item. If you want to display additional
472
		 * content like the product attributes, you can configure your own list of
473
		 * domains (attribute, media, price, product, text, etc. are domains)
474
		 * whose items are fetched from the storage. Please keep in mind that
475
		 * the more domains you add to the configuration, the more time is required
476
		 * for fetching the content!
477
		 *
478
		 * This configuration option overwrites the "client/html/catalog/domains"
479
		 * option that allows to configure the domain names of the items fetched
480
		 * for all catalog related data.
481
		 *
482
		 * @param array List of domain names
483
		 * @since 2014.03
484
		 * @see client/html/catalog/domains
485
		 * @see client/html/catalog/detail/domains
486
		 * @see client/html/catalog/stage/domains
487
		 * @see client/html/catalog/lists/attrid-default
488
		 * @see client/html/catalog/lists/catid-default
489
		 * @see client/html/catalog/lists/supid-default
490
		 * @see client/html/catalog/lists/size
491
		 * @see client/html/catalog/lists/levels
492
		 * @see client/html/catalog/lists/sort
493
		 * @see client/html/catalog/lists/pages
494
		 * @see client/html/catalog/lists/instock
495
		 */
496
		$domains = $config->get( 'client/html/catalog/lists/domains', $domains );
497
498
		if( $config->get( 'client/html/catalog/lists/basket-add', false ) ) {
499
			$domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] );
500
		}
501
502
		return $domains;
503
	}
504
505
506
	/**
507
	 * Returns the category depth level
508
	 *
509
	 * @return int Category depth level
510
	 */
511
	protected function level() : int
512
	{
513
		/** client/html/catalog/lists/levels
514
		 * Include products of sub-categories in the product list of the current category
515
		 *
516
		 * Sometimes it may be useful to show products of sub-categories in the
517
		 * current category product list, e.g. if the current category contains
518
		 * no products at all or if there are only a few products in all categories.
519
		 *
520
		 * Possible constant values for this setting are:
521
		 *
522
		 * * 1 : Only products from the current category
523
		 * * 2 : Products from the current category and the direct child categories
524
		 * * 3 : Products from the current category and the whole category sub-tree
525
		 *
526
		 * Caution: Please keep in mind that displaying products of sub-categories
527
		 * can slow down your shop, especially if it contains more than a few
528
		 * products! You have no real control over the positions of the products
529
		 * in the result list too because all products from different categories
530
		 * with the same position value are placed randomly.
531
		 *
532
		 * Usually, a better way is to associate products to all categories they
533
		 * should be listed in. This can be done manually if there are only a few
534
		 * ones or during the product import automatically.
535
		 *
536
		 * @param integer Tree level constant
537
		 * @since 2015.11
538
		 * @see client/html/catalog/lists/attrid-default
539
		 * @see client/html/catalog/lists/catid-default
540
		 * @see client/html/catalog/lists/supid-default
541
		 * @see client/html/catalog/lists/domains
542
		 * @see client/html/catalog/lists/size
543
		 * @see client/html/catalog/lists/sort
544
		 * @see client/html/catalog/lists/pages
545
		 * @see client/html/catalog/lists/instock
546
		 */
547
		return $this->context()->config()->get( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
548
	}
549
550
551
	/**
552
	 * Returns the number of allowed pages
553
	 *
554
	 * @return int Number of allowed pages
555
	 */
556
	protected function pages() : int
557
	{
558
		/** client/html/catalog/lists/pages
559
		 * Maximum number of product pages shown in pagination
560
		 *
561
		 * Limits the number of product pages that are shown in the navigation.
562
		 * The user is able to move to the next page (or previous one if it's not
563
		 * the first) to display the next (or previous) products.
564
		 *
565
		 * The value must be a positive integer number. Negative values are not
566
		 * allowed. The value can't be overwritten per request.
567
		 *
568
		 * @param integer Number of pages
569
		 * @since 2019.04
570
		 * @see client/html/catalog/lists/attrid-default
571
		 * @see client/html/catalog/lists/catid-default
572
		 * @see client/html/catalog/lists/supid-default
573
		 * @see client/html/catalog/lists/domains
574
		 * @see client/html/catalog/lists/levels
575
		 * @see client/html/catalog/lists/sort
576
		 * @see client/html/catalog/lists/size
577
		 * @see client/html/catalog/lists/instock
578
		 */
579
		return $this->context()->config()->get( 'client/html/catalog/lists/pages', 100 );
580
	}
581
582
583
	/**
584
	 * Returns the maximum products per page
585
	 *
586
	 * @return int Maximum products per page
587
	 */
588
	protected function size() : int
589
	{
590
		/** client/html/catalog/lists/size
591
		 * The number of products shown in a list page
592
		 *
593
		 * Limits the number of products that are shown in the list pages to the
594
		 * given value. If more products are available, the products are split
595
		 * into bunches which will be shown on their own list page. The user is
596
		 * able to move to the next page (or previous one if it's not the first)
597
		 * to display the next (or previous) products.
598
		 *
599
		 * The value must be an integer number from 1 to 100. Negative values as
600
		 * well as values above 100 are not allowed. The value can be overwritten
601
		 * per request if the "l_size" parameter is part of the URL.
602
		 *
603
		 * @param integer Number of products
604
		 * @since 2014.03
605
		 * @see client/html/catalog/lists/attrid-default
606
		 * @see client/html/catalog/lists/catid-default
607
		 * @see client/html/catalog/lists/supid-default
608
		 * @see client/html/catalog/lists/domains
609
		 * @see client/html/catalog/lists/levels
610
		 * @see client/html/catalog/lists/sort
611
		 * @see client/html/catalog/lists/pages
612
		 * @see client/html/catalog/lists/instock
613
		 */
614
		$size = $this->context()->config()->get( 'client/html/catalog/lists/size', 48 );
615
616
		return min( max( $this->view()->param( 'l_size', $size ), 1 ), 100 );
617
	}
618
619
620
	/**
621
	 * Returns the product sorting
622
	 *
623
	 * @return string Product sorting
624
	 */
625
	protected function sort() : string
626
	{
627
		/** client/html/catalog/lists/sort
628
		 * Default sorting of product list if no other sorting is given by parameter
629
		 *
630
		 * Configures the standard sorting of products in list views. This sorting is used
631
		 * as long as it's not overwritten by an URL parameter. Except "relevance", all
632
		 * other sort codes can be prefixed by a "-" (minus) sign to sort the products in
633
		 * a descending order. By default, the sorting is ascending.
634
		 *
635
		 * @param string Sort code "relevance", "name", "-name", "price", "-price", "ctime" or "-ctime"
636
		 * @since 2018.07
637
		 * @see client/html/catalog/lists/attrid-default
638
		 * @see client/html/catalog/lists/catid-default
639
		 * @see client/html/catalog/lists/supid-default
640
		 * @see client/html/catalog/lists/domains
641
		 * @see client/html/catalog/lists/levels
642
		 * @see client/html/catalog/lists/size
643
		 * @see client/html/catalog/lists/instock
644
		 */
645
		return $this->view()->param( 'f_sort', $this->context()->config()->get( 'client/html/catalog/lists/sort', 'relevance' ) );
646
	}
647
648
649
	/**
650
	 * Returns the supplier IDs used for filtering products
651
	 *
652
	 * @return array List of supplier IDs
653
	 */
654
	protected function suppliers() : array
655
	{
656
		/** client/html/catalog/lists/supid-default
657
		 * The default supplier ID used if none is given as parameter
658
		 *
659
		 * Products in the list page can be limited to one or more suppliers.
660
		 * By default, the products are not limited to any supplier until one or
661
		 * more supplier IDs are passed in the URL using the f_supid parameter.
662
		 * You can also configure the default supplier IDs for limiting the
663
		 * products if no IDs are passed in the URL using this configuration.
664
		 *
665
		 * @param array|string Supplier ID or IDs
666
		 * @since 2021.01
667
		 * @see client/html/catalog/lists/sort
668
		 * @see client/html/catalog/lists/size
669
		 * @see client/html/catalog/lists/domains
670
		 * @see client/html/catalog/lists/levels
671
		 * @see client/html/catalog/lists/attrid-default
672
		 * @see client/html/catalog/lists/catid-default
673
		 * @see client/html/catalog/detail/prodid-default
674
		 * @see client/html/catalog/lists/instock
675
		 */
676
		$supids = $this->view()->param( 'f_supid', $this->context()->config()->get( 'client/html/catalog/lists/supid-default' ) );
677
		$supids = $supids != null && is_scalar( $supids ) ? explode( ',', $supids ) : $supids; // workaround for TYPO3
678
679
		return (array) $supids;
680
	}
681
682
683
	/**
684
	 * Returns the URLs for fetching stock information
685
	 *
686
	 * @param \Aimeos\Map $products Products to fetch stock information for
687
	 * @return \Aimeos\Map List of stock URLs
688
	 */
689
	protected function stockUrl( \Aimeos\Map $products ) : \Aimeos\Map
690
	{
691
		/** client/html/catalog/lists/stock
692
		 * Enables or disables displaying product stock levels in product list views
693
		 *
694
		 * This configuration option allows shop owners to display product
695
		 * stock levels for each product in list views or to disable
696
		 * fetching product stock information.
697
		 *
698
		 * The stock information is fetched via AJAX and inserted via Javascript.
699
		 * This allows to cache product items by leaving out such highly
700
		 * dynamic content like stock levels which changes with each order.
701
		 *
702
		 * @param boolean Value of "1" to display stock levels, "0" to disable displaying them
703
		 * @since 2014.03
704
		 * @see client/html/catalog/detail/stock/enable
705
		 * @see client/html/catalog/stock/url/target
706
		 * @see client/html/catalog/stock/url/controller
707
		 * @see client/html/catalog/stock/url/action
708
		 * @see client/html/catalog/stock/url/config
709
		 */
710
		if( !$products->isEmpty() && $this->context()->config()->get( 'client/html/catalog/lists/stock', true ) ) {
711
			return $this->getStockUrl( $this->view(), $products );
712
		}
713
714
		return map();
715
	}
716
}
717