Skip to content

Commit 7547dd2

Browse files
committed
MAGETWO-91750: Multiselect attribute values is not searchable under Quick Search when more than one value is selected
- Added possibility to retrieve multiselect option values for catalog fulltext search reindexation
1 parent 8460e4e commit 7547dd2

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Store\Model\Store;
1313

1414
/**
15+
* Data provider class
16+
*
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1618
* @SuppressWarnings(PHPMD.TooManyFields)
1719
* @api
@@ -570,8 +572,8 @@ public function prepareProductIndex($indexData, $productData, $storeId)
570572
}
571573
}
572574
foreach ($indexData as $entityId => $attributeData) {
573-
foreach ($attributeData as $attributeId => $attributeValue) {
574-
$value = $this->getAttributeValue($attributeId, $attributeValue, $storeId);
575+
foreach ($attributeData as $attributeId => $attributeValues) {
576+
$value = $this->getAttributeValue($attributeId, $attributeValues, $storeId);
575577
if (!empty($value)) {
576578
if (isset($index[$attributeId])) {
577579
$index[$attributeId][$entityId] = $value;
@@ -602,16 +604,16 @@ public function prepareProductIndex($indexData, $productData, $storeId)
602604
* Retrieve attribute source value for search
603605
*
604606
* @param int $attributeId
605-
* @param mixed $valueId
607+
* @param mixed $valueIds
606608
* @param int $storeId
607609
* @return string
608610
*/
609-
private function getAttributeValue($attributeId, $valueId, $storeId)
611+
private function getAttributeValue($attributeId, $valueIds, $storeId)
610612
{
611613
$attribute = $this->getSearchableAttribute($attributeId);
612-
$value = $this->engine->processAttributeValue($attribute, $valueId);
614+
$value = $this->engine->processAttributeValue($attribute, $valueIds);
613615
if (false !== $value) {
614-
$optionValue = $this->getAttributeOptionValue($attributeId, $valueId, $storeId);
616+
$optionValue = $this->getAttributeOptionValue($attributeId, $valueIds, $storeId);
615617
if (null === $optionValue) {
616618
$value = $this->filterAttributeValue($value);
617619
} else {
@@ -626,13 +628,15 @@ private function getAttributeValue($attributeId, $valueId, $storeId)
626628
* Get attribute option value
627629
*
628630
* @param int $attributeId
629-
* @param int $valueId
631+
* @param int|string $valueIds
630632
* @param int $storeId
631633
* @return null|string
632634
*/
633-
private function getAttributeOptionValue($attributeId, $valueId, $storeId)
635+
private function getAttributeOptionValue($attributeId, $valueIds, $storeId)
634636
{
635637
$optionKey = $attributeId . '-' . $storeId;
638+
$attributeValueIds = explode(',', $valueIds);
639+
$attributeOptionValue = '';
636640
if (!array_key_exists($optionKey, $this->attributeOptions)
637641
) {
638642
$attribute = $this->getSearchableAttribute($attributeId);
@@ -650,8 +654,10 @@ private function getAttributeOptionValue($attributeId, $valueId, $storeId)
650654
$this->attributeOptions[$optionKey] = null;
651655
}
652656
}
653-
654-
return $this->attributeOptions[$optionKey][$valueId] ?? null;
657+
foreach ($attributeValueIds as $attrValueId) {
658+
$attributeOptionValue .= $this->attributeOptions[$optionKey][$attrValueId] . ' ';
659+
}
660+
return empty($attributeOptionValue) ? null : trim($attributeOptionValue);
655661
}
656662

657663
/**

0 commit comments

Comments
 (0)