Skip to content

Commit 3beb5e8

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 88713d0 + faa38f8 commit 3beb5e8

File tree

6 files changed

+191
-117
lines changed

6 files changed

+191
-117
lines changed

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,11 @@ public function prepareProductIndex($indexData, $productData, $storeId)
572572
foreach ($indexData as $entityId => $attributeData) {
573573
foreach ($attributeData as $attributeId => $attributeValues) {
574574
$value = $this->getAttributeValue($attributeId, $attributeValues, $storeId);
575-
if (!empty($value)) {
575+
if ($value !== null && $value !== false && $value != '') {
576576
if (!isset($index[$attributeId])) {
577577
$index[$attributeId] = [];
578578
}
579-
$index[$attributeId][$entityId] = $value;
579+
$index[$attributeId][$entityId] = $value;
580580
}
581581
}
582582
}

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private function convertAttribute(Attribute $attribute, array $attributeValues,
209209
$productAttributes = [];
210210

211211
$retrievedValue = $this->retrieveFieldValue($attributeValues);
212-
if ($retrievedValue) {
212+
if ($retrievedValue !== null) {
213213
$productAttributes[$attribute->getAttributeCode()] = $retrievedValue;
214214

215215
if ($attribute->getIsSearchable()) {
@@ -354,7 +354,7 @@ private function getAttributeOptions(Attribute $attribute, int $storeId): array
354354
*/
355355
private function retrieveFieldValue(array $values)
356356
{
357-
$values = \array_filter(\array_unique($values));
357+
$values = \array_unique($values);
358358

359359
return count($values) === 1 ? \array_shift($values) : \array_values($values);
360360
}

app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder/Term.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function buildFilter(RequestFilterInterface $filter)
6868
$fieldName .= '.' . $suffix;
6969
}
7070

71-
if ($filter->getValue()) {
71+
if ($filter->getValue() !== false) {
7272
$operator = is_array($filter->getValue()) ? 'terms' : 'term';
7373
$filterQuery []= [
7474
$operator => [

dev/tests/integration/testsuite/Magento/Catalog/_files/product_boolean_attribute.php

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Eav\Api\AttributeRepositoryInterface;
1010
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1111
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
12+
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\TestFramework\Helper\Bootstrap;
1314

1415
$objectManager = Bootstrap::getObjectManager();
@@ -19,32 +20,36 @@
1920
/** @var $installer CategorySetup */
2021
$installer = $objectManager->create(CategorySetup::class);
2122

22-
$attribute->setData(
23-
[
24-
'attribute_code' => 'boolean_attribute',
25-
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
26-
'is_global' => 0,
27-
'is_user_defined' => 1,
28-
'frontend_input' => 'boolean',
29-
'is_unique' => 0,
30-
'is_required' => 0,
31-
'is_searchable' => 1,
32-
'is_visible_in_advanced_search' => 1,
33-
'is_comparable' => 0,
34-
'is_filterable' => 1,
35-
'is_filterable_in_search' => 1,
36-
'is_used_for_promo_rules' => 0,
37-
'is_html_allowed_on_front' => 1,
38-
'is_visible_on_front' => 1,
39-
'used_in_product_listing' => 1,
40-
'used_for_sort_by' => 0,
41-
'frontend_label' => ['Boolean Attribute'],
42-
'backend_type' => 'int',
43-
'source_model' => Boolean::class
44-
]
45-
);
23+
try {
24+
$attributeRepository->get(CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID, 'boolean_attribute');
25+
} catch (NoSuchEntityException $e) {
26+
$attribute->setData(
27+
[
28+
'attribute_code' => 'boolean_attribute',
29+
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
30+
'is_global' => 0,
31+
'is_user_defined' => 1,
32+
'frontend_input' => 'boolean',
33+
'is_unique' => 0,
34+
'is_required' => 0,
35+
'is_searchable' => 1,
36+
'is_visible_in_advanced_search' => 1,
37+
'is_comparable' => 0,
38+
'is_filterable' => 1,
39+
'is_filterable_in_search' => 1,
40+
'is_used_for_promo_rules' => 0,
41+
'is_html_allowed_on_front' => 1,
42+
'is_visible_on_front' => 1,
43+
'used_in_product_listing' => 1,
44+
'used_for_sort_by' => 0,
45+
'frontend_label' => ['Boolean Attribute'],
46+
'backend_type' => 'int',
47+
'source_model' => Boolean::class
48+
]
49+
);
4650

47-
$attributeRepository->save($attribute);
51+
$attributeRepository->save($attribute);
4852

49-
/* Assign attribute to attribute set */
50-
$installer->addAttributeToGroup('catalog_product', 'Default', 'Attributes', $attribute->getId());
53+
/* Assign attribute to attribute set */
54+
$installer->addAttributeToGroup('catalog_product', 'Default', 'Attributes', $attribute->getId());
55+
}

dev/tests/integration/testsuite/Magento/Elasticsearch/Model/Indexer/IndexHandlerTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Indexer\Model\Indexer;
2020
use Magento\Framework\Search\EngineResolverInterface;
2121
use Magento\TestModuleCatalogSearch\Model\ElasticsearchVersionChecker;
22+
use PHPUnit\Framework\TestCase;
2223

2324
/**
2425
* Important: Please make sure that each integration test file works with unique elastic search index. In order to
@@ -29,7 +30,7 @@
2930
* @magentoDataFixture Magento/Elasticsearch/_files/indexer.php
3031
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3132
*/
32-
class IndexHandlerTest extends \PHPUnit\Framework\TestCase
33+
class IndexHandlerTest extends TestCase
3334
{
3435
/**
3536
* @var string
@@ -116,6 +117,9 @@ public function testReindexAll(): void
116117

117118
$products = $this->searchByName('Simple Product', $storeId);
118119
$this->assertCount(5, $products);
120+
121+
$this->assertCount(2, $this->searchByBoolAttribute(0, $storeId));
122+
$this->assertCount(3, $this->searchByBoolAttribute(1, $storeId));
119123
}
120124
}
121125

@@ -266,6 +270,32 @@ private function searchByName(string $text, int $storeId): array
266270
return $products;
267271
}
268272

273+
/**
274+
* Search docs in Elasticsearch by boolean attribute.
275+
*
276+
* @param int $value
277+
* @param int $storeId
278+
* @return array
279+
*/
280+
private function searchByBoolAttribute(int $value, int $storeId): array
281+
{
282+
$index = $this->searchIndexNameResolver->getIndexName($storeId, $this->indexer->getId());
283+
$searchQuery = [
284+
'index' => $index,
285+
'type' => $this->entityType,
286+
'body' => [
287+
'query' => [
288+
'query_string' => [
289+
'query' => $value,
290+
'default_field' => 'boolean_attribute',
291+
],
292+
],
293+
],
294+
];
295+
$queryResult = $this->client->query($searchQuery);
296+
return isset($queryResult['hits']['hits']) ? $queryResult['hits']['hits'] : [];
297+
}
298+
269299
/**
270300
* Returns installed on server search service
271301
*

0 commit comments

Comments
 (0)