Skip to content

Commit d8c59be

Browse files
php4umagentodmanners
authored andcommitted
[MAGETWO-1556] Export: Unable to Filter Data by Attribute With Input Type Multiple Select
- added support for multiselect attribute for both product and customer entity
1 parent ddf6862 commit d8c59be

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function _getMultiSelectHtmlWithValue(Attribute $attribute, $value)
142142
if ($attribute->getFilterOptions()) {
143143
$options = $attribute->getFilterOptions();
144144
} else {
145-
$options = $attribute->getSource()->getAllOptions(false);
145+
$options = $attribute->getSource()->getAllOptions();
146146

147147
foreach ($options as $key => $optionParams) {
148148
if ('' === $optionParams['value']) {
@@ -151,12 +151,13 @@ protected function _getMultiSelectHtmlWithValue(Attribute $attribute, $value)
151151
}
152152
}
153153
}
154+
154155
if ($size = count($options)) {
155156
$arguments = [
156157
'name' => $this->getFilterElementName($attribute->getAttributeCode()) . '[]',
157158
'id' => $this->getFilterElementId($attribute->getAttributeCode()),
158159
'class' => 'multiselect multiselect-export-filter',
159-
'extra_params' => 'multiple="multiple" size="' . ($size > 5 ? 5 : ($size < 2 ? 2 : $size)),
160+
'extra_params' => 'multiple="multiple" size="' . ($size > 5 ? 5 : ($size < 2 ? 2 : $size)) . '"',
160161
];
161162
/** @var $selectBlock \Magento\Framework\View\Element\Html\Select */
162163
$selectBlock = $this->_layout->createBlock(
@@ -364,6 +365,9 @@ public function decorateFilter($value, Attribute $row, \Magento\Framework\DataOb
364365
case \Magento\ImportExport\Model\Export::FILTER_TYPE_SELECT:
365366
$cell = $this->_getSelectHtmlWithValue($row, $value);
366367
break;
368+
case \Magento\ImportExport\Model\Export::FILTER_TYPE_MULTISELECT:
369+
$cell = $this->_getMultiSelectHtmlWithValue($row, $value);
370+
break;
367371
case \Magento\ImportExport\Model\Export::FILTER_TYPE_INPUT:
368372
$cell = $this->_getInputHtmlWithValue($row, $value);
369373
break;

app/code/Magento/ImportExport/Model/Export.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Export extends \Magento\ImportExport\Model\AbstractModel
3030
*/
3131
const FILTER_TYPE_SELECT = 'select';
3232

33+
const FILTER_TYPE_MULTISELECT ='multiselect';
34+
3335
const FILTER_TYPE_INPUT = 'input';
3436

3537
const FILTER_TYPE_DATE = 'date';
@@ -215,7 +217,8 @@ public function filterAttributeCollection(\Magento\Framework\Data\Collection $co
215217
public static function getAttributeFilterType(\Magento\Eav\Model\Entity\Attribute $attribute)
216218
{
217219
if ($attribute->usesSource() || $attribute->getFilterOptions()) {
218-
return self::FILTER_TYPE_SELECT;
220+
return 'multiselect' == $attribute->getFrontendInput() ?
221+
self::FILTER_TYPE_MULTISELECT : self::FILTER_TYPE_SELECT;
219222
} elseif ('datetime' == $attribute->getBackendType()) {
220223
return self::FILTER_TYPE_DATE;
221224
} elseif ('decimal' == $attribute->getBackendType() || 'int' == $attribute->getBackendType()) {

app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,25 @@ public function filterEntityCollection(AbstractCollection $collection)
152152
// filter applying
153153
if (isset($exportFilter[$attributeCode])) {
154154
$attributeFilterType = Export::getAttributeFilterType($attribute);
155-
156155
if (Export::FILTER_TYPE_SELECT == $attributeFilterType) {
157156
if (is_scalar($exportFilter[$attributeCode]) && trim($exportFilter[$attributeCode])) {
158157
$collection->addAttributeToFilter(
159158
$attributeCode,
160159
['eq' => $exportFilter[$attributeCode]]
161160
);
162161
}
162+
} elseif (Export::FILTER_TYPE_MULTISELECT == $attributeFilterType) {
163+
if (is_array($exportFilter[$attributeCode])) {
164+
array_filter($exportFilter[$attributeCode]);
165+
if (!empty($exportFilter[$attributeCode])) {
166+
foreach ($exportFilter[$attributeCode] as $val) {
167+
$collection->addAttributeToFilter(
168+
$attributeCode,
169+
['finset' => $val]
170+
);
171+
}
172+
}
173+
}
163174
} elseif (Export::FILTER_TYPE_INPUT == $attributeFilterType) {
164175
if (is_scalar($exportFilter[$attributeCode]) && trim($exportFilter[$attributeCode])) {
165176
$collection->addAttributeToFilter(

0 commit comments

Comments
 (0)