Skip to content

Commit 7f2ced9

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-70062' into PANDA-FIXES-2.1
2 parents 8d7b39d + ced7a2e commit 7f2ced9

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Ui\DataProvider\Product;
7+
8+
/**
9+
* Collection which is used for rendering product list in the backend.
10+
*
11+
* Used for product grid and customizes behavior of the default Product collection for grid needs.
12+
*/
13+
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
14+
{
15+
/**
16+
* Disables using of price index for grid rendering
17+
*
18+
* Admin area shouldn't use price index and should rely on actual product data instead.
19+
*
20+
* @codeCoverageIgnore
21+
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
22+
*/
23+
protected function _productLimitationJoinPrice()
24+
{
25+
$this->_productLimitationFilters->setUsePriceIndex(false);
26+
return $this->_productLimitationPrice(true);
27+
}
28+
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
<type name="Magento\Catalog\Model\ResourceModel\Attribute">
7878
<plugin name="invalidate_pagecache_after_attribute_save" type="Magento\Catalog\Plugin\Model\ResourceModel\Attribute\Save" />
7979
</type>
80+
<virtualType name="\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory" type="\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
81+
<arguments>
82+
<argument name="instanceName" xsi:type="string">\Magento\Catalog\Ui\DataProvider\Product\ProductCollection</argument>
83+
</arguments>
84+
</virtualType>
8085
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
8186
<arguments>
8287
<argument name="addFieldStrategies" xsi:type="array">
@@ -85,6 +90,7 @@
8590
<argument name="addFilterStrategies" xsi:type="array">
8691
<item name="store_id" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddStoreFieldToCollection</item>
8792
</argument>
93+
<argument name="collectionFactory" xsi:type="object">\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument>
8894
</arguments>
8995
</type>
9096
<type name="Magento\Catalog\Model\Product\Action">
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Ui\DataProvider;
7+
8+
use Magento\Framework\Data\Collection;
9+
10+
/**
11+
* @magentoAppArea adminhtml
12+
*/
13+
class ProductTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider
17+
*/
18+
private $dataProvider;
19+
20+
protected function setUp()
21+
{
22+
$this->dataProvider = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
23+
\Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider::class,
24+
[
25+
'name'=> 'products',
26+
'primaryFieldName' => 'entity_id',
27+
'requestFieldName' => 'id',
28+
]
29+
);
30+
}
31+
32+
/**
33+
* @dataProvider sortingFieldsDataProvider
34+
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
35+
*
36+
* @param string $orderByField
37+
* @param string $direction
38+
*/
39+
public function testSortingNotAffectsCount($orderByField, $direction)
40+
{
41+
$this->dataProvider->addOrder($orderByField, $direction);
42+
$result = $this->dataProvider->getData();
43+
$this->assertEquals(3, $result['totalRecords']);
44+
}
45+
46+
/**
47+
* @return array
48+
*/
49+
public function sortingFieldsDataProvider()
50+
{
51+
return [
52+
'name ASC' => ['name', Collection::SORT_ORDER_ASC],
53+
'name DESC' => ['name', Collection::SORT_ORDER_DESC],
54+
'sku ASC' => ['sku', Collection::SORT_ORDER_ASC],
55+
'sku DESC' => ['sku', Collection::SORT_ORDER_DESC],
56+
'price ASC' => ['price', Collection::SORT_ORDER_ASC],
57+
'price DESC' => ['price', Collection::SORT_ORDER_DESC],
58+
];
59+
}
60+
}

0 commit comments

Comments
 (0)