Skip to content

Commit cc65c82

Browse files
author
Mastiuhin Olexandr
committed
MAGETWO-98088: [2.3] Configurable product can be added as a variation to another Configurable product in the admin
1 parent 250045e commit cc65c82

File tree

3 files changed

+223
-3
lines changed

3 files changed

+223
-3
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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\Catalog\Test\Unit\Ui\Component;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Catalog\Ui\Component\ColumnFactory;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
14+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
15+
use Magento\Framework\View\Element\UiComponentFactory;
16+
use Magento\Ui\Component\Listing\Columns\ColumnInterface;
17+
use Magento\Ui\Component\Filters\FilterModifier;
18+
19+
/**
20+
* ColumnFactory test.
21+
*/
22+
class ColumnFactoryTest extends TestCase
23+
{
24+
/**
25+
* @var ColumnFactory
26+
*/
27+
private $columnFactory;
28+
29+
/**
30+
* @var ObjectManager
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var ProductAttributeInterface|\PHPUnit\Framework\MockObject\MockObject
36+
*/
37+
private $attribute;
38+
39+
/**
40+
* @var ContextInterface|\PHPUnit\Framework\MockObject\MockObject
41+
*/
42+
private $context;
43+
44+
/**
45+
* @var UiComponentFactory|\PHPUnit\Framework\MockObject\MockObject
46+
*/
47+
private $uiComponentFactory;
48+
49+
/**
50+
* @var ColumnInterface|\PHPUnit\Framework\MockObject\MockObject
51+
*/
52+
private $column;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
protected function setUp(): void
58+
{
59+
$this->objectManager = new ObjectManager($this);
60+
61+
$this->attribute = $this->getMockBuilder(ProductAttributeInterface::class)
62+
->setMethods(['usesSource'])
63+
->getMockForAbstractClass();
64+
$this->context = $this->createMock(ContextInterface::class);
65+
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
66+
$this->column = $this->getMockForAbstractClass(ColumnInterface::class);
67+
$this->uiComponentFactory->method('create')
68+
->willReturn($this->column);
69+
70+
$this->columnFactory = $this->objectManager->getObject(ColumnFactory::class, [
71+
'componentFactory' => $this->uiComponentFactory
72+
]);
73+
}
74+
75+
/**
76+
* Tests the create method will return correct object.
77+
*
78+
* @return void
79+
*/
80+
public function testCreatedObject(): void
81+
{
82+
$this->context->method('getRequestParam')
83+
->with(FilterModifier::FILTER_MODIFIER, [])
84+
->willReturn([]);
85+
86+
$object = $this->columnFactory->create($this->attribute, $this->context);
87+
$this->assertEquals(
88+
$this->column,
89+
$object,
90+
'Object must be the same which the ui component factory creates.'
91+
);
92+
}
93+
94+
/**
95+
* Tests create method with not filterable in grid attribute.
96+
*
97+
* @param array $filterModifiers
98+
* @param null|string $filter
99+
*
100+
* @return void
101+
* @dataProvider filterModifiersProvider
102+
*/
103+
public function testCreateWithNotFilterableInGridAttribute(array $filterModifiers,?string $filter): void
104+
{
105+
$componentFactoryArgument = [
106+
'data' => [
107+
'config' => [
108+
'label' => __(null),
109+
'dataType' => 'text',
110+
'add_field' => true,
111+
'visible' => null,
112+
'filter' => $filter,
113+
'component' => 'Magento_Ui/js/grid/columns/column',
114+
],
115+
],
116+
'context' => $this->context,
117+
];
118+
119+
$this->context->method('getRequestParam')
120+
->with(FilterModifier::FILTER_MODIFIER, [])
121+
->willReturn($filterModifiers);
122+
$this->attribute->method('getIsFilterableInGrid')
123+
->willReturn(false);
124+
$this->attribute->method('getAttributeCode')
125+
->willReturn('color');
126+
127+
$this->uiComponentFactory->expects($this->once())
128+
->method('create')
129+
->with($this->anything(), $this->anything(), $componentFactoryArgument);
130+
131+
$this->columnFactory->create($this->attribute, $this->context);
132+
}
133+
134+
/**
135+
* The omit filterable in grid parameter data provider.
136+
*
137+
* @return array
138+
*/
139+
public function filterModifiersProvider(): array
140+
{
141+
return [
142+
'without' => [
143+
'filter_modifiers' => [],
144+
'filter' => null,
145+
],
146+
'with' => [
147+
'filter_modifiers' => [
148+
'color' => [
149+
'condition_type' => 'notnull',
150+
],
151+
],
152+
'filter' => 'text',
153+
],
154+
];
155+
}
156+
}

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Ui\Component;
77

