I am trying to get product collection with filter by attribute Color(code) with value Black(5). I have one configurable product with color Black(5), Red(6). Here Product Name Product 1(configurable product), Product 1 Black (simple product), Product 1 Red (simple product).
So I get the resulting Product 1 Black (simple product) but I want to result from Product 1(configurable product).
So please let me know the code for this. My code is
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryProducts = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$categoryProducts->addAttributeToSelect('*')->addAttributeToFilter('color', array('eq' => '5'));
foreach ($categoryProducts as $product) {
echo "<br>";
echo $i.'==='.$product->getId().'==='.$product->getName();
echo "<br>";
//$i++;
}
Thanks in Advance!