Passed
Push — master ( 34ac4e...42601f )
by Aimeos
06:35
created

StandardTest::testSearchItemsBase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\MShop\Index\Manager;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private static $products;
16
	private $context;
17
	private $object;
18
	private $editor = '';
19
20
21
	public static function setUpBeforeClass()
22
	{
23
		$context = \TestHelperMShop::getContext();
24
25
		$manager = new \Aimeos\MShop\Index\Manager\Standard( $context );
26
		$productManager = \Aimeos\MShop\Product\Manager\Factory::createManager( $context );
27
28
		$search = $productManager->createSearch();
29
		$conditions = array(
30
			$search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ),
31
			$search->compare( '==', 'product.editor', $context->getEditor() ),
32
		);
33
		$search->setConditions( $search->combine( '&&', $conditions ) );
34
		$result = $productManager->searchItems( $search, array( 'attribute', 'price', 'text', 'product' ) );
35
36
		if( count( $result ) !== 2 ) {
37
			throw new \RuntimeException( 'Products not available' );
38
		}
39
40
		foreach( $result as $item )
41
		{
42
			self::$products[$item->getCode()] = $item;
43
			$manager->saveItem( $item );
44
		}
45
	}
46
47
48
	protected function setUp()
49
	{
50
		$this->context = \TestHelperMShop::getContext();
51
		$this->editor = $this->context->getEditor();
52
		$this->object = new \Aimeos\MShop\Index\Manager\Standard( $this->context );
53
	}
54
55
56
	protected function tearDown()
57
	{
58
		unset( $this->object );
59
	}
60
61
62
	public function testCreateItem()
63
	{
64
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $this->object->createItem() );
65
	}
66
67
68
	public function testCreateSearch()
69
	{
70
		$this->assertInstanceOf( \Aimeos\MW\Criteria\Iface::class, $this->object->createSearch() );
71
	}
72
73
74
	public function testAggregate()
75
	{
76
		$manager = \Aimeos\MShop\Factory::createManager( \TestHelperMShop::getContext(), 'attribute' );
77
78
		$search = $manager->createSearch();
79
		$expr = array(
80
			$search->compare( '==', 'attribute.code', 'white' ),
81
			$search->compare( '==', 'attribute.domain', 'product' ),
82
			$search->compare( '==', 'attribute.type.code', 'color' ),
83
		);
84
		$search->setConditions( $search->combine( '&&', $expr ) );
85
86
		$items = $manager->searchItems( $search );
87
88
		if( ( $item = reset( $items ) ) === false ) {
89
			throw new \RuntimeException( 'No attribute found' );
90
		}
91
92
93
		$search = $this->object->createSearch( true );
94
		$result = $this->object->aggregate( $search, 'index.attribute.id' );
95
96
		$this->assertEquals( 15, count( $result ) );
97
		$this->assertArrayHasKey( $item->getId(), $result );
98
		$this->assertEquals( 4, $result[$item->getId()] );
99
	}
100
101
102
	public function testGetItem()
103
	{
104
		$productManager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context );
105
		$product = $productManager->findItem( 'CNE' );
1 ignored issue
show
Bug introduced by
The method findItem() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Index\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Index\Manager\Attribute\Iface or Aimeos\MShop\Index\Manager\Text\Iface or Aimeos\MShop\Index\Manager\Supplier\Iface or Aimeos\MShop\Index\Manager\Catalog\Iface or Aimeos\MShop\Index\Manager\Price\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
		/** @scrutinizer ignore-call */ 
106
  $product = $productManager->findItem( 'CNE' );
Loading history...
106
107
		$item = $this->object->getItem( $product->getId() );
108
		$this->assertEquals( $product, $item );
109
	}
110
111
112
	public function testGetResourceType()
113
	{
114
		$result = $this->object->getResourceType();
115
116
		$this->assertContains( 'index', $result );
117
		$this->assertContains( 'index/attribute', $result );
118
		$this->assertContains( 'index/supplier', $result );
119
		$this->assertContains( 'index/catalog', $result );
120
		$this->assertContains( 'index/price', $result );
121
		$this->assertContains( 'index/text', $result );
122
	}
123
124
125
	public function testGetSearchAttributes()
126
	{
127
		$attributes = $this->object->getSearchAttributes();
128
129
		foreach( $attributes as $attribute ) {
130
			$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute );
131
		}
