public function aroundGetFilterArray(
        \Magento\Swatches\Model\ProductSubstitute $productSubstitute,
        \Closure $proceed,
        array $request
    ) {
        $filterArray = $proceed($request);

        $attributeCodes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY);

        foreach ($request as $code => $value) {
            if (in_array($code, $attributeCodes)) {
                $attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $code);

                if (isset($filterArray[$code]) && !is_array($filterArray[$code])) {
                    $filterArray[$code] = [$filterArray[$code]];
                }

                if ($attribute->getId() && $productSubstitute->canReplaceImageWithSwatch($attribute)) {
                    $filterArray[$code][] = $this->swatchHelper->getOptionIds($attribute, $value);
                }
            }
        }

        return $filterArray;
    }
public function aroundGetFilterArray(
        \Magento\Swatches\Model\ProductSubstitute $productSubstitute,
        \Closure $proceed,
        array $request
    ) {
        $filterArray = $proceed($request);

        $attributeCodes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY);

        foreach ($request as $code => $value) {
            if (in_array($code, $attributeCodes)) {
                $attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $code);

                if (isset($filterArray[$code]) && !is_array($filterArray[$code])) {
                    $filterArray[$code] = [$filterArray[$code]];
                }

                if ($attribute->getId() && $productSubstitute->canReplaceImageWithSwatch($attribute)) {
                    $filterArray[$code][] = $this->swatchHelper->getOptionIds($attribute, $value);
                }
            }
        }

        return $filterArray;
    }
public function aroundGetFilterArray ( \ Magento \ Swatches \ Model \ ProductSubstitute $ productSubstitute , \ Closure $ proceed , array $ request ) { $ filterArray = $ proceed ( $ request ) ; $ attributeCodes = $ this -> eavConfig -> getEntityAttributeCodes ( \ Magento \ Catalog \ Model \ Product :: ENTITY ) ; foreach ( $ request as $ code => $ value ) { if ( in_array ( $ code , $ attributeCodes ) ) { $ attribute = $ this -> eavConfig -> getAttribute ( \ Magento \ Catalog \ Model \ Product :: ENTITY , $ code ) ; if ( isset ( $ filterArray [ $ code ] ) && ! is_array ( $ filterArray [ $ code ] ) ) { $ filterArray [ $ code ] = [ $ filterArray [ $ code ] ] ; } if ( $ attribute -> getId ( ) && $ productSubstitute -> canReplaceImageWithSwatch ( $ attribute ) ) { $ filterArray [ $ code ] [ ] = $ this -> swatchHelper -> getOptionIds ( $ attribute , $ value ) ; } } } return $ filterArray ; }
Build proper array for swatches rendering. Especially in product listing where values may come as label
instead of option Ids.

@param \Magento\Swatches\Model\ProductSubstitute $productSubstitute Original ProductSubstitute class
@param \Closure                                  $proceed           ProductSubstitute::getFilterArray()
@param array                                     $request           Request

@return mixed
Build proper array for swatches rendering . Especially in product listing where values may come as label instead of option Ids .