Skip to content

Commit 072b863

Browse files
committed
MAGETWO-97044: Calculated Labels in Columns Widget
1 parent 0965809 commit 072b863

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

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: 21 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,22 @@ 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): array
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+
return $options;
643+
}
644+
625645
/**
626646
* @param ProductAttributeInterface $attribute
627647
* @param array $meta

0 commit comments

Comments
 (0)