132
133
		$this->assertArrayHasKey( 'index.attribute.id', $attributes );
134
		$this->assertArrayHasKey( 'index.catalog.id', $attributes );
135
		$this->assertArrayHasKey( 'index.supplier.id', $attributes );
136
	}
137
138
139
	public function testSaveDeleteItem()
140
	{
141
		$item = self::$products['CNE'];
142
143
		$context = $this->context;
144
		$dbm = $context->getDatabaseManager();
145
		$siteId = $context->getLocale()->getSiteId();
146
147
		$sqlAttribute = 'SELECT COUNT(*) as count FROM "mshop_index_attribute" WHERE "siteid" = ? AND "prodid" = ?';
148
		$sqlCatalog = 'SELECT COUNT(*) as count FROM "mshop_index_catalog" WHERE "siteid" = ? AND "prodid" = ?';
149
		$sqlPrice = 'SELECT COUNT(*) as count FROM "mshop_index_price" WHERE "siteid" = ? AND "prodid" = ?';
150
		$sqlText = 'SELECT COUNT(*) as count FROM "mshop_index_text" WHERE "siteid" = ? AND "prodid" = ?';
151
152
		$this->object->saveItem( $item );
153
154
		$cntAttributeA = $this->getValue( $dbm, $sqlAttribute, 'count', $siteId, $item->getId() );
155
		$cntCatalogA = $this->getValue( $dbm, $sqlCatalog, 'count', $siteId, $item->getId() );
156
		$cntPriceA = $this->getValue( $dbm, $sqlPrice, 'count', $siteId, $item->getId() );
157
		$cntTextA = $this->getValue( $dbm, $sqlText, 'count', $siteId, $item->getId() );
158
159
160
		$this->object->deleteItem( $item->getId() );
161
162
		$cntAttributeB = $this->getValue( $dbm, $sqlAttribute, 'count', $siteId, $item->getId() );
163
		$cntCatalogB = $this->getValue( $dbm, $sqlCatalog, 'count', $siteId, $item->getId() );
164
		$cntPriceB = $this->getValue( $dbm, $sqlPrice, 'count', $siteId, $item->getId() );
165
		$cntTextB = $this->getValue( $dbm, $sqlText, 'count', $siteId, $item->getId() );
166
167
168
		// recreate index for CNE
169
		$result = $this->object->saveItem( $item );
170
171
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $result );
172
173
		$this->assertEquals( 8, $cntAttributeA );
174
		$this->assertEquals( 5, $cntCatalogA );
175
		$this->assertEquals( 1, $cntPriceA );
176
		$this->assertEquals( 1, $cntTextA );
177
178
		$this->assertEquals( 0, $cntAttributeB );
179
		$this->assertEquals( 0, $cntCatalogB );
180
		$this->assertEquals( 0, $cntPriceB );
181
		$this->assertEquals( 0, $cntTextB );
182
	}
183
184
185
	public function testSearchItems()
186
	{
187
		$total = 0;
188
		$search = $this->object->createSearch();
189
		$search->setSlice( 0, 1 );
190
191
		$expr = array(
192
			$search->compare( '!=', 'index.catalog.id', null ),
193
			$search->compare( '=~', 'product.label', 'Cafe Noire' ),
194
			$search->compare( '==', 'product.editor', $this->editor ),
195
		);
196
		$search->setConditions( $search->combine( '&&', $expr ) );
197
198
		$result = $this->object->searchItems( $search, [], $total );
199
200
		$this->assertEquals( 1, count( $result ) );
201
		$this->assertEquals( 2, $total );
202
	}
203
204
205
	public function testSearchItemsBase()
206
	{
207
		$search = $this->object->createSearch( true );
208
		$conditions = array(
209
			$search->compare( '!=', 'index.catalog.id', null ),
210
			$search->compare( '==', 'product.editor', $this->editor ),
211
			$search->getConditions()
212
		);
213
		$search->setConditions( $search->combine( '&&', $conditions ) );
214
		$products = $this->object->searchItems( $search );
215
		$this->assertEquals( 8, count( $products ) );
216
217
		foreach( $products as $itemId => $item ) {
218
			$this->assertEquals( $itemId, $item->getId() );
219
		}
220
	}
221
222
223
	public function testSearchItemsAttributeId()