8+
use Magento\Ui\Component\Filters\FilterModifier;
9+
810
/**
911
* Column Factory
1012
*
@@ -60,13 +62,15 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
6062
*/
6163
public function create($attribute, $context, array $config = [])
6264
{
65+
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);
66+
6367
$columnName = $attribute->getAttributeCode();
6468
$config = array_merge([
6569
'label' => __($attribute->getDefaultFrontendLabel()),
6670
'dataType' => $this->getDataType($attribute),
6771
'add_field' => true,
6872
'visible' => $attribute->getIsVisibleInGrid(),
69-
'filter' => ($attribute->getIsFilterableInGrid())
73+
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
7074
? $this->getFilterType($attribute->getFrontendInput())
7175
: null,
7276
], $config);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@
55
*/
66
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\Data;
77

8-
class AssociatedProductsTest extends \PHPUnit\Framework\TestCase
8+
use Magento\Framework\View\Element\UiComponentFactory;
9+
use Magento\Ui\Component\Filters\FilterModifier;
10+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
11+
use Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePanel;
12+
use Magento\Framework\App\RequestInterface;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* AssociatedProductsTest
17+
*/
18+
class AssociatedProductsTest extends TestCase
919
{
1020
/**
1121
* @var \Magento\Framework\ObjectManagerInterface $objectManager
@@ -17,7 +27,10 @@ class AssociatedProductsTest extends \PHPUnit\Framework\TestCase
1727
*/
1828
private $registry;
1929

20-
public function setUp()
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function setUp(): void
2134
{
2235
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
2336
$this->registry = $this->objectManager->get(\Magento\Framework\Registry::class);
@@ -64,6 +77,53 @@ public function testGetProductMatrix($interfaceLocale)
6477
}
6578
}
6679

80+
/**
81+
* Tests configurable product won't appear in product listing.
82+
*
83+
* Tests configurable product won't appear in configurable associated product listing if its options attribute
84+
* is not filterable in grid.
85+
*
86+
* @return void
87+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
88+
* @magentoAppArea adminhtml
89+
*/
90+
public function testAddManuallyConfigurationsWithNotFilterableInGridAttribute(): void
91+
{
92+
/** @var RequestInterface $request */
93+
$request = $this->objectManager->get(RequestInterface::class);
94+
$request->setParams([
95+
FilterModifier::FILTER_MODIFIER => [
96+
'test_configurable' => [
97+
'condition_type' => 'notnull',
98+
],
99+
],
100+
'attributes_codes' => [
101+
'test_configurable'
102+
],
103+
]);
104+
$context = $this->objectManager->create(ContextInterface::class, ['request' => $request]);
105+
/** @var UiComponentFactory $uiComponentFactory */
106+
$uiComponentFactory = $this->objectManager->get(UiComponentFactory::class);
107+
$uiComponent = $uiComponentFactory->create(
108+
ConfigurablePanel::ASSOCIATED_PRODUCT_LISTING,
109+
null,
110+
['context' => $context]
111+
);
112+
113+
foreach ($uiComponent->getChildComponents() as $childUiComponent) {
114+
$childUiComponent->prepare();
115+
}
116+
117+
$dataSource = $uiComponent->getDataSourceData();
118+
$skus = array_column($dataSource['data']['items'], 'sku');
119+
120+
$this->assertNotContains(
121+
'configurable',
122+
$skus,
123+
'Only products with specified attribute should be in product list'
124+
);
125+
}
126+
67127
/**
68128
* @return array
69129
*/

0 commit comments

Comments
 (0)