Passed
Push — master ( 152100...161248 )
by Aimeos
17:03
created

Standard::body()   A

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
		$catIds = $this->categories();
257
258
		if( $catItem = $this->category( $catIds ) )
259
		{
260
			$listCatPath = \Aimeos\Controller\Frontend::create( $context, 'catalog' )
261
				->uses( ['media', 'media/property', 'text'] )
262
				->getPath( $catItem->getId() );
263
264
			$view->listCatPath = $this->addMetaItems( $listCatPath, $expire, $tags );
265
			$catIds[] = $catItem->getId();
266
		}
267
268
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )
269
			->sort( $sort ) // prioritize user sorting over the sorting through relevance and category
270
			->text( $view->param( 'f_search' ) )
271
			->price( $view->param( 'f_price' ) )
272
			->category( $catIds, 'default', $this->level() )
273
			->radius( $view->param( 'f_point', [] ), $view->param( 'f_dist' ) )
274
			->supplier( $this->suppliers() )
275
			->allOf( $this->attributes() )
276
			->allOf( $view->param( 'f_attrid', [] ) )
277
			->oneOf( $view->param( 'f_optid', [] ) )
278
			->oneOf( $view->param( 'f_oneid', [] ) )
279
			->slice( ( $page - 1 ) * $size, $size )
280
			->uses( $this->domains() );
281
282
		$this->call( 'conditions', $cntl, $view );
283
284
		$products = $cntl->search( $total );
285
		$articles = $products->getRefItems( 'product', 'default', 'default' )->flat( 1 )->union( $products );
286
287
		$attrMap = $articles->getRefItems( 'attribute' )->flat( 1 )->groupBy( 'attribute.type' );
288
		$attrTypes = $this->attributeTypes( $attrMap->keys() );
289
290
		$this->addMetaItems( $products, $expire, $tags, ['product'] );
291
292
293
		$view->listProductItems = $products;
294
		$view->listProductSort = $sort;
295
		$view->listProductTotal = $total;
296
297
		$view->listPageSize = $size;
298
		$view->listPageCurr = $page;
299
		$view->listPagePrev = ( $page > 1 ? $page - 1 : 1 );
300
		$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...
301
		$view->listPageNext = ( $page < $view->listPageLast ? $page + 1 : $view->listPageLast );
302
303
		$view->listAttributeTypes = $attrTypes->col( null, 'attribute.type.code' );
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.items.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/catid-default
351
		 * @see client/html/catalog/lists/supid-default
352
		 * @see client/html/catalog/detail/prodid-default
353
		 * @see client/html/catalog/instock
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 attribute type items for the given codes
364
	 *
365
	 * @param \Aimeos\Map $codes List of attribute type codes
366
	 * @return \Aimeos\Map List of attribute type items
367
	 */
368
	protected function attributeTypes( \Aimeos\Map $codes ) : \Aimeos\Map
369
	{
370
		$manager = \Aimeos\MShop::create( $this->context(), 'attribute/type' );
371
372
		$filter = $manager->filter( true )
373
			->add( 'attribute.type.domain', '==', 'product' )
374
			->add( 'attribute.type.code', '==', $codes )
375
			->order( 'attribute.type.position' );
376
377
		return $manager->search( $filter->slice( 0, count( $codes ) ) );
378
	}
379
380
381
	/**
382
	 * Returns the category item
383
	 *
384
	 * @param array List of category IDs
0 ignored issues
show
Bug introduced by
The type Aimeos\Client\Html\Catalog\Lists\List was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
385
	 * @return \Aimeos\MShop\Catalog\Item\Iface|null Catalog item
386
	 */
387
	protected function category( array $catIds ) : ?\Aimeos\MShop\Catalog\Item\Iface
388
	{
389
		$cntl = \Aimeos\Controller\Frontend::create( $this->context(), 'catalog' )
390
			->uses( ['media', 'media/property', 'text'] );
391
392
		if( $id = current( $catIds ) ) {
393
			return $cntl->get( $id );
394
		}
395
396
		if( $name = $this->view()->param( 'f_name' ) ) {
397
			return $cntl->resolve( $name );
398
		}
399
400
		return null;
401
	}
402
403
404
	/**
405
	 * Returns the category IDs used for filtering products
406
	 *
407
	 * @return array List of category IDs
408
	 */
409
	protected function categories() : array
