Inspired by answer mentioned in the link. I wrote following code but it is not returning invisible products.

$productCollection = $this->categoryFactory->create()->load($this->_storeManager->getStore()->getRootCategoryId())

1 Answer 1


it is not possible in magento2.

In the back end, following query is getting executed.

SELECT `e`.`entity_id` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.visibility IN(4, 2, 1) 

If we mark a product as invisible, magento2 is removing from catalog_category_product_index so regardless of visibility filter, inner join will not work. Further you can see that visibility field is inside catalog_category_product_index table.

way around

In my case no category filter was required so I used following code.

$productCollection = $this->collectionFactory->create()

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.