224
	{
225
		$attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager( $this->context );
226
		$attrWidthItem = $attributeManager->findItem( '29', [], 'product', 'width' );
227
228
		$total = 0;
229
		$search = $this->object->createSearch();
230
		$search->setSlice( 0, 1 );
231
232
		$conditions = array(
233
			$search->compare( '==', 'index.attribute.id', $attrWidthItem->getId() ),
234
			$search->compare( '==', 'product.editor', $this->editor ),
235
		);
236
		$search->setConditions( $search->combine( '&&', $conditions ) );
237
		$result = $this->object->searchItems( $search, [], $total );
238
239
		$this->assertEquals( 1, count( $result ) );
240
		$this->assertEquals( 3, $total );
241
	}
242
243
244
	public function testSearchItemsAttributeIdNotNull()
245
	{
246
		$total = 0;
247
		$search = $this->object->createSearch();
248
		$search->setSlice( 0, 1 );
249
250
		$expr = array(
251
			$search->compare( '!=', 'index.attribute.id', null ),
252
			$search->compare( '!=', 'index.catalog.id', null ),
253
			$search->compare( '==', 'product.editor', $this->editor )
254
		);
255
256
		$search->setConditions( $search->combine( '&&', $expr ) );
257
		$result = $this->object->searchItems( $search, [], $total );
258
259
		$this->assertEquals( 1, count( $result ) );
260
		$this->assertEquals( 7, $total );
261
	}
262
263
264
	public function testSearchItemsCatalog()
265
	{
266
		$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
267
		$catItem = $catalogManager->findItem( 'cafe' );
268
269
		$search = $this->object->createSearch()->setSlice( 0, 1 );
270
		$search->setConditions( $search->compare( '==', 'product.editor', $this->editor ) );
271
272
		$sortfunc = $search->createFunction( 'sort:index.catalog:position', array( 'promotion', [$catItem->getId()] ) );
273
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
274
275
		$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) );
276
	}
277
278
279
	public function testSearchItemsCatalogId()
280
	{
281
		$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
282
		$catItem = $catalogManager->findItem( 'cafe' );
283
284
		$search = $this->object->createSearch()->setSlice( 0, 1 );
285
		$total = 0;
286
287
		$conditions = array(
288
			$search->compare( '==', 'index.catalog.id', $catItem->getId() ), // catalog ID
289
			$search->compare( '==', 'product.editor', $this->editor )
290
		);
291
		$search->setConditions( $search->combine( '&&', $conditions ) );
292
		$result = $this->object->searchItems( $search, [], $total );
293
294
		$this->assertEquals( 1, count( $result ) );
295
		$this->assertEquals( 2, $total );
296
	}
297
298
299
	public function testSearchItemsCatalogIdNotNull()
300
	{
301
		$search = $this->object->createSearch()->setSlice( 0, 1 );
302
		$total = 0;
303
304
		$conditions = array(
305
			$search->compare( '!=', 'index.catalog.id', null ), // catalog ID
306
			$search->compare( '==', 'product.editor', $this->editor )
307
		);
308
		$search->setConditions( $search->combine( '&&', $conditions ) );
309
		$result = $this->object->searchItems( $search, [], $total );
310
311
		$this->assertEquals( 1, count( $result ) );
312
		$this->assertEquals( 8, $total );
313
	}
314
315
316
	public function testSearchItemsCatalogPosition()
317
	{
318
		$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
319
		$catItem = $catalogManager->findItem( 'cafe' );
320
321
		$search = $this->object->createSearch()->setSlice( 0, 1 );
322
		$total = 0;
323
324
		$func = $search->createFunction( 'index.catalog:position', array( 'promotion', [$catItem->getId()] ) );
325
		$conditions = array(
326
			$search->compare( '!=', $func, null ), // position
327
			$search->compare( '==', 'product.editor', $this->editor )
328
		);
329
		$search->setConditions( $search->combine( '&&', $conditions ) );
330
331
		$sortfunc = $search->createFunction( 'sort:index.catalog:position', array( 'promotion', [$catItem->getId()] ) );
332
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
333
334
		$result = $this->object->searchItems( $search, [], $total );
335
336
		$this->assertEquals( 1, count( $result ) );
337
		$this->assertEquals( 2, $total );
338
	}
339
340
341
	public function testSearchItemsPrice()