410
	{
411
		/** client/html/catalog/lists/catid-default
412
		 * The default category ID used if none is given as parameter
413
		 *
414
		 * If users view a product list page without a category ID in the
415
		 * parameter list, the first found products are displayed with a
416
		 * random order. You can circumvent this by configuring a default
417
		 * category ID that should be used in this case (the ID of the root
418
		 * category is best for this). In most cases you can set this value
419
		 * via the administration interface of the shop application.
420
		 *
421
		 * @param array|string Category ID or IDs
422
		 * @since 2014.03
423
		 * @see client/html/catalog/lists/sort
424
		 * @see client/html/catalog/lists/size
425
		 * @see client/html/catalog/lists/domains
426
		 * @see client/html/catalog/lists/levels
427
		 * @see client/html/catalog/lists/attrid-default
428
		 * @see client/html/catalog/detail/prodid-default
429
		 * @see client/html/catalog/lists/supid-default
430
		 * @see client/html/catalog/instock
431
		 */
432
		$catids = $this->view()->param( 'f_catid', $this->context()->config()->get( 'client/html/catalog/lists/catid-default' ) );
433
		$catids = $catids != null && is_scalar( $catids ) ? explode( ',', (string) $catids ) : $catids; // workaround for TYPO3
434
435
		return array_filter( (array) $catids );
436
	}
437
438
439
	/**
440
	 * Adds additional conditions for filtering
441
	 *
442
	 * @param \Aimeos\Controller\Frontend\Product\Iface $cntl Product controller
443
	 * @param \Aimeos\Base\View\Iface $view View object
444
	 */
445
	protected function conditions( \Aimeos\Controller\Frontend\Product\Iface $cntl, \Aimeos\Base\View\Iface $view )
446
	{
447
		/** client/html/catalog/instock
448
		 * Show only products which are in stock
449
		 *
450
		 * This configuration option overwrites the "client/html/catalog/domains"
451
		 * option that allows to configure the domain names of the items fetched
452
		 * for all catalog related data.
453
		 *
454
		 * @param int Zero to show all products, "1" to show only products with stock
455
		 * @since 2021.10
456
		 * @see client/html/catalog/domains
457
		 * @see client/html/catalog/lists/domains
458
		 * @see client/html/catalog/detail/domains
459
		 * @see client/html/catalog/stage/domains
460
		 * @see client/html/catalog/lists/attrid-default
461
		 * @see client/html/catalog/lists/catid-default
462
		 * @see client/html/catalog/lists/supid-default
463
		 * @see client/html/catalog/lists/size
464
		 * @see client/html/catalog/lists/levels
465
		 * @see client/html/catalog/lists/sort
466
		 * @see client/html/catalog/lists/pages
467
		 */
468
469
		if( $view->config( 'client/html/catalog/instock', false ) ) {
470
			$cntl->compare( '>', 'product.instock', 0 );
471
		}
472
	}
473
474
475
	/**
476
	 * Returns the data domains fetched along with the products
477
	 *
478
	 * @return array List of domain names
479
	 */
480
	protected function domains() : array
481
	{
482
		$config = $this->context()->config();
483
		$domains = ['catalog', 'media', 'media/property', 'price', 'supplier', 'text'];
484
485
		/** client/html/catalog/domains
486
		 * A list of domain names whose items should be available in the catalog view templates
487
		 *
488
		 * The templates rendering catalog related data usually add the images and
489
		 * texts associated to each item. If you want to display additional
490
		 * content like the 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 can be overwritten by the "client/html/catalog/lists/domains"
497
		 * configuration option that allows to configure the domain names of the
498
		 * items fetched specifically for all types of product listings.
499
		 *
500
		 * @param array List of domain names
501
		 * @since 2014.03
502
		 * @see client/html/catalog/lists/domains
503
		 * @see client/html/catalog/lists/size
504
		 * @see client/html/catalog/lists/levels
505
		 * @see client/html/catalog/lists/sort
506
		 * @see client/html/catalog/lists/pages
507
		 */
508
		$domains = $config->get( 'client/html/catalog/domains', $domains );
509
510
		/** client/html/catalog/lists/domains
511
		 * A list of domain names whose items should be available in the product list view template
512
		 *
513
		 * The templates rendering product lists usually add the images, prices
514
		 * and texts associated to each product item. If you want to display additional
515
		 * content like the product attributes, you can configure your own list of
516
		 * domains (attribute, media, price, product, text, etc. are domains)
517
		 * whose items are fetched from the storage. Please keep in mind that
518
		 * the more domains you add to the configuration, the more time is required
519
		 * for fetching the content!
520
		 *
521
		 * This configuration option overwrites the "client/html/catalog/domains"
522
		 * option that allows to configure the domain names of the items fetched
523
		 * for all catalog related data.
524
		 *
525
		 * @param array List of domain names
526
		 * @since 2014.03
527
		 * @see client/html/catalog/domains
528
		 * @see client/html/catalog/detail/domains
529
		 * @see client/html/catalog/stage/domains
530
		 * @see client/html/catalog/lists/attrid-default
531
		 * @see client/html/catalog/lists/catid-default
532
		 * @see client/html/catalog/lists/supid-default
533
		 * @see client/html/catalog/lists/size
534
		 * @see client/html/catalog/lists/levels
535
		 * @see client/html/catalog/lists/sort
536
		 * @see client/html/catalog/lists/pages
537
		 * @see client/html/catalog/instock
538
		 */
539
		$domains = $config->get( 'client/html/catalog/lists/domains', $domains );
540
541
		if( $config->get( 'client/html/catalog/lists/basket-add', false ) ) {
542
			$domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] );
