Skip to content

Commit 27e1817

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-pr137
2 parents 0353a27 + e41f379 commit 27e1817

File tree

8 files changed

+267
-118
lines changed

8 files changed

+267
-118
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private function convertAttribute(Attribute $attribute, array $attributeValues,
216216
$productAttributes = [];
217217

218218
$retrievedValue = $this->retrieveFieldValue($attributeValues);
219-
if ($retrievedValue) {
219+
if ($retrievedValue !== null) {
220220
$productAttributes[$attribute->getAttributeCode()] = $retrievedValue;
221221

222222
if ($this->isAttributeLabelsShouldBeMapped($attribute)) {
@@ -385,8 +385,8 @@ private function getAttributeOptions(Attribute $attribute, int $storeId): array
385385
*/
386386
private function retrieveFieldValue(array $values)
387387
{
388-
$values = \array_filter(\array_unique($values));
388+
$values = array_unique($values);
389389

390-
return count($values) === 1 ? \array_shift($values) : \array_values($values);
390+
return count($values) === 1 ? array_shift($values) : array_values($values);
391391
}
392392
}

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+
}
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+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Helper\DefaultCategory;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\Catalog\Model\Product\Type;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Store\Api\WebsiteRepositoryInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
18+
$objectManager = Bootstrap::getObjectManager();
19+
/** @var WebsiteRepositoryInterface $websiteRepository */
20+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
21+
$defaultWebsiteId = $websiteRepository->get('base')->getId();
22+
/** @var DefaultCategory $defaultCategory */
23+
$defaultCategory = $objectManager->get(DefaultCategory::class);
24+
/** @var ProductRepositoryInterface $productRepository */
25+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
26+
/** @var ProductInterfaceFactory $productFactory */
27+
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
28+
$product = $productFactory->create();
29+
$productData = [
30+
ProductInterface::TYPE_ID => Type::TYPE_SIMPLE,
31+
ProductInterface::ATTRIBUTE_SET_ID => $product->getDefaultAttributeSetId(),
32+
ProductInterface::SKU => 'product_disabled',
33+
ProductInterface::NAME => 'Product with category',
34+
ProductInterface::PRICE => 10,
35+
ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH,
36+
ProductInterface::STATUS => Status::STATUS_DISABLED,
37+
'website_ids' => [$defaultWebsiteId],
38+
'stock_data' => [
39+
'use_config_manage_stock' => 1,
40+
'qty' => 100,
41+
'is_qty_decimal' => 0,
42+
'is_in_stock' => 1,
43+
],
44+
'category_ids' => [$defaultCategory->getId()],
45+
];
46+
$product->setData($productData);
47+
48+
$productRepository->save($product);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
$registry->unregister('isSecureArea');
19+
$registry->register('isSecureArea', true);
20+
21+
try {
22+
$productRepository->deleteById('product_disabled');
23+
} catch (NoSuchEntityException $e) {
24+
// product already deleted
25+
}
26+
27+
$registry->unregister('isSecureArea');
28+
$registry->register('isSecureArea', false);

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)