342
	{
343
		$total = 0;
344
		$search = $this->object->createSearch()->setSlice( 0, 1 );
345
346
		$func = $search->createFunction( 'index.price:value', ['EUR'] );
347
		$expr = array(
348
			$search->compare( '>=', $func, '18.00' ),
349
			$search->compare( '!=', 'index.catalog.id', null ),
350
			$search->compare( '==', 'product.editor', $this->editor )
351
		);
352
		$search->setConditions( $search->combine( '&&', $expr ) );
353
354
		$sortfunc = $search->createFunction( 'sort:index.price:value', ['EUR'] );
355
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
356
357
		$result = $this->object->searchItems( $search, [], $total );
358
359
		$this->assertEquals( 1, count( $result ) );
360
		$this->assertEquals( 5, $total );
361
	}
362
363
364
	public function testSearchItemsText()
365
	{
366
		$this->context->getConfig()->set( 'mshop/index/manager/text/name', 'Standard' );
367
		$object = new \Aimeos\MShop\Index\Manager\Standard( $this->context );
368
369
		$total = 0;
370
		$search = $object->createSearch()->setSlice( 0, 1 );
371
372
		$func = $search->createFunction( 'index.text:relevance', array( 'de', 'Cafe' ) );
0 ignored issues
show
Bug introduced by
The method createFunction() does not exist on Aimeos\MW\Criteria\Iface. Since it exists in all sub-types, consider adding an abstract or default implementation to Aimeos\MW\Criteria\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

372
		/** @scrutinizer ignore-call */ 
373
  $func = $search->createFunction( 'index.text:relevance', array( 'de', 'Cafe' ) );
Loading history...
373
		$conditions = array(
374
			$search->compare( '>', $func, 0 ), // text relevance
375
			$search->compare( '==', 'product.editor', $this->editor )
376
		);
377
		$search->setConditions( $search->combine( '&&', $conditions ) );
378
379
		$result = $object->searchItems( $search, [], $total );
380
381
		$this->assertEquals( 1, count( $result ) );
382
		$this->assertEquals( 3, $total );
383
	}
384
385
386
	public function testOptimize()
387
	{
388
		$this->object->optimize();
389
	}
390
391
392
	public function testCleanupIndex()
393
	{
394
		$this->object->cleanupIndex( '1970-01-01 00:00:00' );
395
	}
396
397
398
	public function testRebuildIndexAll()
399
	{
400
		$config = $this->context->getConfig();
401
402
		$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context );
403
		$search = $manager->createSearch( true );
404
		$search->setSlice( 0, 0x7fffffff );
405
406
		//delete whole catalog
407
		$this->object->deleteItems( array_keys( $manager->searchItems( $search ) ) );
408
409
		//build catalog with all products
410
		$config->set( 'mshop/index/manager/standard/index', 'all' );
411
		$this->object->rebuildIndex();
412
413
		$afterInsertAttr = $this->getCatalogSubDomainItems( 'index.attribute.id', 'attribute' );
414
		$afterInsertCat = $this->getCatalogSubDomainItems( 'index.catalog.id', 'catalog' );
415
416
		//restore index with categorized products only
417
		$config->set( 'mshop/index/manager/standard/index', 'categorized' );
418
		$this->object->rebuildIndex();
419
420
		$this->assertEquals( 13, count( $afterInsertAttr ) );
421
		$this->assertEquals( 8, count( $afterInsertCat ) );
422
	}
423
424
425
	public function testRebuildIndexWithList()
426
	{
427
		$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context );
428
		$search = $manager->createSearch();
429
		$search->setSlice( 0, 0x7fffffff );
430
431
		//delete whole catalog
432
		$this->object->deleteItems( array_keys( $manager->searchItems( $search ) ) );
433
434
		$afterDeleteAttr = $this->getCatalogSubDomainItems( 'index.attribute.id', 'attribute' );
435
		$afterDeleteCat = $this->getCatalogSubDomainItems( 'index.catalog.id', 'catalog' );
436
437
		//insert cne, cnc
438
		$search = $manager->createSearch();
439
		$search->setConditions( $search->compare( '==', 'product.code', array( 'CNE', 'CNC' ) ) );
440
		$items = $manager->searchItems( $search );
441
442
		$this->object->rebuildIndex( $items );
