Skip to content

Commit 6561fe0

Browse files
committed
Merge remote-tracking branch 'origin/MC-40679' into 2.4-develop-pr134
2 parents 06bd9c1 + 50a16d0 commit 6561fe0

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
namespace Magento\Weee\Plugin\Catalog\Ui\Component\Listing;
9+
10+
use Magento\Catalog\Ui\Component\Listing\Attribute\Repository;
11+
use Magento\Catalog\Ui\Component\Listing\Columns as DefaultColumns;
12+
use Magento\Weee\Model\Attribute\Backend\Weee\Tax;
13+
14+
/**
15+
* Class Columns
16+
*/
17+
class Columns
18+
{
19+
/**
20+
* @var Repository
21+
*/
22+
private $attributeRepository;
23+
24+
/**
25+
* @param Repository $attributeRepository
26+
*/
27+
public function __construct(
28+
Repository $attributeRepository
29+
) {
30+
$this->attributeRepository = $attributeRepository;
31+
}
32+
33+
/**
34+
* Makes column for FPT attribute in grid not sortable
35+
*
36+
* @param DefaultColumns $subject
37+
*/
38+
public function afterPrepare(DefaultColumns $subject) : void
39+
{
40+
foreach ($this->attributeRepository->getList() as $attribute) {
41+
if ($attribute->getBackendModel() === Tax::class) {
42+
$column = $subject->getComponent($attribute->getAttributeCode());
43+
$columnConfig = $column->getData('config');
44+
$columnConfig['sortable'] = false;
45+
$column->setData('config', $columnConfig);
46+
}
47+
}
48+
}
49+
}

app/code/Magento/Weee/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@
8484
<type name="Magento\Catalog\Model\ResourceModel\Attribute\RemoveProductAttributeData">
8585
<plugin name="removeWeeAttributesData" type="Magento\Weee\Plugin\Catalog\ResourceModel\Attribute\RemoveProductWeeData" />
8686
</type>
87+
<type name="Magento\Catalog\Ui\Component\Listing\Columns">
88+
<plugin name="changeWeeColumnConfig" type="Magento\Weee\Plugin\Catalog\Ui\Component\Listing\Columns"/>
89+
</type>
8790
</config>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
namespace Magento\Weee\Plugin\Catalog\Ui\Component\Listing;
9+
10+
use Magento\Catalog\Ui\Component\Listing\Attribute\Repository;
11+
use Magento\Catalog\Ui\Component\Listing\Columns;
12+
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
13+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Class ColumnsTest
19+
* Check if FPT attribute column in product grid won't be sortable
20+
*/
21+
class ColumnsTest extends TestCase
22+
{
23+
/**
24+
* @var Columns
25+
*/
26+
private $columns;
27+
28+
/**
29+
* @inheritDoc
30+
*/
31+
protected function setUp(): void
32+
{
33+
$objectManager = Bootstrap::getObjectManager();
34+
$attributeRepository = $objectManager->get(Repository::class);
35+
$dataProvider = $objectManager->create(
36+
ProductDataProvider::class,
37+
[
38+
'name' => "product_listing_data_source",
39+
'primaryFieldName' => "entity_id",
40+
'requestFieldName' => "id",
41+
]
42+
);
43+
$context = $objectManager->create(ContextInterface::class);
44+
$context->setDataProvider($dataProvider);
45+
$this->columns = $objectManager->create(
46+
Columns::class,
47+
['attributeRepository' => $attributeRepository, 'context' => $context]
48+
);
49+
}
50+
51+
/**
52+
* @magentoDbIsolation enabled
53+
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
54+
*/
55+
public function testGetProductWeeeAttributesConfig()
56+
{
57+
$this->columns->prepare();
58+
$column = $this->columns->getComponent('fixed_product_attribute');
59+
$columnConfig = $column->getData('config');
60+
$this->assertArrayHasKey('sortable', $columnConfig);
61+
$this->assertFalse($columnConfig['sortable']);
62+
}
63+
}

dev/tests/integration/testsuite/Magento/Weee/_files/fixed_product_attribute.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
declare(strict_types=1);
88

9+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
10+
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/fixed_product_attribute_rollback.php');
11+
912
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
1013

1114
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
@@ -27,6 +30,7 @@
2730
'attribute_group_id' => $attributeGroupId,
2831
'frontend_input' => 'weee',
2932
'frontend_label' => 'fixed product tax',
33+
'is_used_in_grid' => '1',
3034
];
3135

3236
/** @var \Magento\Catalog\Model\Entity\Attribute $attribute */

0 commit comments

Comments
 (0)