eavConfig = $eavConfig; $this->swatchHelper = $swatchHelper; } /** * Add swatch attributes to Configurable Products Collection * * @param ConfigurableProductType $subject * @param Collection $result * @param ProductInterface $product * @return Collection */ public function afterGetUsedProductCollection( ConfigurableProductType $subject, Collection $result, ProductInterface $product ) { $swatchAttributes = ['image']; foreach ($subject->getUsedProductAttributes($product) as $code => $attribute) { if ($attribute->getData('additional_data') && ( $this->swatchHelper->isVisualSwatch($attribute) || $this->swatchHelper->isTextSwatch($attribute) ) ) { $swatchAttributes[] = $code; } } $result->addAttributeToSelect($swatchAttributes); return $result; } }