543
		}
544
545
		return $domains;
546
	}
547
548
549
	/**
550
	 * Returns the category depth level
551
	 *
552
	 * @return int Category depth level
553
	 */
554
	protected function level() : int
555
	{
556
		/** client/html/catalog/lists/levels
557
		 * Include products of sub-categories in the product list of the current category
558
		 *
559
		 * Sometimes it may be useful to show products of sub-categories in the
560
		 * current category product list, e.g. if the current category contains
561
		 * no products at all or if there are only a few products in all categories.
562
		 *
563
		 * Possible constant values for this setting are:
564
		 *
565
		 * * 1 : Only products from the current category
566
		 * * 2 : Products from the current category and the direct child categories
567
		 * * 3 : Products from the current category and the whole category sub-tree
568
		 *
569
		 * Caution: Please keep in mind that displaying products of sub-categories
570
		 * can slow down your shop, especially if it contains more than a few
571
		 * products! You have no real control over the positions of the products
572
		 * in the result list too because all products from different categories
573
		 * with the same position value are placed randomly.
574
		 *
575
		 * Usually, a better way is to associate products to all categories they
576
		 * should be listed in. This can be done manually if there are only a few
577
		 * ones or during the product import automatically.
578
		 *
579
		 * @param integer Tree level constant
580
		 * @since 2015.11
581
		 * @see client/html/catalog/lists/attrid-default
582
		 * @see client/html/catalog/lists/catid-default
583
		 * @see client/html/catalog/lists/supid-default
584
		 * @see client/html/catalog/lists/domains
585
		 * @see client/html/catalog/lists/size
586
		 * @see client/html/catalog/lists/sort
587
		 * @see client/html/catalog/lists/pages
588
		 * @see client/html/catalog/instock
589
		 */
590
		return $this->context()->config()->get( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
591
	}
592
593
594
	/**
595
	 * Returns the number of allowed pages
596
	 *
597
	 * @return int Number of allowed pages
598
	 */
599
	protected function pages() : int
600
	{
601
		/** client/html/catalog/lists/pages
602
		 * Maximum number of product pages shown in pagination
603
		 *
604
		 * Limits the number of product pages that are shown in the navigation.
605
		 * The user is able to move to the next page (or previous one if it's not
606
		 * the first) to display the next (or previous) products.
607
		 *
608
		 * The value must be a positive integer number. Negative values are not
609
		 * allowed. The value can't be overwritten per request.
610
		 *
611
		 * @param integer Number of pages
612
		 * @since 2019.04
613
		 * @see client/html/catalog/lists/attrid-default
614
		 * @see client/html/catalog/lists/catid-default
615
		 * @see client/html/catalog/lists/supid-default
616
		 * @see client/html/catalog/lists/domains
617
		 * @see client/html/catalog/lists/levels
618
		 * @see client/html/catalog/lists/sort
619
		 * @see client/html/catalog/lists/size
620
		 * @see client/html/catalog/instock
621
		 */
622
		return $this->context()->config()->get( 'client/html/catalog/lists/pages', 100 );
623
	}
624
625
626
	/**
627
	 * Returns the maximum products per page
628
	 *
629
	 * @return int Maximum products per page
630
	 */
631
	protected function size() : int
632
	{
633
		/** client/html/catalog/lists/size
634
		 * The number of products shown in a list page
635
		 *
636
		 * Limits the number of products that are shown in the list pages to the
637
		 * given value. If more products are available, the products are split
638
		 * into bunches which will be shown on their own list page. The user is
639
		 * able to move to the next page (or previous one if it's not the first)
640
		 * to display the next (or previous) products.
641
		 *
642
		 * The value must be an integer number from 1 to 100. Negative values as
643
		 * well as values above 100 are not allowed. The value can be overwritten
644
		 * per request if the "l_size" parameter is part of the URL.
645
		 *
646
		 * @param integer Number of products
647
		 * @since 2014.03
648
		 * @see client/html/catalog/lists/attrid-default
649
		 * @see client/html/catalog/lists/catid-default
650
		 * @see client/html/catalog/lists/supid-default
651
		 * @see client/html/catalog/lists/domains
652
		 * @see client/html/catalog/lists/levels
653
		 * @see client/html/catalog/lists/sort
654
		 * @see client/html/catalog/lists/pages
655
		 * @see client/html/catalog/instock
656
		 */
657
		$size = $this->context()->config()->get( 'client/html/catalog/lists/size', 48 );
658
659
		return min( max( $this->view()->param( 'l_size', $size ), 1 ), 100 );
660
	}
661
662
663
	/**
664
	 * Returns the product sorting
665
	 *
666
	 * @return string Product sorting
667
	 */
668
	protected function sort() : string
669
	{
670
		/** client/html/catalog/lists/sort
671
		 * Default sorting of product list if no other sorting is given by parameter
672
		 *
673
		 * Configures the standard sorting of products in list views. This sorting is used
674
		 * as long as it's not overwritten by an URL parameter. Except "relevance", all
675
		 * other sort codes can be prefixed by a "-" (minus) sign to sort the products in
676
		 * a descending order. By default, the sorting is ascending.
677
		 *
678
		 * @param string Sort code "relevance", "name", "-name", "price", "-price", "ctime" or "-ctime"
679
		 * @since 2018.07
680
		 * @see client/html/catalog/lists/attrid-default
681
		 * @see client/html/catalog/lists/catid-default
682
		 * @see client/html/catalog/lists/supid-default
683
		 * @see client/html/catalog/lists/domains
684
		 * @see client/html/catalog/lists/levels
685
		 * @see client/html/catalog/lists/size
686
		 * @see client/html/catalog/instock
687
		 */
688
		return $this->view()->param( 'f_sort', $this->context()->config()->get( 'client/html/catalog/lists/sort', 'relevance' ) );
689
	}
690
691
692
	/**
693
	 * Returns the supplier IDs used for filtering products
694
	 *
695
	 * @return array List of supplier IDs
696
	 */
697
	protected function suppliers() : array
698
	{
699
		/** client/html/catalog/lists/supid-default
700
		 * The default supplier ID used if none is given as parameter
701
		 *
702
		 * Products in the list page can be limited to one or more suppliers.
703
		 * By default, the products are not limited to any supplier until one or
704
		 * more supplier IDs are passed in the URL using the f_supid parameter.
705
		 * You can also configure the default supplier IDs for limiting the
706
		 * products if no IDs are passed in the URL using this configuration.
707
		 *
708
		 * @param array|string Supplier ID or IDs
709
		 * @since 2021.01
710
		 * @see client/html/catalog/lists/sort
711
		 * @see client/html/catalog/lists/size
712
		 * @see client/html/catalog/lists/domains
713
		 * @see client/html/catalog/lists/levels
714
		 * @see client/html/catalog/lists/attrid-default
715
		 * @see client/html/catalog/lists/catid-default
716
		 * @see client/html/catalog/detail/prodid-default
717
		 * @see client/html/catalog/instock
718
		 */
719
		$supids = $this->view()->param( 'f_supid', $this->context()->config()->get( 'client/html/catalog/lists/supid-default' ) );
720
		$supids = $supids != null && is_scalar( $supids ) ? explode( ',', $supids ) : $supids; // workaround for TYPO3
721
722
		return (array) $supids;
723
	}
724
725
726
	/**
727
	 * Returns the URLs for fetching stock information
728
	 *
729
	 * @param \Aimeos\Map $products Products to fetch stock information for
730
	 * @return \Aimeos\Map List of stock URLs
731
	 */
732
	protected function stockUrl( \Aimeos\Map $products ) : \Aimeos\Map
733
	{
734
		/** client/html/catalog/lists/stock
735
		 * Enables or disables displaying product stock levels in product list views
736
		 *
737
		 * This configuration option allows shop owners to display product
738
		 * stock levels for each product in list views or to disable
739
		 * fetching product stock information.
740
		 *
741
		 * The stock information is fetched via AJAX and inserted via Javascript.
742
		 * This allows to cache product items by leaving out such highly
743
		 * dynamic content like stock levels which changes with each order.
744
		 *
745
		 * @param boolean Value of "1" to display stock levels, "0" to disable displaying them
746
		 * @since 2014.03
747
		 * @see client/html/catalog/detail/stock/enable
748
		 * @see client/html/catalog/stock/url/target
749
		 * @see client/html/catalog/stock/url/controller
750
		 * @see client/html/catalog/stock/url/action
751
		 * @see client/html/catalog/stock/url/config
752
		 */
753
		if( !$products->isEmpty() && $this->context()->config()->get( 'client/html/catalog/lists/stock', true ) ) {
754
			return $this->getStockUrl( $this->view(), $products );
755
		}
756
757
		return map();
758
	}
759
760
761
	/** client/html/catalog/lists/decorators/excludes
762
	 * Excludes decorators added by the "common" option from the catalog lists html client
763
	 *
764
	 * Decorators extend the functionality of a class by adding new aspects
765
	 * (e.g. log what is currently done), executing the methods of the underlying
766
	 * class only in certain conditions (e.g. only for logged in users) or
767
	 * modify what is returned to the caller.
768
	 *
769
	 * This option allows you to remove a decorator added via
770
	 * "client/html/common/decorators/default" before they are wrapped
771
	 * around the html client.
772
	 *
773
	 *  client/html/catalog/lists/decorators/excludes = array( 'decorator1' )
774
	 *
775
	 * This would remove the decorator named "decorator1" from the list of
776
	 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
777
	 * "client/html/common/decorators/default" to the html client.
778
	 *
779
	 * @param array List of decorator names
780
	 * @see client/html/common/decorators/default
781
	 * @see client/html/catalog/lists/decorators/global
782
	 * @see client/html/catalog/lists/decorators/local
783
	 */
784
785
	/** client/html/catalog/lists/decorators/global
786
	 * Adds a list of globally available decorators only to the catalog lists html client
787
	 *
788
	 * Decorators extend the functionality of a class by adding new aspects
789
	 * (e.g. log what is currently done), executing the methods of the underlying
790
	 * class only in certain conditions (e.g. only for logged in users) or
791
	 * modify what is returned to the caller.
792
	 *
793
	 * This option allows you to wrap global decorators
794
	 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
795
	 *
796
	 *  client/html/catalog/lists/decorators/global = array( 'decorator1' )
797
	 *
798
	 * This would add the decorator named "decorator1" defined by
799
	 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
800
	 *
801
	 * @param array List of decorator names
802
	 * @see client/html/common/decorators/default
803
	 * @see client/html/catalog/lists/decorators/excludes
804
	 * @see client/html/catalog/lists/decorators/local
805
	 */
806
807
	/** client/html/catalog/lists/decorators/local
808
	 * Adds a list of local decorators only to the catalog lists html client
809
	 *
810
	 * Decorators extend the functionality of a class by adding new aspects
811
	 * (e.g. log what is currently done), executing the methods of the underlying
812
	 * class only in certain conditions (e.g. only for logged in users) or
813
	 * modify what is returned to the caller.
814
	 *
815
	 * This option allows you to wrap local decorators
816
	 * ("\Aimeos\Client\Html\Catalog\Decorator\*") around the html client.
817
	 *
818
	 *  client/html/catalog/lists/decorators/local = array( 'decorator2' )
819
	 *
820
	 * This would add the decorator named "decorator2" defined by
821
	 * "\Aimeos\Client\Html\Catalog\Decorator\Decorator2" only to the html client.
822
	 *
823
	 * @param array List of decorator names
824
	 * @see client/html/common/decorators/default
825
	 * @see client/html/catalog/lists/decorators/excludes
826
	 * @see client/html/catalog/lists/decorators/global
827
	 */
828
}
829