Skip to content

Commit ae906d1

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-97044' into 2.1.18-develop-pr68
2 parents 87e872e + aa1e2d1 commit ae906d1

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Catalog\Api\ProductAttributeGroupRepositoryInterface;
1010
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
11+
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
1112
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1213
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
1314
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory as EavAttributeFactory;
@@ -254,7 +255,15 @@ protected function setUp()
254255
$this->searchResultsMock = $this->getMockBuilder(SearchResultsInterface::class)
255256
->getMockForAbstractClass();
256257
$this->eavAttributeMock = $this->getMockBuilder(Attribute::class)
257-
->setMethods(['load', 'getAttributeGroupCode', 'getApplyTo', 'getFrontendInput', 'getAttributeCode'])
258+
->setMethods([
259+
'load',
260+
'getAttributeGroupCode',
261+
'getApplyTo',
262+
'getFrontendInput',
263+
'getAttributeCode',
264+
'usesSource',
265+
'getSource',
266+
])
258267
->disableOriginalConstructor()
259268
->getMock();
260269
$this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
@@ -460,6 +469,20 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
460469
$configPath = 'arguments/data/config';
461470
$groupCode = 'product-details';
462471
$sortOrder = '0';
472+
$attributeOptions = [
473+
['value' => 1, 'label' => 'Int label'],
474+
['value' => 1.5, 'label' => 'Float label'],
475+
['value' => true, 'label' => 'Boolean label'],
476+
['value' => 'string', 'label' => 'String label'],
477+
['value' => ['test1', 'test2'], 'label' => 'Array label'],
478+
];
479+
$attributeOptionsExpected = [
480+
['value' => '1', 'label' => 'Int label', '__disableTmpl' => true],
481+
['value' => '1.5', 'label' => 'Float label', '__disableTmpl' => true],
482+
['value' => '1', 'label' => 'Boolean label', '__disableTmpl' => true],
483+
['value' => 'string', 'label' => 'String label', '__disableTmpl' => true],
484+
['value' => ['test1', 'test2'], 'label' => 'Array label', '__disableTmpl' => true],
485+
];
463486

464487
$this->productMock->expects($this->any())
465488
->method('getId')
@@ -491,6 +514,11 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
491514
->method('getCustomAttribute')
492515
->willReturn($attributeMock);
493516

517+
$this->eavAttributeMock->method('usesSource')->willReturn(true);
518+
$attributeSource = $this->getMockBuilder(SourceInterface::class)->getMockForAbstractClass();
519+
$attributeSource->method('getAllOptions')->willReturn($attributeOptions);
520+
$this->eavAttributeMock->method('getSource')->willReturn($attributeSource);
521+
494522
$this->arrayManagerMock->expects($this->any())
495523
->method('set')
496524
->with(
@@ -502,6 +530,15 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
502530

503531
$this->arrayManagerMock->expects($this->any())
504532
->method('merge')
533+
->with(
534+
$this->anything(),
535+
$this->anything(),
536+
$this->callback(
537+
function ($value) use ($attributeOptionsExpected) {
538+
return isset($value['options']) ? $value['options'] === $attributeOptionsExpected : true;
539+
}
540+
)
541+
)
505542
->willReturn($expected);
506543

507544
$this->arrayManagerMock->expects($this->any())

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

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

8+
use Magento\Ui\Component\Filters\FilterModifier;
9+
10+
/**
11+
* Product grid columns factory.
12+
*/
813
class ColumnFactory
914
{
1015
/**
@@ -50,19 +55,24 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
5055
*/
5156
public function create($attribute, $context, array $config = [])
5257
{
58+
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);
59+
5360
$columnName = $attribute->getAttributeCode();
5461
$config = array_merge([
5562
'label' => __($attribute->getDefaultFrontendLabel()),
5663
'dataType' => $this->getDataType($attribute),
5764
'add_field' => true,
5865
'visible' => $attribute->getIsVisibleInGrid(),
59-
'filter' => ($attribute->getIsFilterableInGrid())
66+
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
6067
? $this->getFilterType($attribute->getFrontendInput())
6168
: null,
6269
], $config);
6370

6471
if ($attribute->usesSource()) {
6572
$config['options'] = $attribute->getSource()->getAllOptions();
73+
foreach ($config['options'] as &$optionData) {
74+
$optionData['__disableTmpl'] = true;
75+
}
6676
}
6777

6878
$config['component'] = $this->getJsComponent($config['dataType']);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,12 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
568568
// TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
569569
$attributeModel = $this->getAttributeModel($attribute);
570570
if ($attributeModel->usesSource()) {
571+
$options = $attributeModel->getSource()->getAllOptions();
572+
foreach ($options as &$option) {
573+
$option['__disableTmpl'] = true;
574+
}
571575
$meta = $this->arrayManager->merge($configPath, $meta, [
572-
'options' => $attributeModel->getSource()->getAllOptions(),
576+
'options' => $this->convertOptionsValueToString($options),
573577
]);
574578
}
575579

@@ -622,6 +626,23 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
622626
return $meta;
623627
}
624628

629+
/**
630+
* Convert options value to string.
631+
*
632+
* @param array $options
633+
* @return array
634+
*/
635+
private function convertOptionsValueToString(array $options)
636+
{
637+
array_walk($options, function (&$value) {
638+
if (isset($value['value']) && is_scalar($value['value'])) {
639+
$value['value'] = (string)$value['value'];
640+
}
641+
});
642+
643+
return $options;
644+
}
645+
625646
/**
626647
* @param ProductAttributeInterface $attribute
627648
* @param array $meta

0 commit comments

Comments
 (0)