Skip to content

Commit b0aa60a

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-59163: Category product count incorporating products with visibility set to search only
1 parent 378c139 commit b0aa60a

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/AliasResolverTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public function aliasDataProvider()
6363
],
6464
'category_ids' => [
6565
'field' => 'category_ids',
66-
'alias' => 'category_ids_index',
66+
'alias' => 'category_products_index',
67+
],
68+
'visibility' => [
69+
'field' => 'visibility',
70+
'alias' => 'category_products_index',
6771
],
6872
];
6973
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ public function testProcessPrice()
203203
public function processCategoryIdsDataProvider()
204204
{
205205
return [
206-
['5', 'category_ids_index.category_id = 5'],
207-
[3, 'category_ids_index.category_id = 3'],
208-
["' and 1 = 0", 'category_ids_index.category_id = 0'],
206+
['5', ':alias.category_id = 5'],
207+
[3, ':alias.category_id = 3'],
208+
["' and 1 = 0", ':alias.category_id = 0'],
209209
];
210210
}
211211

@@ -218,7 +218,11 @@ public function testProcessCategoryIds($categoryId, $expectedResult)
218218
{
219219
$isNegation = false;
220220
$query = 'SELECT category_ids FROM catalog_product_entity';
221+
$tableAlias = 'category__alias';
221222

223+
$this->aliasResolver->expects($this->atLeastOnce())
224+
->method('getAlias')
225+
->willReturn($tableAlias);
222226
$this->filter->expects($this->exactly(3))
223227
->method('getField')
224228
->will($this->returnValue('category_ids'));
@@ -233,9 +237,35 @@ public function testProcessCategoryIds($categoryId, $expectedResult)
233237
->will($this->returnValue($this->attribute));
234238

235239
$actualResult = $this->target->process($this->filter, $isNegation, $query);
240+
$expectedResult = strtr($expectedResult, [':alias' => $tableAlias]);
236241
$this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
237242
}
238243

244+
public function testProcessVisibilityIds()
245+
{
246+
$query = 'visibility in (1, 2)';
247+
$tableAlias = 'visibility__alias';
248+
249+
$this->aliasResolver->expects($this->atLeastOnce())
250+
->method('getAlias')
251+
->willReturn($tableAlias);
252+
$this->filter->expects($this->atLeastOnce())
253+
->method('getField')
254+
->will($this->returnValue('visibility'));
255+
$this->filter->expects($this->never())
256+
->method('getValue');
257+
$this->config->expects($this->once())
258+
->method('getAttribute')
259+
->with(\Magento\Catalog\Model\Product::ENTITY, 'visibility')
260+
->will($this->returnValue($this->attribute));
261+
262+
$actualResult = $this->target->process($this->filter, false, $query);
263+
$this->assertSame(
264+
"$tableAlias.$query",
265+
$this->removeWhitespaces($actualResult)
266+
);
267+
}
268+
239269
public function testProcessStaticAttribute()
240270
{
241271
$expectedResult = 'attr_table_alias.static_attribute LIKE %name%';
@@ -246,7 +276,7 @@ public function testProcessStaticAttribute()
246276
->willReturn('static_attribute');
247277
$this->aliasResolver->expects($this->once())->method('getAlias')
248278
->willReturn('attr_table_alias');
249-
$this->filter->expects($this->exactly(3))
279+
$this->filter->expects($this->exactly(4))
250280
->method('getField')
251281
->will($this->returnValue('static_attribute'));
252282
$this->config->expects($this->exactly(1))
@@ -285,7 +315,7 @@ public function testProcessTermFilter($frontendInput, $fieldValue, $isNegation,
285315
$this->aliasResolver->expects($this->once())->method('getAlias')
286316
->willReturn('termAttrAlias');
287317

288-
$this->filter->expects($this->exactly(3))
318+
$this->filter->expects($this->exactly(4))
289319
->method('getField')
290320
->willReturn('termField');
291321
$this->filter->expects($this->exactly(2))
@@ -360,7 +390,7 @@ public function testProcessNotStaticAttribute()
360390
$attributeId = 1234567;
361391

362392
$this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
363-
$this->filter->expects($this->exactly(4))
393+
$this->filter->expects($this->exactly(5))
364394
->method('getField')
365395
->will($this->returnValue('not_static_attribute'));
366396
$this->config->expects($this->exactly(1))

dev/tests/api-functional/testsuite/Magento/Framework/Api/Search/SearchTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function testCatalogSearch()
3434
'field' => 'price_dynamic_algorithm',
3535
'value' => 'auto',
3636
'condition_type' => 'eq'
37+
],
38+
[
39+
'field' => 'visibility',
40+
'value' => [3, 4],
41+
'condition_type' => 'eq'
3742
]
3843
]
3944
]

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/ResourceModel/Fulltext/CollectionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function filtersDataProviderSearch()
4040
['catalog_view_container', ['category_ids' => 100001], 0],
4141
['catalog_view_container', ['category_ids' => []], 0],
4242
['catalog_view_container', [], 0],
43+
['catalog_view_container', ['visibility' => [2, 4]], 5],
4344
];
4445
}
4546
}

0 commit comments

Comments
 (0)