Skip to content

Commit 780ba08

Browse files
committed
MC-34217: Sku search and Partial search by name in Advanced Search not working correctly
1 parent 2e2af0a commit 780ba08

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed

app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ private function generateAdvancedSearchRequest()
186186
[
187187
'field' => $attribute->getAttributeCode(),
188188
'boost' => $attribute->getSearchWeight() ?: 1,
189+
'matchCondition' => 'match_phrase_prefix',
189190
],
190191
],
191192
];

app/code/Magento/CatalogSearch/Test/Mftf/Test/StorefrontAdvancedSearchByPartialNameTest.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
1111
<test name="StorefrontAdvancedSearchByPartialNameTest" extends="StorefrontAdvancedSearchEntitySimpleProductTest">
1212
<annotations>
13+
<features value="CatalogSearch"/>
1314
<stories value="Use Advanced Search"/>
1415
<title value="Search product in advanced search by partial name"/>
1516
<description value="Search product in advanced search by partial name"/>
16-
<testCaseId value="MAGETWO-24729"/>
1717
<severity value="CRITICAL"/>
18+
<testCaseId value="MC-40416"/>
1819
<group value="searchFrontend"/>
1920
<group value="mtf_migrated"/>
2021
<group value="SearchEngineElasticsearch"/>
21-
<skip>
22-
<issueId value="MC-34217"/>
23-
</skip>
2422
</annotations>
2523
<actionGroup ref="StorefrontFillFormAdvancedSearchActionGroup" stepKey="search">
2624
<argument name="productName" value="abc"/>

dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/ResultTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ public function testExecuteSkuWithHyphen(): void
101101
$this->assertStringContainsString('Simple product name', $responseBody);
102102
}
103103

104+
/**
105+
* Advanced search with an underscore in product attributes.
106+
*
107+
* @magentoAppArea frontend
108+
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search_with_underscore.php
109+
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
110+
*
111+
* @return void
112+
*/
113+
public function testExecuteWithUnderscore(): void
114+
{
115+
$this->getRequest()->setQuery(
116+
$this->_objectManager->create(
117+
Parameters::class,
118+
[
119+
'values' => [
120+
'name' => 'name',
121+
'sku' => 'sku',
122+
'description' => 'description',
123+
'short_description' => 'short',
124+
'price' => [
125+
'from' => '',
126+
'to' => '',
127+
],
128+
],
129+
]
130+
)
131+
);
132+
$this->dispatch('catalogsearch/advanced/result');
133+
$responseBody = $this->getResponse()->getBody();
134+
$this->assertStringContainsString('name_simple_product', $responseBody);
135+
}
136+
104137
/**
105138
* Data provider with strings for quick search.
106139
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Catalog\Model\Product\Type;
13+
use Magento\Catalog\Model\Product\Visibility;
14+
use Magento\Store\Api\WebsiteRepositoryInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
/** @var WebsiteRepositoryInterface $websiteRepository */
19+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
20+
$baseWebsite = $websiteRepository->get('base');
21+
/** @var ProductInterfaceFactory $productFactory */
22+
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
23+
/** @var ProductRepositoryInterface $productRepository */
24+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
25+
26+
$product = $productFactory->create();
27+
$product->isObjectNew(true);
28+
$product->setTypeId(Type::TYPE_SIMPLE)
29+
->setAttributeSetId($product->getDefaultAttributeSetId())
30+
->setWebsiteIds([$baseWebsite->getId()])
31+
->setName('name_simple_product')
32+
->setSku('sku_simple_product')
33+
->setShortDescription('short_description_simple_product')
34+
->setDescription('description_simple_product')
35+
->setVisibility(Visibility::VISIBILITY_BOTH)
36+
->setStatus(Status::STATUS_ENABLED)
37+
->setPrice(100)
38+
->setWeight(1)
39+
->setTaxClassId(0)
40+
->setStockData(
41+
[
42+
'use_config_manage_stock' => 1,
43+
'qty' => 100,
44+
'is_qty_decimal' => 0,
45+
'is_in_stock' => 1,
46+
]
47+
);
48+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
/** @var Registry $registry */
15+
$registry = $objectManager->get(Registry::class);
16+
/** @var ProductRepositoryInterface $productRepository */
17+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
18+
19+
$registry->unregister('isSecureArea');
20+
$registry->register('isSecureArea', true);
21+
22+
try {
23+
$product = $productRepository->get('sku_simple_product', false, null, true);
24+
$productRepository->delete($product);
25+
} catch (NoSuchEntityException $e) {
26+
//product already deleted.
27+
}
28+
29+
$registry->unregister('isSecureArea');
30+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)