protected function getProductVariationWithMedia(Product $currentConfigurable, array $attributes) { $product = null; $layeredAttributes = []; $configurableAttributes = $this->swatchHelper->getAttributesFromConfigurable($currentConfigurable); if ($configurableAttributes) { $layeredAttributes = $this->getLayeredAttributesIfExists($configurableAttributes); } $resultAttributes = array_merge($layeredAttributes, $attributes); $product = $this->swatchHelper->loadVariationByFallback($currentConfigurable, $resultAttributes); if (!$product || (!$product->getImage() || $product->getImage() == 'no_selection')) { $product = $this->swatchHelper->loadFirstVariationWithImage($currentConfigurable, $resultAttributes); } return $product; }