Skip to content

Commit

Permalink
[MAGETWO-1556] Export: Unable to Filter Data by Attribute With Input …
Browse files Browse the repository at this point in the history
…Type Multiple Select

 - added support for multiselect attribute for both product and customer entity
  • Loading branch information
php4umagento authored and dmanners committed Feb 26, 2018
1 parent ddf6862 commit d8c59be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function _getMultiSelectHtmlWithValue(Attribute $attribute, $value)
if ($attribute->getFilterOptions()) {
$options = $attribute->getFilterOptions();
} else {
$options = $attribute->getSource()->getAllOptions(false);
$options = $attribute->getSource()->getAllOptions();

foreach ($options as $key => $optionParams) {
if ('' === $optionParams['value']) {
Expand All @@ -151,12 +151,13 @@ protected function _getMultiSelectHtmlWithValue(Attribute $attribute, $value)
}
}
}

if ($size = count($options)) {
$arguments = [
'name' => $this->getFilterElementName($attribute->getAttributeCode()) . '[]',
'id' => $this->getFilterElementId($attribute->getAttributeCode()),
'class' => 'multiselect multiselect-export-filter',
'extra_params' => 'multiple="multiple" size="' . ($size > 5 ? 5 : ($size < 2 ? 2 : $size)),
'extra_params' => 'multiple="multiple" size="' . ($size > 5 ? 5 : ($size < 2 ? 2 : $size)) . '"',
];
/** @var $selectBlock \Magento\Framework\View\Element\Html\Select */
$selectBlock = $this->_layout->createBlock(
Expand Down Expand Up @@ -364,6 +365,9 @@ public function decorateFilter($value, Attribute $row, \Magento\Framework\DataOb
case \Magento\ImportExport\Model\Export::FILTER_TYPE_SELECT:
$cell = $this->_getSelectHtmlWithValue($row, $value);
break;
case \Magento\ImportExport\Model\Export::FILTER_TYPE_MULTISELECT:
$cell = $this->_getMultiSelectHtmlWithValue($row, $value);
break;
case \Magento\ImportExport\Model\Export::FILTER_TYPE_INPUT:
$cell = $this->_getInputHtmlWithValue($row, $value);
break;
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/ImportExport/Model/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Export extends \Magento\ImportExport\Model\AbstractModel
*/
const FILTER_TYPE_SELECT = 'select';

const FILTER_TYPE_MULTISELECT ='multiselect';

const FILTER_TYPE_INPUT = 'input';

const FILTER_TYPE_DATE = 'date';
Expand Down Expand Up @@ -215,7 +217,8 @@ public function filterAttributeCollection(\Magento\Framework\Data\Collection $co
public static function getAttributeFilterType(\Magento\Eav\Model\Entity\Attribute $attribute)
{
if ($attribute->usesSource() || $attribute->getFilterOptions()) {
return self::FILTER_TYPE_SELECT;
return 'multiselect' == $attribute->getFrontendInput() ?
self::FILTER_TYPE_MULTISELECT : self::FILTER_TYPE_SELECT;
} elseif ('datetime' == $attribute->getBackendType()) {
return self::FILTER_TYPE_DATE;
} elseif ('decimal' == $attribute->getBackendType() || 'int' == $attribute->getBackendType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,25 @@ public function filterEntityCollection(AbstractCollection $collection)
// filter applying
if (isset($exportFilter[$attributeCode])) {
$attributeFilterType = Export::getAttributeFilterType($attribute);

if (Export::FILTER_TYPE_SELECT == $attributeFilterType) {
if (is_scalar($exportFilter[$attributeCode]) && trim($exportFilter[$attributeCode])) {
$collection->addAttributeToFilter(
$attributeCode,
['eq' => $exportFilter[$attributeCode]]
);
}
} elseif (Export::FILTER_TYPE_MULTISELECT == $attributeFilterType) {
if (is_array($exportFilter[$attributeCode])) {
array_filter($exportFilter[$attributeCode]);
if (!empty($exportFilter[$attributeCode])) {
foreach ($exportFilter[$attributeCode] as $val) {
$collection->addAttributeToFilter(
$attributeCode,
['finset' => $val]
);
}
}
}
} elseif (Export::FILTER_TYPE_INPUT == $attributeFilterType) {
if (is_scalar($exportFilter[$attributeCode]) && trim($exportFilter[$attributeCode])) {
$collection->addAttributeToFilter(
Expand Down

0 comments on commit d8c59be

Please sign in to comment.