Skip to content

Commit b8660cc

Browse files
committed
ACP2E-55: Simple only global attributes make configurable attributes hidden when creating product configurations
- Fixed the solution and test coverage.
1 parent 313c54b commit b8660cc

File tree

2 files changed

+91
-13
lines changed

2 files changed

+91
-13
lines changed

app/code/Magento/ConfigurableProduct/Plugin/Model/UpdateConfigurableProductAttributeCollection.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\ConfigurableProduct\Plugin\Model;
99

10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1012
use Magento\ConfigurableProduct\Ui\DataProvider\Attributes;
1113

1214
/**
@@ -18,21 +20,26 @@ class UpdateConfigurableProductAttributeCollection
1820
* Adding a field to filter in existing configurable product attribute collection.
1921
*
2022
* @param Attributes $subject
21-
* @return object
23+
* @return void
2224
*/
23-
public function beforeGetData(Attributes $subject): object
25+
public function beforeGetData(Attributes $subject): void
2426
{
25-
$types = [
26-
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
27-
\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
28-
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE,
29-
];
30-
return $subject->getCollection()->addFieldToFilter(
31-
['apply_to', 'apply_to'],
32-
[
33-
['null' => true],
34-
['like' => '%' . implode(',', $types) . '%']
35-
]
27+
$subject->getCollection()->getSelect()->where(
28+
'(`apply_to` IS NULL) OR
29+
(
30+
FIND_IN_SET(' .
31+
"'" . Type::TYPE_SIMPLE . "'" . ',
32+
`apply_to`
33+
) AND
34+
FIND_IN_SET(' .
35+
"'" . Type::TYPE_VIRTUAL . "'" . ',
36+
`apply_to`
37+
) AND
38+
FIND_IN_SET(' .
39+
"'" . Configurable::TYPE_CODE . "'" . ',
40+
`apply_to`
41+
)
42+
)'
3643
);
3744
}
3845
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\ConfigurableProduct\Test\Unit\Plugin\Model;
9+
10+
use Magento\ConfigurableProduct\Plugin\Model\UpdateConfigurableProductAttributeCollection;
11+
use Magento\ConfigurableProduct\Ui\DataProvider\Attributes;
12+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection;
13+
use Magento\Framework\DB\Select;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class UpdateConfigurableProductAttributeCollectionTest extends TestCase
17+
{
18+
/**
19+
* @var Attributes
20+
*/
21+
private Attributes $attributesMock;
22+
23+
/**
24+
* @var Collection
25+
*/
26+
private Collection $collectionMock;
27+
28+
/**
29+
* @var Select
30+
*/
31+
private Select $selectMock;
32+
33+
/**
34+
* @var UpdateConfigurableProductAttributeCollection
35+
*/
36+
private UpdateConfigurableProductAttributeCollection $plugin;
37+
38+
/**
39+
* @return void
40+
*/
41+
protected function setUp(): void
42+
{
43+
$this->attributesMock = $this->getMockBuilder(Attributes::class)
44+
->setMethods(['getCollection'])
45+
->disableOriginalConstructor()
46+
->getMock();
47+
$this->collectionMock = $this->getMockBuilder(Collection::class)
48+
->disableOriginalConstructor()
49+
->onlyMethods(['getSelect'])
50+
->getMock();
51+
$this->selectMock = $this->getMockBuilder(Select::class)
52+
->disableOriginalConstructor()
53+
->onlyMethods(['where'])
54+
->getMock();
55+
$this->plugin = new UpdateConfigurableProductAttributeCollection();
56+
}
57+
58+
/**
59+
* @return void
60+
*/
61+
public function testBeforeGetData()
62+
{
63+
$this->collectionMock->expects($this->once())
64+
->method('getSelect')
65+
->willReturn($this->selectMock);
66+
$this->attributesMock->expects($this->any())
67+
->method('getCollection')
68+
->willReturn($this->collectionMock);
69+
$this->plugin->beforeGetData($this->attributesMock);
70+
}
71+
}

0 commit comments

Comments
 (0)