Skip to content

Commit 8d3f33e

Browse files
committed
MC-37477: Advanced Search on Elasticsearch returns Configurable Product Children as Individual Search Results
1 parent 844c946 commit 8d3f33e

File tree

2 files changed

+67
-1
lines changed
  • app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced
  • dev/tests/integration/testsuite/Magento/Elasticsearch/Model/CatalogSearch

2 files changed

+67
-1
lines changed

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public function _loadEntities($printQuery = false, $logQuery = false)
407407
$query = $this->getSelect();
408408
$rows = $this->_fetchAll($query);
409409
} catch (\Exception $e) {
410-
$this->printLogQuery(false, true, $query);
410+
$this->printLogQuery(false, true, $query ?? null);
411411
throw $e;
412412
}
413413

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch\Model\CatalogSearch;
9+
10+
use Magento\CatalogSearch\Model\Advanced;
11+
use Magento\Catalog\Model\Product\Visibility;
12+
use Magento\Catalog\Api\Data\ProductInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Check catalog Advanced Search process with Elasticsearch enabled.
18+
*/
19+
class AdvancedTest extends TestCase
20+
{
21+
/**
22+
* @var Visibility
23+
*/
24+
private $productVisibility;
25+
26+
/**
27+
* @var Advanced
28+
*/
29+
private $advancedSearch;
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
protected function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
$objectManager = Bootstrap::getObjectManager();
39+
$this->productVisibility = $objectManager->get(Visibility::class);
40+
$this->advancedSearch = $objectManager->get(Advanced::class);
41+
}
42+
43+
/**
44+
* Check that Advanced Search does NOT return products that do NOT have search visibility.
45+
*
46+
* @magentoDbIsolation disabled
47+
* @magentoConfigFixture default/catalog/search/engine elasticsearch7
48+
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_child_products.php
49+
* @return void
50+
*/
51+
public function testAddFilters(): void
52+
{
53+
$searchName = 'Configurable';
54+
55+
$this->advancedSearch->addFilters(['name' => $searchName]);
56+
/** @var ProductInterface[] $itemsResult */
57+
$itemsResult = $this->advancedSearch->getProductCollection()
58+
->addAttributeToSelect(ProductInterface::VISIBILITY)
59+
->getItems();
60+
$this->assertCount(1, $itemsResult);
61+
62+
$product = array_shift($itemsResult);
63+
$this->assertStringContainsString($searchName, $product->getName());
64+
$this->assertContains((int)$product->getVisibility(), $this->productVisibility->getVisibleInSearchIds());
65+
}
66+
}

0 commit comments

Comments
 (0)