Skip to content

Commit ff7c2d5

Browse files
authored
Merge pull request #1168 from magento-dragons/DRAGONS-BUGFIXES
Fixed an issue: - MAGETWO-62227 Unable to sort attributes table when trying to Add Attribute to a product
2 parents 515b0b8 + 63b7c78 commit ff7c2d5

File tree

2 files changed

+56
-1
lines changed
  • app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes
  • dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Attributes

2 files changed

+56
-1
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public function __construct(
4141
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
4242
$this->request = $request;
4343
$this->collection = $collectionFactory->create();
44-
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
4544
}
4645

4746
/**
4847
* {@inheritdoc}
4948
*/
5049
public function getData()
5150
{
51+
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
52+
$this->collection->getSelect()->setPart('order', []);
53+
5254
$items = [];
5355
foreach ($this->getCollection()->getItems() as $attribute) {
5456
$items[] = $attribute->toArray();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Ui\DataProvider\Product\Attributes;
7+
8+
class ListingTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \Magento\Catalog\Ui\DataProvider\Product\Attributes\Listing */
11+
private $dataProvider;
12+
13+
/** @var \Magento\Framework\App\RequestInterface */
14+
private $request;
15+
16+
protected function setUp()
17+
{
18+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
19+
/** @var \Magento\Framework\App\RequestInterface $request */
20+
$this->request = $objectManager->get(\Magento\Framework\App\RequestInterface::class);
21+
22+
/** Default Attribute Set Id is equal 4 */
23+
$this->request->setParams(['template_id' => 4]);
24+
25+
$this->dataProvider = $objectManager->create(
26+
\Magento\Catalog\Ui\DataProvider\Product\Attributes\Listing::class,
27+
[
28+
'name' => 'product_attributes_grid_data_source',
29+
'primaryFieldName' => 'attribute_id',
30+
'requestFieldName' => 'id',
31+
'request' => $this->request
32+
]
33+
);
34+
}
35+
36+
public function testGetDataSortedAsc()
37+
{
38+
$this->dataProvider->addOrder('attribute_code', 'asc');
39+
$data = $this->dataProvider->getData();
40+
$this->assertEquals(2, $data['totalRecords']);
41+
$this->assertEquals('color', $data['items'][0]['attribute_code']);
42+
$this->assertEquals('manufacturer', $data['items'][1]['attribute_code']);
43+
}
44+
45+
public function testGetDataSortedDesc()
46+
{
47+
$this->dataProvider->addOrder('attribute_code', 'desc');
48+
$data = $this->dataProvider->getData();
49+
$this->assertEquals(2, $data['totalRecords']);
50+
$this->assertEquals('manufacturer', $data['items'][0]['attribute_code']);
51+
$this->assertEquals('color', $data['items'][1]['attribute_code']);
52+
}
53+
}

0 commit comments

Comments
 (0)