Passed
Pull Request — master (#297)
by Aimeos
10:30
created

Standard::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 14
rs 10
1
<?php
2
/**
3
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
4
 * @copyright Aimeos (aimeos.org), 2018-2022
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\Base\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\Base\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\Base\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\Base\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\ContextIface $context Context object
76
	 */
77
	public function __construct( \Aimeos\MShop\ContextIface $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->siteString( '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\Base\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\Base\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\Base\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
	 * Iterates over all matching items and returns the found ones
381
	 *
382
	 * @param \Aimeos\MShop\Common\Iterator\Iface $iterator Iterator object with conditions, sortations, etc.
383
	 * @param string[] $ref List of domains to fetch list items and referenced items for
384
	 * @param int $count Maximum number of items which should be returned
385
	 * @return \Aimeos\Map|null List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
386
	 */
387
	public function iterate( \Aimeos\MShop\Common\Iterator\Iface $iterator, array $ref = [], int $count = 100 ) : ?\Aimeos\Map
388
	{
389
		return $this->iterateIndexBase( $iterator, $ref, $count );
390
	}
391
392
393
	/**
394
	 * Creates a new iterator based on the filter criteria
395
	 *
396
	 * @param \Aimeos\Base\Criteria\Iface $filter Criteria object with conditions, sortations, etc.
397
	 * @return \Aimeos\MShop\Common\Iterator\Iface Iterator object
398
	 */
399
	public function iterator( \Aimeos\Base\Criteria\Iface $filter ) : \Aimeos\MShop\Common\Iterator\Iface
400
	{
401
		return $this->iteratorIndexBase( $filter, 'mshop/index/manager/iterate' );
402
	}
403
404
405
	/**
406
	 * Optimizes the index if necessary.
407
	 * Execution of this operation can take a very long time and shouldn't be
408
	 * called through a web server enviroment.
409
	 *
410
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
411
	 */
412
	public function optimize() : \Aimeos\MShop\Index\Manager\Iface
413
	{
414
		/** mshop/index/manager/supplier/optimize/mysql
415
		 * Optimizes the stored supplier data for retrieving the records faster
416
		 *
417
		 * @see mshop/index/manager/supplier/optimize/ansi
418
		 */
419
420
		/** mshop/index/manager/supplier/optimize/ansi
421
		 * Optimizes the stored supplier data for retrieving the records faster
422
		 *
423
		 * The SQL statement should reorganize the data in the DBMS storage to
424
		 * optimize access to the records of the table or tables. Some DBMS
425
		 * offer specialized statements to optimize indexes and records. This
426
		 * statement doesn't return any records.
427
		 *
428
		 * The SQL statement should conform to the ANSI standard to be
429
		 * compatible with most relational database systems. This also
430
		 * includes using double quotes for table and column names.
431
		 *
432
		 * @param string SQL statement for optimizing the stored supplier data
433
		 * @since 2018.07
434
		 * @category Developer
435
		 * @see mshop/index/manager/supplier/count/ansi
436
		 * @see mshop/index/manager/supplier/search/ansi
437
		 * @see mshop/index/manager/supplier/aggregate/ansi
438
		 */
439
		return $this->optimizeBase( 'mshop/index/manager/supplier/optimize' );
440
	}
441
442
443
	/**
444
	 * Rebuilds the index supplier for searching products or specified list of products.
445
	 * This can be a long lasting operation.
446
	 *
447
	 * @param \Aimeos\MShop\Product\Item\Iface[] $items Associative list of product IDs as keys and items as values
448
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
449
	 */
450
	public function rebuild( iterable $items = [] ) : \Aimeos\MShop\Index\Manager\Iface
451
	{
452
		if( ( $items = map( $items ) )->isEmpty() ) { return $this; }
453
454
		$items->implements( \Aimeos\MShop\Product\Item\Iface::class, true );
455
456
		$date = date( 'Y-m-d H:i:s' );
457
		$context = $this->context();
458
		$siteid = $context->locale()->getSiteId();
459
		$conn = $context->db( $this->getResourceName() );
460
461
			/** mshop/index/manager/supplier/insert/mysql
462
			 * Inserts a new supplier record into the product index database
463
			 *
464
			 * @see mshop/index/manager/supplier/insert/ansi
465
			 */
466
467
			/** mshop/index/manager/supplier/insert/ansi
468
			 * Inserts a new supplier record into the product index database
469
			 *
470
			 * During the product index rebuild, categories related to a
471
			 * product will be stored in the index for this product. All
472
			 * records are deleted before the new ones are inserted.
473
			 *
474
			 * The SQL statement must be a string suitable for being used as
475
			 * prepared statement. It must include question marks for binding
476
			 * the values from the order item to the statement before they are
477
			 * sent to the database server. The number of question marks must
478
			 * be the same as the number of columns listed in the INSERT
479
			 * statement. The order of the columns must correspond to the
480
			 * order in the rebuild() method, so the correct values are
481
			 * bound to the columns.
482
			 *
483
			 * The SQL statement should conform to the ANSI standard to be
484
			 * compatible with most relational database systems. This also
485
			 * includes using double quotes for table and column names.
486
			 *
487
			 * @param string SQL statement for inserting records
488
			 * @since 2018.07
489
			 * @category Developer
490
			 * @see mshop/index/manager/supplier/cleanup/ansi
491
			 * @see mshop/index/manager/supplier/delete/ansi
492
			 * @see mshop/index/manager/supplier/search/ansi
493
			 * @see mshop/index/manager/supplier/count/ansi
494
			 */
495
			$stmt = $this->getCachedStatement( $conn, 'mshop/index/manager/supplier/insert' );
496
497
			foreach( $items as $id => $item )
498
			{
499
				foreach( $item->getListItems( 'supplier' ) as $listItem )
500
				{
501
					if( ( $supplier = $listItem->getRefItem() ) === null ) {
502
						continue;
503
					}
504
505
					$pairs = $supplier->getAddressItems()->map( function( $addr ) {
506
						return $addr->getLatitude() !== null && $addr->getLongitude() !== null
507
							? ['lat' => $addr->getLatitude(), 'lon' => $addr->getLongitude()]
508
							: null;
509
					} )->filter();
510
511
					if( $pairs->isEmpty() ) {
512
						$pairs = [['lat' => null, 'lon' => null]];
513
					}
514
515
					foreach( $pairs as $pair )
516
					{
517
						$stmt->bind( 1, $listItem->getParentId(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
518
						$stmt->bind( 2, $listItem->getRefId(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
519
						$stmt->bind( 3, $listItem->getType() );
520
						$stmt->bind( 4, $listItem->getPosition(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
521
						$stmt->bind( 5, $pair['lat'] ?? null, \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT );
522
						$stmt->bind( 6, $pair['lon'] ?? null, \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT );
523
						$stmt->bind( 7, $date ); //mtime
524
						$stmt->bind( 8, $siteid );
525
526
						try {
527
							$stmt->execute()->finish();
528
						} catch( \Aimeos\Base\DB\Exception $e ) { ; } // Ignore duplicates
529
					}
530
				}
531
			}
532
533
		foreach( $this->getSubManagers() as $submanager ) {
534
			$submanager->rebuild( $items );
535
		}
536
537
		return $this;
538
	}
539
540
541
	/**
542
	 * Removes the products from the product index.
543
	 *
544
	 * @param array|string $ids Product ID or list of IDs
545
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
546
	 */
547
	public function remove( $ids ) : \Aimeos\MShop\Index\Manager\Iface
548
	{
549
		parent::remove( $ids )->delete( $ids );
550
		return $this;
551
	}
552
553
554
	/**
555
	 * Searches for items matching the given criteria.
556
	 *
557
	 * @param \Aimeos\Base\Criteria\Iface $search Search criteria object
558
	 * @param string[] $ref List of domains to fetch list items and referenced items for
559
	 * @param int|null &$total Number of items that are available in total
560
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Product\Item\Iface with ids as keys
561
	 */
562
	public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
563
	{
564
		/** mshop/index/manager/supplier/search/mysql
565
		 * Retrieves the records matched by the given criteria in the database
566
		 *
567
		 * @see mshop/index/manager/supplier/search/ansi
568
		 */
569
570
		/** mshop/index/manager/supplier/search/ansi
571
		 * Retrieves the records matched by the given criteria in the database
572
		 *
573
		 * Fetches the records matched by the given criteria from the product index
574
		 * database. The records must be from one of the sites that are
575
		 * configured via the context item. If the current site is part of
576
		 * a tree of sites, the SELECT statement can retrieve all records
577
		 * from the current site and the complete sub-tree of sites.
578
		 *
579
		 * As the records can normally be limited by criteria from sub-managers,
580
		 * their tables must be joined in the SQL context. This is done by
581
		 * using the "internaldeps" property from the definition of the ID
582
		 * column of the sub-managers. These internal dependencies specify
583
		 * the JOIN between the tables and the used columns for joining. The
584
		 * ":joins" placeholder is then replaced by the JOIN strings from
585
		 * the sub-managers.
586
		 *
587
		 * To limit the records matched, conditions can be added to the given
588
		 * criteria object. It can contain comparisons like column names that
589
		 * must match specific values which can be combined by AND, OR or NOT
590
		 * operators. The resulting string of SQL conditions replaces the
591
		 * ":cond" placeholder before the statement is sent to the database
592
		 * server.
593
		 *
594
		 * If the records that are retrieved should be ordered by one or more
595
		 * columns, the generated string of column / sort direction pairs
596
		 * replaces the ":order" placeholder. In case no ordering is required,
597
		 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
598
		 * markers is removed to speed up retrieving the records. Columns of
599
		 * sub-managers can also be used for ordering the result set but then
600
		 * no index can be used.
601
		 *
602
		 * The number of returned records can be limited and can start at any
603
		 * number between the begining and the end of the result set. For that
604
		 * the ":size" and ":start" placeholders are replaced by the
605
		 * corresponding values from the criteria object. The default values
606
		 * are 0 for the start and 100 for the size value.
607
		 *
608
		 * The SQL statement should conform to the ANSI standard to be
609
		 * compatible with most relational database systems. This also
610
		 * includes using double quotes for table and column names.
611
		 *
612
		 * @param string SQL statement for searching items
613
		 * @since 2018.07
614
		 * @category Developer
615
		 * @see mshop/index/manager/supplier/count/ansi
616
		 * @see mshop/index/manager/supplier/optimize/ansi
617
		 * @see mshop/index/manager/supplier/aggregate/ansi
618
		 */
619
		$cfgPathSearch = 'mshop/index/manager/supplier/search';
620
621
		/** mshop/index/manager/supplier/count/mysql
622
		 * Counts the number of records matched by the given criteria in the database
623
		 *
624
		 * @see mshop/index/manager/supplier/count/ansi
625
		 */
626
627
		/** mshop/index/manager/supplier/count/ansi
628
		 * Counts the number of records matched by the given criteria in the database
629
		 *
630
		 * Counts all records matched by the given criteria from the product index
631
		 * database. The records must be from one of the sites that are
632
		 * configured via the context item. If the current site is part of
633
		 * a tree of sites, the statement can count all records from the
634
		 * current site and the complete sub-tree of sites.
635
		 *
636
		 * As the records can normally be limited by criteria from sub-managers,
637
		 * their tables must be joined in the SQL context. This is done by
638
		 * using the "internaldeps" property from the definition of the ID
639
		 * column of the sub-managers. These internal dependencies specify
640
		 * the JOIN between the tables and the used columns for joining. The
641
		 * ":joins" placeholder is then replaced by the JOIN strings from
642
		 * the sub-managers.
643
		 *
644
		 * To limit the records matched, conditions can be added to the given
645
		 * criteria object. It can contain comparisons like column names that
646
		 * must match specific values which can be combined by AND, OR or NOT
647
		 * operators. The resulting string of SQL conditions replaces the
648
		 * ":cond" placeholder before the statement is sent to the database
649
		 * server.
650
		 *
651
		 * Both, the strings for ":joins" and for ":cond" are the same as for
652
		 * the "search" SQL statement.
653
		 *
654
		 * Contrary to the "search" statement, it doesn't return any records
655
		 * but instead the number of records that have been found. As counting
656
		 * thousands of records can be a long running task, the maximum number
657
		 * of counted records is limited for performance reasons.
658
		 *
659
		 * The SQL statement should conform to the ANSI standard to be
660
		 * compatible with most relational database systems. This also
661
		 * includes using double quotes for table and column names.
662
		 *
663
		 * @param string SQL statement for counting items
664
		 * @since 2018.07
665
		 * @category Developer
666
		 * @see mshop/index/manager/supplier/search/ansi
667
		 * @see mshop/index/manager/supplier/optimize/ansi
668
		 * @see mshop/index/manager/supplier/aggregate/ansi
669
		 */
670
		$cfgPathCount = 'mshop/index/manager/supplier/count';
671
672
		return $this->searchItemsIndexBase( $search, $ref, $total, $cfgPathSearch, $cfgPathCount );
673
	}
674
675
676
	/**
677
	 * Returns the list of sub-managers available for the index supplier manager.
678
	 *
679
	 * @return \Aimeos\MShop\Index\Manager\Iface[] Associative list of the sub-domain as key and the manager object as value
680
	 */
681
	protected function getSubManagers() : array
682
	{
683
		if( $this->subManagers === null )
684
		{
685
			$this->subManagers = [];
686
			$config = $this->context()->config();
687
688
			/** mshop/index/manager/supplier/submanagers
689
			 * A list of sub-manager names used for indexing associated items to categories
690
			 *
691
			 * All items referenced by a product (e.g. texts, prices, media,
692
			 * etc.) are added to the product index via specialized index
693
			 * managers. You can add the name of new sub-managers to add more
694
			 * data to the index or remove existing ones if you don't want to
695
			 * index that data at all.
696
			 *
697
			 * This option configures the sub-managers that cares about
698
			 * indexing data associated to product categories.
699
			 *
700
			 * @param string List of index sub-manager names
701
			 * @since 2018.07
702
			 * @category User
703
			 * @category Developer
704
			 * @see mshop/index/manager/submanagers
705
			 */
706
			foreach( $config->get( 'mshop/index/manager/supplier/submanagers', [] ) as $domain )
707
			{
708
				$name = $config->get( 'mshop/index/manager/supplier/' . $domain . '/name' );
709
				$this->subManagers[$domain] = $this->object()->getSubManager( $domain, $name );
710
			}
711
712
			return $this->subManagers;
713
		}
714
715
		return $this->subManagers;
716
	}
717
}
718