443
444
		$afterInsertAttr = $this->getCatalogSubDomainItems( 'index.attribute.id', 'attribute' );
445
		$afterInsertCat = $this->getCatalogSubDomainItems( 'index.catalog.id', 'catalog' );
446
447
		//delete cne, cnc
448
		foreach( $items as $item ) {
449
			$this->object->deleteItem( $item->getId() );
450
		}
451
452
		//restores catalog
453
		$this->object->rebuildIndex();
454
455
		//check delete
456
		$this->assertEquals( [], $afterDeleteAttr );
457
		$this->assertEquals( [], $afterDeleteCat );
458
459
		//check inserted items
460
		$this->assertEquals( 2, count( $afterInsertAttr ) );
461
		$this->assertEquals( 2, count( $afterInsertCat ) );
462
	}
463
464
465
	public function testRebuildIndexCategorizedOnly()
466
	{
467
		$context = $this->context;
468
		$config = $context->getConfig();
469
470
		$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $context );
471
472
		//delete whole catalog
473
		$search = $manager->createSearch();
474
		$search->setSlice( 0, 0x7fffffff );
475
		$this->object->deleteItems( array_keys( $manager->searchItems( $search ) ) );
476
477
		$config->set( 'mshop/index/manager/standard/index', 'categorized' );
478
		$this->object->rebuildIndex();
479
480
		$afterInsertAttr = $this->getCatalogSubDomainItems( 'index.attribute.id', 'attribute' );
481
		$afterInsertCat = $this->getCatalogSubDomainItems( 'index.catalog.id', 'catalog' );
482
483
		//check inserted items
484
		$this->assertEquals( 7, count( $afterInsertAttr ) );
485
		$this->assertEquals( 8, count( $afterInsertCat ) );
486
	}
487
488
489
	/**
490
	 * Returns value of a catalog_index column.
491
	 *
492
	 * @param \Aimeos\MW\DB\Manager\Iface $dbm Database Manager for connection
493
	 * @param string $sql Specified db query to find only one value
494
	 * @param string $column Column where to search
495
	 * @param integer $siteId Siteid of the db entry
496
	 * @param integer $productId Product id
497
	 * @return string $value Value returned for specified sql statement
498
	 * @throws \Exception If column not available or error during a connection to db
499
	 */
500
	protected function getValue( \Aimeos\MW\DB\Manager\Iface $dbm, $sql, $column, $siteId, $productId )
501
	{
502
		$config = $this->context->getConfig();
503
504
		if( $config->get( 'resource/db-product' ) === null ) {
505
			$dbname = $config->get( 'resource/default', 'db' );
506
		} else {
507
			$dbname = 'db-product';
508
		}
509
510
		$conn = $dbm->acquire( $dbname );
511
512
		try
513
		{
514
			$stmt = $conn->create( $sql );
515
			$stmt->bind( 1, $siteId, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
516
			$stmt->bind( 2, $productId, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
517
			$result = $stmt->execute();
518
519
			if( ( $row = $result->fetch() ) === false ) {
1 ignored issue
show
introduced by
The condition $row = $result->fetch() === false is always false.
Loading history...
520
				throw new \RuntimeException( 'No rows available' );
521
			}
522
523
			if( !isset( $row[$column] ) ) {
524
				throw new \RuntimeException( sprintf( 'Column "%1$s" not available for "%2$s"', $column, $sql ) );
525
			}
526
527
			$value = $row[$column];
528
529
			$dbm->release( $conn, $dbname );
530
		}
531
		catch( \Exception $e )
532
		{
533
			$dbm->release( $conn, $dbname );
534
			throw $e;
535
		}
536
537
		return $value;
538
	}
539
540
541
	/**
542
	 * Gets product items of index subdomains specified by the key.
543
	 *
544
	 * @param string $key Key for searchItems
545
	 * @param string $domain Subdomain of index manager
546
	 */
547
	protected function getCatalogSubDomainItems( $key, $domain )
548
	{
549
		$subIndex = $this->object->getSubManager( $domain );
550
		$search = $subIndex->createSearch();
551
552
		$expr = array(
553
			$search->compare( '!=', $key, null ),
554
			$search->compare( '==', 'product.editor', $this->editor )
555
		);
556
557
		$search->setConditions( $search->combine( '&&', $expr ) );
558
559
		return $subIndex->searchItems( $search );
560
	}
561
562
}
563