I am working on to get all the products that have attributes match. My current code is

$categoryProducts1 = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$categoryProducts1->addAttributeToFilter('price', array('from' => 0, 'to' => 2500));
echo $categoryProducts1->count();
echo "<br>";
echo $categoryProducts1->getSelect()->__toString();
echo "<br>";
foreach ($categoryProducts1 as $_pro) {
    echo $_pro->getId().' === '.$_pro->getName();
    echo "<br>";

So here I get only simple products and configureable child products but not the configurable parent one products because the parent product has price 0. So, In this case, I need to display that configurable product too. So I need simple products and configurable parent products only.

So please help me with this.

1 Answer 1


Since you filtering for the price, this table will be helpful for you: catalog_product_index_price. This is a default Mage2 table that has reindexed data about prices of all products and takes into account catalog product rules and special prices for different customer groups.

Also, catalog_category_product_index_store1 will be helpful for you. You can join it to your collection and filter by visibility(don't forget to filter by store).

  • thanks, but can you write exact query here. because I do not want custom query. I want just add ore replace existing code. Commented Dec 3, 2019 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.