Skip to content

Commit 983da74

Browse files
committed
MAGETWO-70062: Product price filter in admin shows incorrect product amount
- Don't use price index for product grid on backend - Add integration test
1 parent efb475b commit 983da74

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Collection.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
1414
{
1515
/**
16-
* Join Product Price Table using left-join
16+
* Disables using of price index for grid rendering
1717
*
18-
* Customizes how price index joined to product collection in order to show disabled products in the list.
19-
* It's needed as price index by its nature contains only values for enabled products.
20-
* However, product grid requires to show all available products without any implicit filtering.
18+
* Admin area shouldn't use price index and should rely on actual product data instead.
2119
*
2220
* @codeCoverageIgnore
2321
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
2422
*/
2523
protected function _productLimitationJoinPrice()
2624
{
25+
$this->_productLimitationFilters->setUsePriceIndex(false);
2726
return $this->_productLimitationPrice(true);
2827
}
2928
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Data\Collection;
8+
9+
/**
10+
* @magentoAppArea adminhtml
11+
*/
12+
class ProductTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider
16+
*/
17+
private $dataProvider;
18+
19+
protected function setUp()
20+
{
21+
$this->dataProvider = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
22+
\Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider::class,
23+
[
24+
'name'=> 'products',
25+
'primaryFieldName' => 'entity_id',
26+
'requestFieldName' => 'id',
27+
]
28+
);
29+
}
30+
31+
/**
32+
* @dataProvider sortingFieldsDataProvider
33+
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
34+
*
35+
* @param string $orderByField
36+
* @param string $direction
37+
*/
38+
public function testSortingNotAffectsCount($orderByField, $direction)
39+
{
40+
$this->dataProvider->addOrder($orderByField, $direction);
41+
$result = $this->dataProvider->getData();
42+
$this->assertEquals(3, $result['totalRecords']);
43+
}
44+
45+
/**
46+
* @return array
47+
*/
48+
public function sortingFieldsDataProvider()
49+
{
50+
return [
51+
'name ASC' => ['name', Collection::SORT_ORDER_ASC],
52+
'name DESC' => ['name', Collection::SORT_ORDER_DESC],
53+
'sku ASC' => ['sku', Collection::SORT_ORDER_ASC],
54+
'sku DESC' => ['sku', Collection::SORT_ORDER_DESC],
55+
'price ASC' => ['price', Collection::SORT_ORDER_ASC],
56+
'price DESC' => ['price', Collection::SORT_ORDER_DESC],
57+
];
58+
}
59+
}

0 commit comments

Comments
 (0)