Passed
Push — master ( 71484b...354380 )
by Aimeos
05:13
created

Standard::getSuppliers()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 24
rs 9.7998
1
<?php
2
/**
3
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
4
 * @copyright Aimeos (aimeos.org), 2018-2021
5
 * @package MShop
6
 * @subpackage Index
7
 */
8
9
10
namespace Aimeos\MShop\Index\Manager\Supplier;
11
12
13
/**
14
 * Submanager for supplier.
15
 *
16
 * @package MShop
17
 * @subpackage Index
18
 */
19
class Standard
20
	extends \Aimeos\MShop\Index\Manager\DBBase
21
	implements \Aimeos\MShop\Index\Manager\Supplier\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
22
{
23
	private $searchConfig = array(
24
		'index.supplier.id' => array(
25
			'code' => 'index.supplier.id',
26
			'internalcode' => 'mindsu."supid"',
27
			'internaldeps'=>array( 'LEFT JOIN "mshop_index_supplier" AS mindsu ON mindsu."prodid" = mpro."id"' ),
28
			'label' => 'Product index supplier ID',
29
			'type' => 'string',
30
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
31
			'public' => false,
32
		),
33
		'index.supplier:radius' => array(
34
			'code' => 'index.supplier:radius()',
35
			'internalcode' => ':site AND
36
				mindsu."latitude" > $1 - $3 / 111.19493 AND
37
				mindsu."latitude" < $1 + $3 / 111.19493 AND
38
				mindsu."longitude" > $2 - $3 / 111.19493 / COS( RADIANS( $2 ) ) AND
39
				mindsu."longitude" < $2 + $3 / 111.19493 / COS( RADIANS( $2 ) ) AND
40
				ACOS(
41
					SIN( RADIANS( $1 ) ) * SIN( RADIANS( mindsu."latitude" ) ) +
42
					COS( RADIANS( $1 ) ) * COS( RADIANS( mindsu."latitude" ) ) *
43
					COS( RADIANS( mindsu."longitude" ) - RADIANS( $2 ) )
44
				) * 6371
45
			',
46
			'label' => 'Within distance to given coordinates, parameter(<latitude>,<longitude>,<distance in km>)',
47
			'type' => 'boolean',
48
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_BOOL,
49
			'public' => false,
50
		),
51
		'index.supplier:position' => array(
52
			'code' => 'index.supplier:position()',
53
			'internalcode' => ':site AND mindsu."supid" IN ( $2 ) AND mindsu."listtype" = $1 AND mindsu."pos"',
54
			'label' => 'Product position in supplier list, parameter(<list type code>,<supplier IDs>)',
55
			'type' => 'integer',
56
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
57
			'public' => false,
58
		),
59
		'sort:index.supplier:position' => array(
60
			'code' => 'sort:index.supplier:position()',
61
			'internalcode' => 'mindsu."pos"',
62
			'label' => 'Sort product position in supplier list, parameter(<list type code>,<supplier IDs>)',
63
			'type' => 'integer',
64
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
65
			'public' => false,
66
		)
67
	);
68
69
	private $subManagers;
70
71
72
	/**
73
	 * Initializes the manager instance.
74
	 *
75
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
76
	 */
77
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
78
	{
79
		parent::__construct( $context );
80
81
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
82
		$level = $context->config()->get( 'mshop/index/manager/sitemode', $level );
83
84
		$expr = $this->getSiteString( 'mindsu."siteid"', $level );
85
86
		$name = 'index.supplier:position';
87
		$this->searchConfig[$name]['internalcode'] = str_replace( ':site', $expr, $this->searchConfig[$name]['internalcode'] );
88
89
		$name = 'index.supplier:radius';
90
		$this->searchConfig[$name]['internalcode'] = str_replace( ':site', $expr, $this->searchConfig[$name]['internalcode'] );
91
	}
92
93
94
	/**
95
	 * Counts the number products that are available for the values of the given key.
96
	 *
97
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria
98
	 * @param string $key Search key (usually the ID) to aggregate products for
99
	 * @param string|null $value Search key for aggregating the value column
100
	 * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average)
101
	 * @return \Aimeos\Map List of ID values as key and the number of counted products as value
102
	 */
103
	public function aggregate( \Aimeos\MW\Criteria\Iface $search, $key, string $value = null, string $type = null ) : \Aimeos\Map
104
	{
105
		return $this->aggregateBase( $search, $key, 'mshop/index/manager/aggregate', [], $value, $type );
106
	}
107
108
109
	/**
110
	 * Removes old entries from the storage.
111
	 *
112
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
113
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
114
	 */
115
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
116
	{
117
		parent::clear( $siteids );
118
119
		return $this->clearBase( $siteids, 'mshop/index/manager/supplier/delete' );
120
	}
121
122
123
	/**
124
	 * Removes all entries not touched after the given timestamp in the index.
125
	 * This can be a long lasting operation.
126
	 *
127
	 * @param string $timestamp Timestamp in ISO format (YYYY-MM-DD HH:mm:ss)
128
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
129
	 */
130
	public function cleanup( string $timestamp ) : \Aimeos\MShop\Index\Manager\Iface
131
	{
132
		/** mshop/index/manager/supplier/cleanup/mysql
133
		 * Deletes the index supplier records that haven't been touched
134
		 *
135
		 * @see mshop/index/manager/supplier/cleanup/ansi
136
		 */
137
138
		/** mshop/index/manager/supplier/cleanup/ansi
139
		 * Deletes the index supplier records that haven't been touched
140
		 *
141
		 * During the rebuild process of the product index, the entries of all
142
		 * active products will be removed and readded. Thus, no stale data for
143
		 * these products will remain in the database.
144
		 *
145
		 * All products that have been disabled since the last rebuild will be
146
		 * still part of the index. The cleanup statement removes all records
147
		 * that belong to products that haven't been touched during the index
148
		 * rebuild because these are the disabled ones.
149
		 *
150
		 * The SQL statement should conform to the ANSI standard to be
151
		 * compatible with most relational database systems. This also
152
		 * includes using double quotes for table and column names.
153
		 *
154
		 * @param string SQL statement for deleting the outdated index records
155
		 * @since 2018.07
156
		 * @category Developer
157
		 * @see mshop/index/manager/supplier/count/ansi
158
		 * @see mshop/index/manager/supplier/delete/ansi
159
		 * @see mshop/index/manager/supplier/insert/ansi
160
		 * @see mshop/index/manager/supplier/search/ansi
161
		 */
162
		return $this->cleanupBase( $timestamp, 'mshop/index/manager/supplier/cleanup' );
163
	}
164
165
166
	/**
167
	 * Removes multiple items.
168
	 *
169
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
170
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
171
	 */
172
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
173
	{
174
		/** mshop/index/manager/supplier/delete/mysql
175
		 * Deletes the items matched by the given IDs from the database
176
		 *
177
		 * @see mshop/index/manager/supplier/delete/ansi
178
		 */
179
180
		/** mshop/index/manager/supplier/delete/ansi
181
		 * Deletes the items matched by the given IDs from the database
182
		 *
183
		 * Removes the records specified by the given IDs from the index database.
184
		 * The records must be from the site that is configured via the
185
		 * context item.
186
		 *
187
		 * The ":cond" placeholder is replaced by the name of the ID column and
188
		 * the given ID or list of IDs while the site ID is bound to the question
189
		 * mark.
190
		 *
191
		 * The SQL statement should conform to the ANSI standard to be
192
		 * compatible with most relational database systems. This also
193
		 * includes using double quotes for table and column names.
194
		 *
195
		 * @param string SQL statement for deleting index supplier records
196
		 * @since 2018.07
197
		 * @category Developer
198
		 * @see mshop/index/manager/supplier/count/ansi
199
		 * @see mshop/index/manager/supplier/cleanup/ansi
200
		 * @see mshop/index/manager/supplier/insert/ansi
201
		 * @see mshop/index/manager/supplier/search/ansi
202
		 */
203
		return $this->deleteItemsBase( $itemIds, 'mshop/index/manager/supplier/delete' );
204
	}
205
206
207
	/**
208
	 * Returns the available manager types
209
	 *
210
	 * @param bool $withsub Return also the resource type of sub-managers if true
211
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
212
	 */
213
	public function getResourceType( bool $withsub = true ) : array
214
	{
215
		$path = 'mshop/index/manager/supplier/submanagers';
216
217
		return $this->getResourceTypeBase( 'index/supplier', $path, [], $withsub );
218
	}
219
220
221
	/**
222
	 * Returns a list of objects describing the available criterias for searching.
223
	 *
224
	 * @param bool $withsub Return also attributes of sub-managers if true
225
	 * @return array List of items implementing \Aimeos\MW\Criteria\Attribute\Iface
226
	 */
227
	public function getSearchAttributes( bool $withsub = true ) : array
228
	{
229
		$list = parent::getSearchAttributes( $withsub );
230
231
		/** mshop/index/manager/supplier/submanagers
232
		 * List of manager names that can be instantiated by the index attribute manager
233
		 *
234
		 * Managers provide a generic interface to the underlying storage.
235
		 * Each manager has or can have sub-managers caring about particular
236
		 * aspects. Each of these sub-managers can be instantiated by its
237
		 * parent manager using the getSubManager() method.
238
		 *
239
		 * The search keys from sub-managers can be normally used in the
240
		 * manager as well. It allows you to search for items of the manager
241
		 * using the search keys of the sub-managers to further limit the
242
		 * retrieved list of items.
243
		 *
244
		 * @param array List of sub-manager names
245
		 * @since 2018.07
246
		 * @category Developer
247
		 */
248
		$path = 'mshop/index/manager/supplier/submanagers';
249
250
		return $list + $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
251
	}
252
253
254
	/**
255
	 * Returns a new manager for product extensions.
256
	 *
257
	 * @param string $manager Name of the sub manager type in lower case
258
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
259
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g stock, tags, locations, etc.
260
	 */
261
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
262
	{
263
		/** mshop/index/manager/supplier/name
264
		 * Class name of the used index supplier manager implementation
265
		 *
266
		 * Each default index supplier manager can be replaced by an alternative imlementation.
267
		 * To use this implementation, you have to set the last part of the class
268
		 * name as configuration value so the manager factory knows which class it
269
		 * has to instantiate.
270
		 *
271
		 * For example, if the name of the default class is
272
		 *
273
		 *  \Aimeos\MShop\Index\Manager\Supplier\Standard
274
		 *
275
		 * and you want to replace it with your own version named
276
		 *
277
		 *  \Aimeos\MShop\Index\Manager\Supplier\Mysupplier
278
		 *
279
		 * then you have to set the this configuration option:
280
		 *
281
		 *  mshop/index/manager/supplier/name = Mysupplier
282
		 *
283
		 * The value is the last part of your own class name and it's case sensitive,
284
		 * so take care that the configuration value is exactly named like the last
285
		 * part of the class name.
286
		 *
287
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
288
		 * characters are possible! You should always start the last part of the class
289
		 * name with an upper case character and continue only with lower case characters
290
		 * or numbers. Avoid chamel case names like "MySupplier"!
291
		 *
292
		 * @param string Last part of the class name
293
		 * @since 2018.07
294
		 * @category Developer
295
		 */
296
297
		/** mshop/index/manager/supplier/decorators/excludes
298
		 * Excludes decorators added by the "common" option from the index supplier manager
299
		 *
300
		 * Decorators extend the functionality of a class by adding new aspects
301
		 * (e.g. log what is currently done), executing the methods of the underlying
302
		 * class only in certain conditions (e.g. only for logged in users) or
303
		 * modify what is returned to the caller.
304
		 *
305
		 * This option allows you to remove a decorator added via
306
		 * "mshop/common/manager/decorators/default" before they are wrapped
307
		 * around the index supplier manager.
308
		 *
309
		 *  mshop/index/manager/supplier/decorators/excludes = array( 'decorator1' )
310
		 *
311
		 * This would remove the decorator named "decorator1" from the list of
312
		 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
313
		 * "mshop/common/manager/decorators/default" for the index supplier manager.
314
		 *
315
		 * @param array List of decorator names
316
		 * @since 2018.07
317
		 * @category Developer
318
		 * @see mshop/common/manager/decorators/default
319
		 * @see mshop/index/manager/supplier/decorators/global
320
		 * @see mshop/index/manager/supplier/decorators/local
321
		 */
322
323
		/** mshop/index/manager/supplier/decorators/global
324
		 * Adds a list of globally available decorators only to the index supplier manager
325
		 *
326
		 * Decorators extend the functionality of a class by adding new aspects
327
		 * (e.g. log what is currently done), executing the methods of the underlying
328
		 * class only in certain conditions (e.g. only for logged in users) or
329
		 * modify what is returned to the caller.
330
		 *
331
		 * This option allows you to wrap global decorators
332
		 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the index supplier
333
		 * manager.
334
		 *
335
		 *  mshop/index/manager/supplier/decorators/global = array( 'decorator1' )
336
		 *
337
		 * This would add the decorator named "decorator1" defined by
338
		 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the index
339
		 * supplier manager.
340
		 *
341
		 * @param array List of decorator names
342
		 * @since 2018.07
343
		 * @category Developer
344
		 * @see mshop/common/manager/decorators/default
345
		 * @see mshop/index/manager/supplier/decorators/excludes
346
		 * @see mshop/index/manager/supplier/decorators/local
347
		 */
348
349
		/** mshop/index/manager/supplier/decorators/local
350
		 * Adds a list of local decorators only to the index supplier manager
351
		 *
352
		 * Decorators extend the functionality of a class by adding new aspects
353
		 * (e.g. log what is currently done), executing the methods of the underlying
354
		 * class only in certain conditions (e.g. only for logged in users) or
355
		 * modify what is returned to the caller.
356
		 *
357
		 * This option allows you to wrap local decorators
358
		 * ("\Aimeos\MShop\Index\Manager\Supplier\Decorator\*") around the index
359
		 * supplier manager.
360
		 *
361
		 *  mshop/index/manager/supplier/decorators/local = array( 'decorator2' )
362
		 *
363
		 * This would add the decorator named "decorator2" defined by
364
		 * "\Aimeos\MShop\Index\Manager\Supplier\Decorator\Decorator2" only to the
365
		 * index supplier manager.
366
		 *
367
		 * @param array List of decorator names
368
		 * @since 2018.07
369
		 * @category Developer
370
		 * @see mshop/common/manager/decorators/default
371
		 * @see mshop/index/manager/supplier/decorators/excludes
372
		 * @see mshop/index/manager/supplier/decorators/global
373
		 */
374
375
		return $this->getSubManagerBase( 'index', 'supplier/' . $manager, $name );
376
	}
377
378
379
	/**
380
	 * Optimizes the index if necessary.
381
	 * Execution of this operation can take a very long time and shouldn't be
382
	 * called through a web server enviroment.
383
	 *
384
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
385
	 */
386
	public function optimize() : \Aimeos\MShop\Index\Manager\Iface
387
	{
388
		/** mshop/index/manager/supplier/optimize/mysql
389
		 * Optimizes the stored supplier data for retrieving the records faster
390
		 *
391
		 * @see mshop/index/manager/supplier/optimize/ansi
392
		 */
393
394
		/** mshop/index/manager/supplier/optimize/ansi
395
		 * Optimizes the stored supplier data for retrieving the records faster
396
		 *
397
		 * The SQL statement should reorganize the data in the DBMS storage to
398
		 * optimize access to the records of the table or tables. Some DBMS
399
		 * offer specialized statements to optimize indexes and records. This
400
		 * statement doesn't return any records.
401
		 *
402
		 * The SQL statement should conform to the ANSI standard to be
403
		 * compatible with most relational database systems. This also
404
		 * includes using double quotes for table and column names.
405
		 *
406
		 * @param string SQL statement for optimizing the stored supplier data
407
		 * @since 2018.07
408
		 * @category Developer
409
		 * @see mshop/index/manager/supplier/count/ansi
410
		 * @see mshop/index/manager/supplier/search/ansi
411
		 * @see mshop/index/manager/supplier/aggregate/ansi
412
		 */
413
		return $this->optimizeBase( 'mshop/index/manager/supplier/optimize' );
414
	}
415
416
417
	/**
418
	 * Rebuilds the index supplier for searching products or specified list of products.
419
	 * This can be a long lasting operation.
420
	 *
421
	 * @param \Aimeos\MShop\Product\Item\Iface[] $items Associative list of product IDs as keys and items as values
422
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
423
	 */
424
	public function rebuild( iterable $items = [] ) : \Aimeos\MShop\Index\Manager\Iface
425
	{
426
		if( map( $items )->isEmpty() ) { return $this; }
427
428
		\Aimeos\MW\Common\Base::checkClassList( \Aimeos\MShop\Product\Item\Iface::class, $items );
429
430
		$date = date( 'Y-m-d H:i:s' );
431
		$context = $this->context();
432
		$siteid = $context->getLocale()->getSiteId();
433
434
		$dbm = $context->getDatabaseManager();
435
		$dbname = $this->getResourceName();
436
		$conn = $dbm->acquire( $dbname );
437
438
		try
439
		{
440
			/** mshop/index/manager/supplier/insert/mysql
441
			 * Inserts a new supplier record into the product index database
442
			 *
443
			 * @see mshop/index/manager/supplier/insert/ansi
444
			 */
445
446
			/** mshop/index/manager/supplier/insert/ansi
447
			 * Inserts a new supplier record into the product index database
448
			 *
449
			 * During the product index rebuild, categories related to a
450
			 * product will be stored in the index for this product. All
451
			 * records are deleted before the new ones are inserted.
452
			 *
453
			 * The SQL statement must be a string suitable for being used as
454
			 * prepared statement. It must include question marks for binding
455
			 * the values from the order item to the statement before they are
456
			 * sent to the database server. The number of question marks must
457
			 * be the same as the number of columns listed in the INSERT
458
			 * statement. The order of the columns must correspond to the
459
			 * order in the rebuild() method, so the correct values are
460
			 * bound to the columns.
461
			 *
462
			 * The SQL statement should conform to the ANSI standard to be
463
			 * compatible with most relational database systems. This also
464
			 * includes using double quotes for table and column names.
465
			 *
466
			 * @param string SQL statement for inserting records
467
			 * @since 2018.07
468
			 * @category Developer
469
			 * @see mshop/index/manager/supplier/cleanup/ansi
470
			 * @see mshop/index/manager/supplier/delete/ansi
471
			 * @see mshop/index/manager/supplier/search/ansi
472
			 * @see mshop/index/manager/supplier/count/ansi
473
			 */
474
			$stmt = $this->getCachedStatement( $conn, 'mshop/index/manager/supplier/insert' );
475
476
			foreach( $items as $id => $item )
477
			{
478
				foreach( $item->getListItems( 'supplier' ) as $listItem )
479
				{
480
					if( ( $supplier = $listItem->getRefItem() ) === null ) {
481
						continue;
482
					}
483
484
					$pairs = $supplier->getAddressItems()->map( function( $addr ) {
485
						return $addr->getLatitude() !== null && $addr->getLongitude() !== null
486
							? ['lat' => $addr->getLatitude(), 'lon' => $addr->getLongitude()]
487
							: null;
488
					} )->filter();
489
490
					if( $pairs->isEmpty() ) {
491
						$pairs = [['lat' => null, 'lon' => null]];
492
					}
493
494
					foreach( $pairs as $pair )
495
					{
496
						$stmt->bind( 1, $listItem->getParentId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
497
						$stmt->bind( 2, $listItem->getRefId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
498
						$stmt->bind( 3, $listItem->getType() );
499
						$stmt->bind( 4, $listItem->getPosition(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
500
						$stmt->bind( 5, $pair['lat'] ?? null, \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT );
501
						$stmt->bind( 6, $pair['lon'] ?? null, \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT );
502
						$stmt->bind( 7, $date ); //mtime
503
						$stmt->bind( 8, $siteid );
504
505
						try {
506
							$stmt->execute()->finish();
507
						} catch( \Aimeos\MW\DB\Exception $e ) { ; } // Ignore duplicates
508
					}
509
				}
510
			}
511
512
			$dbm->release( $conn, $dbname );
513
		}
514
		catch( \Exception $e )
515
		{
516
			$dbm->release( $conn, $dbname );
517
			throw $e;
518
		}
519
520
		foreach( $this->getSubManagers() as $submanager ) {
521
			$submanager->rebuild( $items );
522
		}
523
524
		return $this;
525
	}
526
527
528
	/**
529
	 * Removes the products from the product index.
530
	 *
531
	 * @param array|string $ids Product ID or list of IDs
532
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
533
	 */
534
	public function remove( $ids ) : \Aimeos\MShop\Index\Manager\Iface
535
	{
536
		parent::remove( $ids )->delete( $ids );
537
		return $this;
538
	}
539
540
541
	/**
542
	 * Searches for items matching the given criteria.
543
	 *
544
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
545
	 * @param string[] $ref List of domains to fetch list items and referenced items for
546
	 * @param int|null &$total Number of items that are available in total
547
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Product\Item\Iface with ids as keys
548
	 */
549
	public function search( \Aimeos\MW\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
550
	{
551
		/** mshop/index/manager/supplier/search/mysql
552
		 * Retrieves the records matched by the given criteria in the database
553
		 *
554
		 * @see mshop/index/manager/supplier/search/ansi
555
		 */
556
557
		/** mshop/index/manager/supplier/search/ansi
558
		 * Retrieves the records matched by the given criteria in the database
559
		 *
560
		 * Fetches the records matched by the given criteria from the product index
561
		 * database. The records must be from one of the sites that are
562
		 * configured via the context item. If the current site is part of
563
		 * a tree of sites, the SELECT statement can retrieve all records
564
		 * from the current site and the complete sub-tree of sites.
565
		 *
566
		 * As the records can normally be limited by criteria from sub-managers,
567
		 * their tables must be joined in the SQL context. This is done by
568
		 * using the "internaldeps" property from the definition of the ID
569
		 * column of the sub-managers. These internal dependencies specify
570
		 * the JOIN between the tables and the used columns for joining. The
571
		 * ":joins" placeholder is then replaced by the JOIN strings from
572
		 * the sub-managers.
573
		 *
574
		 * To limit the records matched, conditions can be added to the given
575
		 * criteria object. It can contain comparisons like column names that
576
		 * must match specific values which can be combined by AND, OR or NOT
577
		 * operators. The resulting string of SQL conditions replaces the
578
		 * ":cond" placeholder before the statement is sent to the database
579
		 * server.
580
		 *
581
		 * If the records that are retrieved should be ordered by one or more
582
		 * columns, the generated string of column / sort direction pairs
583
		 * replaces the ":order" placeholder. In case no ordering is required,
584
		 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
585
		 * markers is removed to speed up retrieving the records. Columns of
586
		 * sub-managers can also be used for ordering the result set but then
587
		 * no index can be used.
588
		 *
589
		 * The number of returned records can be limited and can start at any
590
		 * number between the begining and the end of the result set. For that
591
		 * the ":size" and ":start" placeholders are replaced by the
592
		 * corresponding values from the criteria object. The default values
593
		 * are 0 for the start and 100 for the size value.
594
		 *
595
		 * The SQL statement should conform to the ANSI standard to be
596
		 * compatible with most relational database systems. This also
597
		 * includes using double quotes for table and column names.
598
		 *
599
		 * @param string SQL statement for searching items
600
		 * @since 2018.07
601
		 * @category Developer
602
		 * @see mshop/index/manager/supplier/count/ansi
603
		 * @see mshop/index/manager/supplier/optimize/ansi
604
		 * @see mshop/index/manager/supplier/aggregate/ansi
605
		 */
606
		$cfgPathSearch = 'mshop/index/manager/supplier/search';
607
608
		/** mshop/index/manager/supplier/count/mysql
609
		 * Counts the number of records matched by the given criteria in the database
610
		 *
611
		 * @see mshop/index/manager/supplier/count/ansi
612
		 */
613
614
		/** mshop/index/manager/supplier/count/ansi
615
		 * Counts the number of records matched by the given criteria in the database
616
		 *
617
		 * Counts all records matched by the given criteria from the product index
618
		 * database. The records must be from one of the sites that are
619
		 * configured via the context item. If the current site is part of
620
		 * a tree of sites, the statement can count all records from the
621
		 * current site and the complete sub-tree of sites.
622
		 *
623
		 * As the records can normally be limited by criteria from sub-managers,
624
		 * their tables must be joined in the SQL context. This is done by
625
		 * using the "internaldeps" property from the definition of the ID
626
		 * column of the sub-managers. These internal dependencies specify
627
		 * the JOIN between the tables and the used columns for joining. The
628
		 * ":joins" placeholder is then replaced by the JOIN strings from
629
		 * the sub-managers.
630
		 *
631
		 * To limit the records matched, conditions can be added to the given
632
		 * criteria object. It can contain comparisons like column names that
633
		 * must match specific values which can be combined by AND, OR or NOT
634
		 * operators. The resulting string of SQL conditions replaces the
635
		 * ":cond" placeholder before the statement is sent to the database
636
		 * server.
637
		 *
638
		 * Both, the strings for ":joins" and for ":cond" are the same as for
639
		 * the "search" SQL statement.
640
		 *
641
		 * Contrary to the "search" statement, it doesn't return any records
642
		 * but instead the number of records that have been found. As counting
643
		 * thousands of records can be a long running task, the maximum number
644
		 * of counted records is limited for performance reasons.
645
		 *
646
		 * The SQL statement should conform to the ANSI standard to be
647
		 * compatible with most relational database systems. This also
648
		 * includes using double quotes for table and column names.
649
		 *
650
		 * @param string SQL statement for counting items
651
		 * @since 2018.07
652
		 * @category Developer
653
		 * @see mshop/index/manager/supplier/search/ansi
654
		 * @see mshop/index/manager/supplier/optimize/ansi
655
		 * @see mshop/index/manager/supplier/aggregate/ansi
656
		 */
657
		$cfgPathCount = 'mshop/index/manager/supplier/count';
658
659
		return $this->searchItemsIndexBase( $search, $ref, $total, $cfgPathSearch, $cfgPathCount );
660
	}
661
662
663
	/**
664
	 * Returns the list of sub-managers available for the index supplier manager.
665
	 *
666
	 * @return \Aimeos\MShop\Index\Manager\Iface[] Associative list of the sub-domain as key and the manager object as value
667
	 */
668
	protected function getSubManagers() : array
669
	{
670
		if( $this->subManagers === null )
671
		{
672
			$this->subManagers = [];
673
			$config = $this->context()->config();
674
675
			/** mshop/index/manager/supplier/submanagers
676
			 * A list of sub-manager names used for indexing associated items to categories
677
			 *
678
			 * All items referenced by a product (e.g. texts, prices, media,
679
			 * etc.) are added to the product index via specialized index
680
			 * managers. You can add the name of new sub-managers to add more
681
			 * data to the index or remove existing ones if you don't want to
682
			 * index that data at all.
683
			 *
684
			 * This option configures the sub-managers that cares about
685
			 * indexing data associated to product categories.
686
			 *
687
			 * @param string List of index sub-manager names
688
			 * @since 2018.07
689
			 * @category User
690
			 * @category Developer
691
			 * @see mshop/index/manager/submanagers
692
			 */
693
			foreach( $config->get( 'mshop/index/manager/supplier/submanagers', [] ) as $domain )
694
			{
695
				$name = $config->get( 'mshop/index/manager/supplier/' . $domain . '/name' );
696
				$this->subManagers[$domain] = $this->object()->getSubManager( $domain, $name );
697
			}
698
699
			return $this->subManagers;
700
		}
701
702
		return $this->subManagers;
703
	}
704
}
705